Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_NODES_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_NODES_H_ |
| 19 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 20 | #include <algorithm> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 21 | #include <array> |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 22 | #include <type_traits> |
| 23 | |
Mathieu Chartier | e5d80f8 | 2015-10-15 17:47:48 -0700 | [diff] [blame] | 24 | #include "base/arena_bit_vector.h" |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 25 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 26 | #include "base/arena_object.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 27 | #include "base/array_ref.h" |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 28 | #include "base/iteration_range.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 29 | #include "base/quasi_atomic.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 30 | #include "base/stl_util.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 31 | #include "base/transform_array_ref.h" |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 32 | #include "data_type.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 33 | #include "deoptimization_kind.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 34 | #include "dex/dex_file.h" |
| 35 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 36 | #include "dex/invoke_type.h" |
David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 37 | #include "dex/method_reference.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 38 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 39 | #include "handle.h" |
| 40 | #include "handle_scope.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 41 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 42 | #include "locations.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 43 | #include "mirror/class.h" |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 44 | #include "mirror/method_type.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 45 | #include "offsets.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 46 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 47 | |
| 48 | namespace art { |
| 49 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 50 | class ArenaStack; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 51 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 52 | class HBasicBlock; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 53 | class HConstructorFence; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 54 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 55 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 56 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 57 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 58 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 59 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 60 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 61 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 62 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 63 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 64 | class HNullConstant; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 65 | class HParameterValue; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 66 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 67 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 68 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 69 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 70 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 71 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 72 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 73 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 74 | namespace mirror { |
| 75 | class DexCache; |
| 76 | } // namespace mirror |
| 77 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 78 | static const int kDefaultNumberOfBlocks = 8; |
| 79 | static const int kDefaultNumberOfSuccessors = 2; |
| 80 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 81 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 82 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 83 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 84 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 85 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 86 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 87 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 88 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 89 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 90 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 91 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 92 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 93 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 94 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 95 | static constexpr uint32_t kNoDexPc = -1; |
| 96 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 97 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 98 | // For the purposes of the compiler, the dex files must actually be the same object |
| 99 | // if we want to safely treat them as the same. This is especially important for JIT |
| 100 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 101 | // times and provide different class resolution but no two class loaders should ever |
| 102 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 103 | // all sorts of weird failures. |
| 104 | return &lhs == &rhs; |
| 105 | } |
| 106 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 107 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 108 | // All types. |
| 109 | kCondEQ, // == |
| 110 | kCondNE, // != |
| 111 | // Signed integers and floating-point numbers. |
| 112 | kCondLT, // < |
| 113 | kCondLE, // <= |
| 114 | kCondGT, // > |
| 115 | kCondGE, // >= |
| 116 | // Unsigned integers. |
| 117 | kCondB, // < |
| 118 | kCondBE, // <= |
| 119 | kCondA, // > |
| 120 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 121 | // First and last aliases. |
| 122 | kCondFirst = kCondEQ, |
| 123 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 126 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 127 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 128 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 129 | kAnalysisFailThrowCatchLoop, |
| 130 | kAnalysisFailAmbiguousArrayOp, |
| 131 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 134 | template <typename T> |
| 135 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 136 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 137 | } |
| 138 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 139 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 140 | public: |
| 141 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 142 | |
| 143 | void AddInstruction(HInstruction* instruction); |
| 144 | void RemoveInstruction(HInstruction* instruction); |
| 145 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 146 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 147 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 148 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 149 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 150 | // Return true if this list contains `instruction`. |
| 151 | bool Contains(HInstruction* instruction) const; |
| 152 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 153 | // Return true if `instruction1` is found before `instruction2` in |
| 154 | // this instruction list and false otherwise. Abort if none |
| 155 | // of these instructions is found. |
| 156 | bool FoundBefore(const HInstruction* instruction1, |
| 157 | const HInstruction* instruction2) const; |
| 158 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 159 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 160 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 161 | |
| 162 | // Update the block of all instructions to be `block`. |
| 163 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 164 | |
| 165 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 166 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 167 | void Add(const HInstructionList& instruction_list); |
| 168 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 169 | // Return the number of instructions in the list. This is an expensive operation. |
| 170 | size_t CountSize() const; |
| 171 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 172 | private: |
| 173 | HInstruction* first_instruction_; |
| 174 | HInstruction* last_instruction_; |
| 175 | |
| 176 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 177 | friend class HGraph; |
| 178 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 179 | friend class HInstructionIterator; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 180 | friend class HInstructionIteratorHandleChanges; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 181 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 182 | |
| 183 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 184 | }; |
| 185 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 186 | class ReferenceTypeInfo : ValueObject { |
| 187 | public: |
| 188 | typedef Handle<mirror::Class> TypeHandle; |
| 189 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 190 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 191 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 192 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 193 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 194 | } |
| 195 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 196 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 197 | return ReferenceTypeInfo(type_handle, is_exact); |
| 198 | } |
| 199 | |
| 200 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 201 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 202 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 203 | return handle.GetReference() != nullptr; |
| 204 | } |
| 205 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 206 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 207 | return IsValidHandle(type_handle_); |
| 208 | } |
| 209 | |
| 210 | bool IsExact() const { return is_exact_; } |
| 211 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 212 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 213 | DCHECK(IsValid()); |
| 214 | return GetTypeHandle()->IsObjectClass(); |
| 215 | } |
| 216 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 217 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 218 | DCHECK(IsValid()); |
| 219 | return GetTypeHandle()->IsStringClass(); |
| 220 | } |
| 221 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 222 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 223 | DCHECK(IsValid()); |
| 224 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 225 | } |
| 226 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 227 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 228 | DCHECK(IsValid()); |
| 229 | return GetTypeHandle()->IsInterface(); |
| 230 | } |
| 231 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 232 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 233 | DCHECK(IsValid()); |
| 234 | return GetTypeHandle()->IsArrayClass(); |
| 235 | } |
| 236 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 237 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 238 | DCHECK(IsValid()); |
| 239 | return GetTypeHandle()->IsPrimitiveArray(); |
| 240 | } |
| 241 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 242 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 243 | DCHECK(IsValid()); |
| 244 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 245 | } |
| 246 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 247 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 248 | DCHECK(IsValid()); |
| 249 | if (!IsExact()) return false; |
| 250 | if (!IsArrayClass()) return false; |
| 251 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 252 | } |
| 253 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 254 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 255 | DCHECK(IsValid()); |
| 256 | if (!IsExact()) return false; |
| 257 | if (!IsArrayClass()) return false; |
| 258 | if (!rti.IsArrayClass()) return false; |
| 259 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 260 | rti.GetTypeHandle()->GetComponentType()); |
| 261 | } |
| 262 | |
| 263 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 264 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 265 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 266 | DCHECK(IsValid()); |
| 267 | DCHECK(rti.IsValid()); |
| 268 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 269 | } |
| 270 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 271 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 272 | DCHECK(IsValid()); |
| 273 | DCHECK(rti.IsValid()); |
| 274 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 275 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 276 | } |
| 277 | |
| 278 | // Returns true if the type information provide the same amount of details. |
| 279 | // Note that it does not mean that the instructions have the same actual type |
| 280 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 281 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 282 | if (!IsValid() && !rti.IsValid()) { |
| 283 | // Invalid types are equal. |
| 284 | return true; |
| 285 | } |
| 286 | if (!IsValid() || !rti.IsValid()) { |
| 287 | // One is valid, the other not. |
| 288 | return false; |
| 289 | } |
| 290 | return IsExact() == rti.IsExact() |
| 291 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 292 | } |
| 293 | |
| 294 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 295 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 296 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 297 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 298 | |
| 299 | // The class of the object. |
| 300 | TypeHandle type_handle_; |
| 301 | // Whether or not the type is exact or a superclass of the actual type. |
| 302 | // Whether or not we have any information about this type. |
| 303 | bool is_exact_; |
| 304 | }; |
| 305 | |
| 306 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 307 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 308 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 309 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 310 | public: |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 311 | HGraph(ArenaAllocator* allocator, |
| 312 | ArenaStack* arena_stack, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 313 | const DexFile& dex_file, |
| 314 | uint32_t method_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 315 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 316 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 317 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 318 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 319 | int start_instruction_id = 0) |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 320 | : allocator_(allocator), |
| 321 | arena_stack_(arena_stack), |
| 322 | blocks_(allocator->Adapter(kArenaAllocBlockList)), |
| 323 | reverse_post_order_(allocator->Adapter(kArenaAllocReversePostOrder)), |
| 324 | linear_order_(allocator->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 325 | entry_block_(nullptr), |
| 326 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 327 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 328 | number_of_vregs_(0), |
| 329 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 330 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 331 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 332 | has_try_catch_(false), |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 333 | has_simd_(false), |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 334 | has_loops_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 335 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 336 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 337 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 338 | dex_file_(dex_file), |
| 339 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 340 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 341 | in_ssa_form_(false), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 342 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 343 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 344 | cached_null_constant_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 345 | cached_int_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 346 | cached_float_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 347 | cached_long_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 348 | cached_double_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 349 | cached_current_method_(nullptr), |
Nicolas Geoffray | 53fec08 | 2017-03-27 12:56:16 +0100 | [diff] [blame] | 350 | art_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 351 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 352 | osr_(osr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 353 | cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 354 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 355 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 356 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 357 | // Acquires and stores RTI of inexact Object to be used when creating HNullConstant. |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 358 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 359 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 360 | ArenaAllocator* GetAllocator() const { return allocator_; } |
| 361 | ArenaStack* GetArenaStack() const { return arena_stack_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 362 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 363 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 364 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 365 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 366 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 367 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 368 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 369 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 370 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 371 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 372 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 373 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 374 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 375 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 376 | void ComputeDominanceInformation(); |
| 377 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 378 | void ClearLoopInformation(); |
| 379 | void FindBackEdges(ArenaBitVector* visited); |
| 380 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 381 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 382 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 383 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 384 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 385 | // was successful or the reason for failure. The method will fail if a loop |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 386 | // is a throw-catch loop, i.e. the header is a catch block. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 387 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 388 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 389 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 390 | // order and loop information. |
| 391 | void ComputeTryBlockInformation(); |
| 392 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 393 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 394 | // Returns the instruction to replace the invoke expression or null if the |
| 395 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 396 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 397 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 398 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 399 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 400 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 401 | // should be the new back edge. |
| 402 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 403 | HBasicBlock* reference, |
| 404 | bool replace_if_back_edge); |
| 405 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 406 | // Need to add a couple of blocks to test if the loop body is entered and |
| 407 | // put deoptimization instructions, etc. |
| 408 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 409 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 410 | // Adds a new loop directly after the loop with the given header and exit. |
| 411 | // Returns the new preheader. |
| 412 | HBasicBlock* TransformLoopForVectorization(HBasicBlock* header, |
| 413 | HBasicBlock* body, |
| 414 | HBasicBlock* exit); |
| 415 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 416 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 417 | // other blocks and has no instructions or phis. |
| 418 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 419 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 420 | // Splits the edge between `block` and `successor` while preserving the |
| 421 | // indices in the predecessor/successor lists. If there are multiple edges |
| 422 | // between the blocks, the lowest indices are used. |
| 423 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 424 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 425 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 426 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
Artem Serov | c73ee37 | 2017-07-31 15:08:40 +0100 | [diff] [blame] | 427 | void OrderLoopHeaderPredecessors(HBasicBlock* header); |
Artem Serov | 09faaea | 2017-12-07 14:36:01 +0000 | [diff] [blame] | 428 | |
| 429 | // Transform a loop into a format with a single preheader. |
| 430 | // |
| 431 | // Each phi in the header should be split: original one in the header should only hold |
| 432 | // inputs reachable from the back edges and a single input from the preheader. The newly created |
| 433 | // phi in the preheader should collate the inputs from the original multiple incoming blocks. |
| 434 | // |
| 435 | // Loops in the graph typically have a single preheader, so this method is used to "repair" loops |
| 436 | // that no longer have this property. |
| 437 | void TransformLoopToSinglePreheaderFormat(HBasicBlock* header); |
| 438 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 439 | void SimplifyLoop(HBasicBlock* header); |
| 440 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 441 | int32_t GetNextInstructionId() { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 442 | CHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 443 | return current_instruction_id_++; |
| 444 | } |
| 445 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 446 | int32_t GetCurrentInstructionId() const { |
| 447 | return current_instruction_id_; |
| 448 | } |
| 449 | |
| 450 | void SetCurrentInstructionId(int32_t id) { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 451 | CHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 452 | current_instruction_id_ = id; |
| 453 | } |
| 454 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 455 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 456 | return maximum_number_of_out_vregs_; |
| 457 | } |
| 458 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 459 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 460 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 461 | } |
| 462 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 463 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 464 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 465 | } |
| 466 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 467 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 468 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 469 | } |
| 470 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 471 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 472 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 473 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 474 | } |
| 475 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 476 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 477 | number_of_vregs_ = number_of_vregs; |
| 478 | } |
| 479 | |
| 480 | uint16_t GetNumberOfVRegs() const { |
| 481 | return number_of_vregs_; |
| 482 | } |
| 483 | |
| 484 | void SetNumberOfInVRegs(uint16_t value) { |
| 485 | number_of_in_vregs_ = value; |
| 486 | } |
| 487 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 488 | uint16_t GetNumberOfInVRegs() const { |
| 489 | return number_of_in_vregs_; |
| 490 | } |
| 491 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 492 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 493 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 494 | return number_of_vregs_ - number_of_in_vregs_; |
| 495 | } |
| 496 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 497 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 498 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 499 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 500 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 501 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 502 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 503 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 504 | } |
| 505 | |
| 506 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 507 | return ReverseRange(GetReversePostOrder()); |
| 508 | } |
| 509 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 510 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 511 | return linear_order_; |
| 512 | } |
| 513 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 514 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 515 | return ReverseRange(GetLinearOrder()); |
| 516 | } |
| 517 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 518 | bool HasBoundsChecks() const { |
| 519 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 520 | } |
| 521 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 522 | void SetHasBoundsChecks(bool value) { |
| 523 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 526 | bool IsDebuggable() const { return debuggable_; } |
| 527 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 528 | // Returns a constant of the given type and value. If it does not exist |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 529 | // already, it is created and inserted into the graph. This method is only for |
| 530 | // integral types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 531 | HConstant* GetConstant(DataType::Type type, int64_t value, uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 532 | |
| 533 | // TODO: This is problematic for the consistency of reference type propagation |
| 534 | // because it can be created anytime after the pass and thus it will be left |
| 535 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 536 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 537 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 538 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 539 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 540 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 541 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 542 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 543 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 544 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 545 | return CreateConstant(bit_cast<int32_t, float>(value), &cached_float_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 546 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 547 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 548 | return CreateConstant(bit_cast<int64_t, double>(value), &cached_double_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 549 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 550 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 551 | HCurrentMethod* GetCurrentMethod(); |
| 552 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 553 | const DexFile& GetDexFile() const { |
| 554 | return dex_file_; |
| 555 | } |
| 556 | |
| 557 | uint32_t GetMethodIdx() const { |
| 558 | return method_idx_; |
| 559 | } |
| 560 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 561 | // Get the method name (without the signature), e.g. "<init>" |
| 562 | const char* GetMethodName() const; |
| 563 | |
| 564 | // Get the pretty method name (class + name + optionally signature). |
| 565 | std::string PrettyMethod(bool with_signature = true) const; |
| 566 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 567 | InvokeType GetInvokeType() const { |
| 568 | return invoke_type_; |
| 569 | } |
| 570 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 571 | InstructionSet GetInstructionSet() const { |
| 572 | return instruction_set_; |
| 573 | } |
| 574 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 575 | bool IsCompilingOsr() const { return osr_; } |
| 576 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 577 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 578 | return cha_single_implementation_list_; |
| 579 | } |
| 580 | |
| 581 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 582 | cha_single_implementation_list_.insert(method); |
| 583 | } |
| 584 | |
| 585 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 586 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 587 | } |
| 588 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 589 | bool HasTryCatch() const { return has_try_catch_; } |
| 590 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 591 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 592 | bool HasSIMD() const { return has_simd_; } |
| 593 | void SetHasSIMD(bool value) { has_simd_ = value; } |
| 594 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 595 | bool HasLoops() const { return has_loops_; } |
| 596 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 597 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 598 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 599 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 600 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 601 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 602 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 603 | |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 604 | // Returns an instruction with the opposite Boolean value from 'cond'. |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 605 | // The instruction has been inserted into the graph, either as a constant, or |
| 606 | // before cursor. |
| 607 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 608 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 609 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 610 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 611 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 612 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 613 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 614 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 615 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 616 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 617 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 618 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 619 | template <class InstructionType, typename ValueType> |
| 620 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 621 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 622 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 623 | // Try to find an existing constant of the given value. |
| 624 | InstructionType* constant = nullptr; |
| 625 | auto cached_constant = cache->find(value); |
| 626 | if (cached_constant != cache->end()) { |
| 627 | constant = cached_constant->second; |
| 628 | } |
| 629 | |
| 630 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 631 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 632 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 633 | constant = new (allocator_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 634 | cache->Overwrite(value, constant); |
| 635 | InsertConstant(constant); |
| 636 | } |
| 637 | return constant; |
| 638 | } |
| 639 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 640 | void InsertConstant(HConstant* instruction); |
| 641 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 642 | // Cache a float constant into the graph. This method should only be |
| 643 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 644 | void CacheFloatConstant(HFloatConstant* constant); |
| 645 | |
| 646 | // See CacheFloatConstant comment. |
| 647 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 648 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 649 | ArenaAllocator* const allocator_; |
| 650 | ArenaStack* const arena_stack_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 651 | |
| 652 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 653 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 654 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 655 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 656 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 657 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 658 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 659 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 660 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 661 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 662 | HBasicBlock* entry_block_; |
| 663 | HBasicBlock* exit_block_; |
| 664 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 665 | // The maximum number of virtual registers arguments passed to a HInvoke in this graph. |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 666 | uint16_t maximum_number_of_out_vregs_; |
| 667 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 668 | // The number of virtual registers in this method. Contains the parameters. |
| 669 | uint16_t number_of_vregs_; |
| 670 | |
| 671 | // The number of virtual registers used by parameters of this method. |
| 672 | uint16_t number_of_in_vregs_; |
| 673 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 674 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 675 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 676 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 677 | // Flag whether there are bounds checks in the graph. We can skip |
| 678 | // BCE if it's false. It's only best effort to keep it up to date in |
| 679 | // the presence of code elimination so there might be false positives. |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 680 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 681 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 682 | // Flag whether there are try/catch blocks in the graph. We will skip |
| 683 | // try/catch-related passes if it's false. It's only best effort to keep |
| 684 | // it up to date in the presence of code elimination so there might be |
| 685 | // false positives. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 686 | bool has_try_catch_; |
| 687 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 688 | // Flag whether SIMD instructions appear in the graph. If true, the |
| 689 | // code generators may have to be more careful spilling the wider |
| 690 | // contents of SIMD registers. |
| 691 | bool has_simd_; |
| 692 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 693 | // Flag whether there are any loops in the graph. We can skip loop |
| 694 | // optimization if it's false. It's only best effort to keep it up |
| 695 | // to date in the presence of code elimination so there might be false |
| 696 | // positives. |
| 697 | bool has_loops_; |
| 698 | |
| 699 | // Flag whether there are any irreducible loops in the graph. It's only |
| 700 | // best effort to keep it up to date in the presence of code elimination |
| 701 | // so there might be false positives. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 702 | bool has_irreducible_loops_; |
| 703 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 704 | // Indicates whether the graph should be compiled in a way that |
| 705 | // ensures full debuggability. If false, we can apply more |
| 706 | // aggressive optimizations that may limit the level of debugging. |
| 707 | const bool debuggable_; |
| 708 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 709 | // The current id to assign to a newly added instruction. See HInstruction.id_. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 710 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 711 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 712 | // The dex file from which the method is from. |
| 713 | const DexFile& dex_file_; |
| 714 | |
| 715 | // The method index in the dex file. |
| 716 | const uint32_t method_idx_; |
| 717 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 718 | // If inlined, this encodes how the callee is being invoked. |
| 719 | const InvokeType invoke_type_; |
| 720 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 721 | // Whether the graph has been transformed to SSA form. Only used |
| 722 | // in debug mode to ensure we are not using properties only valid |
| 723 | // for non-SSA form (like the number of temporaries). |
| 724 | bool in_ssa_form_; |
| 725 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 726 | // Number of CHA guards in the graph. Used to short-circuit the |
| 727 | // CHA guard optimization pass when there is no CHA guard left. |
| 728 | uint32_t number_of_cha_guards_; |
| 729 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 730 | const InstructionSet instruction_set_; |
| 731 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 732 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 733 | HNullConstant* cached_null_constant_; |
| 734 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 735 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 736 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 737 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 738 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 739 | HCurrentMethod* cached_current_method_; |
| 740 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 741 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 742 | // for example for methods whose declaring class could not be resolved |
| 743 | // (such as when the superclass could not be found). |
| 744 | ArtMethod* art_method_; |
| 745 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 746 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 747 | // collection pointer to passes which may create NullConstant. |
| 748 | ReferenceTypeInfo inexact_object_rti_; |
| 749 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 750 | // Whether we are compiling this graph for on stack replacement: this will |
| 751 | // make all loops seen as irreducible and emit special stack maps to mark |
| 752 | // compiled code entries which the interpreter can directly jump to. |
| 753 | const bool osr_; |
| 754 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 755 | // List of methods that are assumed to have single implementation. |
| 756 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 757 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 758 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 759 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 760 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 761 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 762 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 763 | }; |
| 764 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 765 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 766 | public: |
| 767 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 768 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 769 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 770 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 771 | contains_irreducible_loop_(false), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 772 | back_edges_(graph->GetAllocator()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 773 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 774 | blocks_(graph->GetAllocator(), |
| 775 | graph->GetBlocks().size(), |
| 776 | true, |
| 777 | kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 778 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 779 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 780 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 781 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 782 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 783 | |
| 784 | void Dump(std::ostream& os); |
| 785 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 786 | HBasicBlock* GetHeader() const { |
| 787 | return header_; |
| 788 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 789 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 790 | void SetHeader(HBasicBlock* block) { |
| 791 | header_ = block; |
| 792 | } |
| 793 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 794 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 795 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 796 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 797 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 798 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 799 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 802 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 803 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 804 | } |
| 805 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 806 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 807 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 808 | } |
| 809 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 810 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 811 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 814 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 815 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 816 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 817 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 818 | } |
| 819 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 820 | // Returns the lifetime position of the back edge that has the |
| 821 | // greatest lifetime position. |
| 822 | size_t GetLifetimeEnd() const; |
| 823 | |
| 824 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 825 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 826 | } |
| 827 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 828 | // Finds blocks that are part of this loop. |
| 829 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 830 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 831 | // Updates blocks population of the loop and all of its outer' ones recursively after the |
| 832 | // population of the inner loop is updated. |
| 833 | void PopulateInnerLoopUpwards(HLoopInformation* inner_loop); |
| 834 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 835 | // Returns whether this loop information contains `block`. |
| 836 | // Note that this loop information *must* be populated before entering this function. |
| 837 | bool Contains(const HBasicBlock& block) const; |
| 838 | |
| 839 | // Returns whether this loop information is an inner loop of `other`. |
| 840 | // Note that `other` *must* be populated before entering this function. |
| 841 | bool IsIn(const HLoopInformation& other) const; |
| 842 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 843 | // Returns true if instruction is not defined within this loop. |
| 844 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 845 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 846 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 847 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 848 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 849 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 850 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 851 | void ClearAllBlocks() { |
| 852 | blocks_.ClearAllBits(); |
| 853 | } |
| 854 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 855 | bool HasBackEdgeNotDominatedByHeader() const; |
| 856 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 857 | bool IsPopulated() const { |
| 858 | return blocks_.GetHighestBitSet() != -1; |
| 859 | } |
| 860 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 861 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 862 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 863 | bool HasExitEdge() const; |
| 864 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 865 | // Resets back edge and blocks-in-loop data. |
| 866 | void ResetBasicBlockData() { |
| 867 | back_edges_.clear(); |
| 868 | ClearAllBlocks(); |
| 869 | } |
| 870 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 871 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 872 | // Internal recursive implementation of `Populate`. |
| 873 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 874 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 875 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 876 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 877 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 878 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 879 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 880 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 881 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 882 | |
| 883 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 884 | }; |
| 885 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 886 | // Stores try/catch information for basic blocks. |
| 887 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 888 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 889 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 890 | public: |
| 891 | // Try block information constructor. |
| 892 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 893 | : try_entry_(&try_entry), |
| 894 | catch_dex_file_(nullptr), |
| 895 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 896 | DCHECK(try_entry_ != nullptr); |
| 897 | } |
| 898 | |
| 899 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 900 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 901 | : try_entry_(nullptr), |
| 902 | catch_dex_file_(&dex_file), |
| 903 | catch_type_index_(catch_type_index) {} |
| 904 | |
| 905 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 906 | |
| 907 | const HTryBoundary& GetTryEntry() const { |
| 908 | DCHECK(IsTryBlock()); |
| 909 | return *try_entry_; |
| 910 | } |
| 911 | |
| 912 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 913 | |
| 914 | bool IsCatchAllTypeIndex() const { |
| 915 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 916 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 917 | } |
| 918 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 919 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 920 | DCHECK(IsCatchBlock()); |
| 921 | return catch_type_index_; |
| 922 | } |
| 923 | |
| 924 | const DexFile& GetCatchDexFile() const { |
| 925 | DCHECK(IsCatchBlock()); |
| 926 | return *catch_dex_file_; |
| 927 | } |
| 928 | |
| 929 | private: |
| 930 | // One of possibly several TryBoundary instructions entering the block's try. |
| 931 | // Only set for try blocks. |
| 932 | const HTryBoundary* try_entry_; |
| 933 | |
| 934 | // Exception type information. Only set for catch blocks. |
| 935 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 936 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 937 | }; |
| 938 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 939 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 940 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 941 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 942 | // A block in a method. Contains the list of instructions represented |
| 943 | // as a double linked list. Each block knows its predecessors and |
| 944 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 945 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 946 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 947 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 948 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 949 | : graph_(graph), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 950 | predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), |
| 951 | successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 952 | loop_information_(nullptr), |
| 953 | dominator_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 954 | dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 955 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 956 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 957 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 958 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 959 | try_catch_information_(nullptr) { |
| 960 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 961 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 962 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 963 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 964 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 965 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 966 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 967 | } |
| 968 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 969 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 970 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 971 | } |
| 972 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 973 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 974 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 975 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 976 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 977 | return ContainsElement(successors_, block, start_from); |
| 978 | } |
| 979 | |
| 980 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 981 | return dominated_blocks_; |
| 982 | } |
| 983 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 984 | bool IsEntryBlock() const { |
| 985 | return graph_->GetEntryBlock() == this; |
| 986 | } |
| 987 | |
| 988 | bool IsExitBlock() const { |
| 989 | return graph_->GetExitBlock() == this; |
| 990 | } |
| 991 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 992 | bool IsSingleGoto() const; |
Mads Ager | 16e5289 | 2017-07-14 13:11:37 +0200 | [diff] [blame] | 993 | bool IsSingleReturn() const; |
Mingyao Yang | 46721ef | 2017-10-05 14:45:17 -0700 | [diff] [blame] | 994 | bool IsSingleReturnOrReturnVoidAllowingPhis() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 995 | bool IsSingleTryBoundary() const; |
| 996 | |
| 997 | // Returns true if this block emits nothing but a jump. |
| 998 | bool IsSingleJump() const { |
| 999 | HLoopInformation* loop_info = GetLoopInformation(); |
| 1000 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 1001 | // Back edges generate a suspend check. |
| 1002 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 1003 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1004 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1005 | void AddBackEdge(HBasicBlock* back_edge) { |
| 1006 | if (loop_information_ == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1007 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1008 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1009 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1010 | loop_information_->AddBackEdge(back_edge); |
| 1011 | } |
| 1012 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 1013 | // Registers a back edge; if the block was not a loop header before the call associates a newly |
| 1014 | // created loop info with it. |
| 1015 | // |
| 1016 | // Used in SuperblockCloner to preserve LoopInformation object instead of reseting loop |
| 1017 | // info for all blocks during back edges recalculation. |
| 1018 | void AddBackEdgeWhileUpdating(HBasicBlock* back_edge) { |
| 1019 | if (loop_information_ == nullptr || loop_information_->GetHeader() != this) { |
| 1020 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
| 1021 | } |
| 1022 | loop_information_->AddBackEdge(back_edge); |
| 1023 | } |
| 1024 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1025 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1026 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1027 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1028 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1029 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1030 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1031 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1032 | HBasicBlock* GetDominator() const { return dominator_; } |
| 1033 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1034 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 1035 | |
| 1036 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 1037 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 1038 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1039 | |
| 1040 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1041 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 1042 | } |
| 1043 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1044 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1045 | |
| 1046 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1047 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1050 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1051 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1052 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1053 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1054 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1055 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1056 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1057 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1058 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1059 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1060 | successors_.push_back(block); |
| 1061 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1064 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1065 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1066 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1067 | new_block->predecessors_.push_back(this); |
| 1068 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1071 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1072 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1073 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1074 | new_block->successors_.push_back(this); |
| 1075 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1078 | // Insert `this` between `predecessor` and `successor. This method |
| 1079 | // preserves the indicies, and will update the first edge found between |
| 1080 | // `predecessor` and `successor`. |
| 1081 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1082 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1083 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1084 | successor->predecessors_[predecessor_index] = this; |
| 1085 | predecessor->successors_[successor_index] = this; |
| 1086 | successors_.push_back(successor); |
| 1087 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1088 | } |
| 1089 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1090 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1091 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1092 | } |
| 1093 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1094 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1095 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1098 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1099 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1103 | predecessors_.push_back(block); |
| 1104 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1105 | } |
| 1106 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1107 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1108 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1109 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1110 | } |
| 1111 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1112 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1113 | DCHECK_EQ(successors_.size(), 2u); |
| 1114 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1115 | } |
| 1116 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1117 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1118 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1119 | } |
| 1120 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1121 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1122 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1123 | } |
| 1124 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1125 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1126 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1127 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1131 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1132 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1136 | // predecessors is at index `idx`. |
| 1137 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1138 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1139 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1140 | } |
| 1141 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1142 | // Create a new block between this block and its predecessors. The new block |
| 1143 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1144 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1145 | // loop and try/catch information are not updated. |
| 1146 | HBasicBlock* CreateImmediateDominator(); |
| 1147 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1148 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1149 | // created, latter block. Note that this method will add the block to the |
| 1150 | // graph, create a Goto at the end of the former block and will create an edge |
| 1151 | // between the blocks. It will not, however, update the reverse post order or |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1152 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1153 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1154 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1155 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1156 | // created block. Note that this method just updates raw block information, |
| 1157 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1158 | // update the graph, reverse post order, loop information, nor make sure the |
| 1159 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1160 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1161 | |
| 1162 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1163 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1164 | |
| 1165 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1166 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1167 | // that this method does not update the graph, reverse post order, loop |
| 1168 | // information, nor make sure the blocks are consistent (for example ending |
| 1169 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1170 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1171 | |
| 1172 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1173 | // of `this` are moved to `other`. |
| 1174 | // Note that this method does not update the graph, reverse post order, loop |
| 1175 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1176 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1177 | void ReplaceWith(HBasicBlock* other); |
| 1178 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1179 | // Merges the instructions of `other` at the end of `this`. |
| 1180 | void MergeInstructionsWith(HBasicBlock* other); |
| 1181 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1182 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1183 | // order, links to predecessors, successors, dominators and deletes the block |
| 1184 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1185 | // predecessor of `other` and vice versa. |
| 1186 | void MergeWith(HBasicBlock* other); |
| 1187 | |
| 1188 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1189 | // removes it from all loops it is included in and eventually from the graph. |
| 1190 | // The block must not dominate any other block. Predecessors and successors |
| 1191 | // are safely updated. |
| 1192 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1193 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1194 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1195 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1196 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1197 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1198 | // Replace phi `initial` with `replacement` within this block. |
| 1199 | void ReplaceAndRemovePhiWith(HPhi* initial, HPhi* replacement); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1200 | // Replace instruction `initial` with `replacement` within this block. |
| 1201 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1202 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1203 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1204 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1205 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1206 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1207 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1208 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1209 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1210 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1211 | |
| 1212 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1213 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1214 | } |
| 1215 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1216 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1217 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1218 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1219 | } |
| 1220 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1221 | bool IsFirstPredecessorBackEdge() const { |
| 1222 | DCHECK(IsLoopHeader()); |
| 1223 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1224 | } |
| 1225 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1226 | HLoopInformation* GetLoopInformation() const { |
| 1227 | return loop_information_; |
| 1228 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1229 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1230 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1231 | // loop_information if it is an outer loop of the passed loop information. |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1232 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1233 | void SetInLoop(HLoopInformation* info) { |
| 1234 | if (IsLoopHeader()) { |
| 1235 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1236 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1237 | loop_information_ = info; |
| 1238 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1239 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1240 | // Note that a non loop header having a loop information means this loop information |
| 1241 | // has already been populated |
| 1242 | loop_information_ = info; |
| 1243 | } else { |
| 1244 | // Block is part of an inner loop. Do not update the loop information. |
| 1245 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1246 | // at this point, because this method is being called while populating `info`. |
| 1247 | } |
| 1248 | } |
| 1249 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1250 | // Raw update of the loop information. |
| 1251 | void SetLoopInformation(HLoopInformation* info) { |
| 1252 | loop_information_ = info; |
| 1253 | } |
| 1254 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1255 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1256 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1257 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1258 | |
| 1259 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1260 | try_catch_information_ = try_catch_information; |
| 1261 | } |
| 1262 | |
| 1263 | bool IsTryBlock() const { |
| 1264 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1265 | } |
| 1266 | |
| 1267 | bool IsCatchBlock() const { |
| 1268 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1269 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1270 | |
| 1271 | // Returns the try entry that this block's successors should have. They will |
| 1272 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1273 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1274 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1275 | |
Aart Bik | 75ff2c9 | 2018-04-21 01:28:11 +0000 | [diff] [blame] | 1276 | bool HasThrowingInstructions() const; |
| 1277 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1278 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1279 | bool Dominates(HBasicBlock* block) const; |
| 1280 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1281 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1282 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1283 | |
| 1284 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1285 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1286 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1287 | bool EndsWithControlFlowInstruction() const; |
Aart Bik | 4dc09e7 | 2018-05-11 14:40:31 -0700 | [diff] [blame] | 1288 | bool EndsWithReturn() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1289 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1290 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1291 | bool HasSinglePhi() const; |
| 1292 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1293 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1294 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1295 | ArenaVector<HBasicBlock*> predecessors_; |
| 1296 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1297 | HInstructionList instructions_; |
| 1298 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1299 | HLoopInformation* loop_information_; |
| 1300 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1301 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1302 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1303 | // The dex program counter of the first instruction of this block. |
| 1304 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1305 | size_t lifetime_start_; |
| 1306 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1307 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1308 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1309 | friend class HGraph; |
| 1310 | friend class HInstruction; |
| 1311 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1312 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1313 | }; |
| 1314 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1315 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1316 | // from the innermost to the outermost. |
| 1317 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1318 | public: |
| 1319 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1320 | : current_(block.GetLoopInformation()) {} |
| 1321 | |
| 1322 | bool Done() const { return current_ == nullptr; } |
| 1323 | |
| 1324 | void Advance() { |
| 1325 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1326 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | HLoopInformation* Current() const { |
| 1330 | DCHECK(!Done()); |
| 1331 | return current_; |
| 1332 | } |
| 1333 | |
| 1334 | private: |
| 1335 | HLoopInformation* current_; |
| 1336 | |
| 1337 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1338 | }; |
| 1339 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1340 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1341 | M(Above, Condition) \ |
| 1342 | M(AboveOrEqual, Condition) \ |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 1343 | M(Abs, UnaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1344 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1345 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1346 | M(ArrayGet, Instruction) \ |
| 1347 | M(ArrayLength, Instruction) \ |
| 1348 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1349 | M(Below, Condition) \ |
| 1350 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1351 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1352 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1353 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1354 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1355 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1356 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1357 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1358 | M(Compare, BinaryOperation) \ |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1359 | M(ConstructorFence, Instruction) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1360 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1361 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1362 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1363 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1364 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1365 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1366 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1367 | M(Exit, Instruction) \ |
| 1368 | M(FloatConstant, Constant) \ |
| 1369 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1370 | M(GreaterThan, Condition) \ |
| 1371 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1372 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1373 | M(InstanceFieldGet, Instruction) \ |
| 1374 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1375 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1376 | M(IntConstant, Constant) \ |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 1377 | M(IntermediateAddress, Instruction) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1378 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1379 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1380 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1381 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1382 | M(InvokePolymorphic, Invoke) \ |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame^] | 1383 | M(InvokeCustom, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1384 | M(LessThan, Condition) \ |
| 1385 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1386 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1387 | M(LoadException, Instruction) \ |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 1388 | M(LoadMethodHandle, Instruction) \ |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 1389 | M(LoadMethodType, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1390 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1391 | M(LongConstant, Constant) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1392 | M(Max, Instruction) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1393 | M(MemoryBarrier, Instruction) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1394 | M(Min, BinaryOperation) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1395 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1396 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1397 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1398 | M(Neg, UnaryOperation) \ |
| 1399 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1400 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1401 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1402 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1403 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1404 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1405 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1406 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1407 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1408 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1409 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1410 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1411 | M(Return, Instruction) \ |
| 1412 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1413 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1414 | M(Shl, BinaryOperation) \ |
| 1415 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1416 | M(StaticFieldGet, Instruction) \ |
| 1417 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1418 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1419 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1420 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1421 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1422 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1423 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1424 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1425 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1426 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1427 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1428 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1429 | M(Xor, BinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1430 | M(VecReplicateScalar, VecUnaryOperation) \ |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1431 | M(VecExtractScalar, VecUnaryOperation) \ |
| 1432 | M(VecReduce, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1433 | M(VecCnv, VecUnaryOperation) \ |
| 1434 | M(VecNeg, VecUnaryOperation) \ |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1435 | M(VecAbs, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1436 | M(VecNot, VecUnaryOperation) \ |
| 1437 | M(VecAdd, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1438 | M(VecHalvingAdd, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1439 | M(VecSub, VecBinaryOperation) \ |
| 1440 | M(VecMul, VecBinaryOperation) \ |
| 1441 | M(VecDiv, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1442 | M(VecMin, VecBinaryOperation) \ |
| 1443 | M(VecMax, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1444 | M(VecAnd, VecBinaryOperation) \ |
| 1445 | M(VecAndNot, VecBinaryOperation) \ |
| 1446 | M(VecOr, VecBinaryOperation) \ |
| 1447 | M(VecXor, VecBinaryOperation) \ |
Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1448 | M(VecSaturationAdd, VecBinaryOperation) \ |
| 1449 | M(VecSaturationSub, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1450 | M(VecShl, VecBinaryOperation) \ |
| 1451 | M(VecShr, VecBinaryOperation) \ |
| 1452 | M(VecUShr, VecBinaryOperation) \ |
Aart Bik | 8de5916 | 2017-04-21 09:42:01 -0700 | [diff] [blame] | 1453 | M(VecSetScalars, VecOperation) \ |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1454 | M(VecMultiplyAccumulate, VecOperation) \ |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1455 | M(VecSADAccumulate, VecOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1456 | M(VecLoad, VecMemoryOperation) \ |
| 1457 | M(VecStore, VecMemoryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1458 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1459 | /* |
| 1460 | * Instructions, shared across several (not all) architectures. |
| 1461 | */ |
| 1462 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1463 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1464 | #else |
| 1465 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1466 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1467 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1468 | M(MultiplyAccumulate, Instruction) \ |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 1469 | M(IntermediateAddressIndex, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1470 | #endif |
| 1471 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1472 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1473 | |
| 1474 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1475 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1476 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1477 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1478 | #else |
| 1479 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1480 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 1481 | M(MipsPackedSwitch, Instruction) \ |
| 1482 | M(IntermediateArrayAddressIndex, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1483 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1484 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1485 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1486 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1487 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1488 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1489 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1490 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1491 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1492 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1493 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1494 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1495 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1496 | |
| 1497 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1498 | |
| 1499 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1500 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1501 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1502 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1503 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1504 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1505 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1506 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1507 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1508 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1509 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1510 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1511 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1512 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1513 | M(BinaryOperation, Instruction) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1514 | M(Invoke, Instruction) \ |
| 1515 | M(VecOperation, Instruction) \ |
| 1516 | M(VecUnaryOperation, VecOperation) \ |
| 1517 | M(VecBinaryOperation, VecOperation) \ |
| 1518 | M(VecMemoryOperation, VecOperation) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1519 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1520 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1521 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1522 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1523 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1524 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1525 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1526 | #undef FORWARD_DECLARATION |
| 1527 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1528 | #define DECLARE_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1529 | private: \ |
| 1530 | H##type& operator=(const H##type&) = delete; \ |
| 1531 | public: \ |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1532 | const char* DebugName() const OVERRIDE { return #type; } \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1533 | HInstruction* Clone(ArenaAllocator* arena) const OVERRIDE { \ |
| 1534 | DCHECK(IsClonable()); \ |
| 1535 | return new (arena) H##type(*this->As##type()); \ |
| 1536 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1537 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1538 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1539 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1540 | private: \ |
| 1541 | H##type& operator=(const H##type&) = delete; \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 1542 | public: |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1543 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1544 | #define DEFAULT_COPY_CONSTRUCTOR(type) \ |
| 1545 | explicit H##type(const H##type& other) = default; |
| 1546 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1547 | template <typename T> |
Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 1548 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode>, |
| 1549 | public IntrusiveForwardListNode<HUseListNode<T>> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1550 | public: |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1551 | // Get the instruction which has this use as one of the inputs. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1552 | T GetUser() const { return user_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1553 | // Get the position of the input record that this use corresponds to. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1554 | size_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1555 | // Set the position of the input record that this use corresponds to. |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1556 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1557 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1558 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1559 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1560 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1561 | |
| 1562 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1563 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1564 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1565 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1566 | |
| 1567 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1568 | }; |
| 1569 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1570 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1571 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1572 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1573 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1574 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1575 | // by the used instructions. |
| 1576 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1577 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1578 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1579 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1580 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1581 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1582 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1583 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1584 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1585 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1586 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1590 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1591 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1592 | |
| 1593 | private: |
| 1594 | // Instruction used by the user. |
| 1595 | HInstruction* instruction_; |
| 1596 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1597 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1598 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1599 | }; |
| 1600 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1601 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1602 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1603 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1604 | struct HInputExtractor { |
| 1605 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1606 | return record.GetInstruction(); |
| 1607 | } |
| 1608 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1609 | return record.GetInstruction(); |
| 1610 | } |
| 1611 | }; |
| 1612 | |
| 1613 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1614 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1615 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1616 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1617 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1618 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1619 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1620 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1621 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1622 | * modify the value of a reference field read [although it may modify the |
| 1623 | * reference fetch prior to reading the field, which is represented by its own |
| 1624 | * write/read dependence]). The analysis makes conservative points-to |
| 1625 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1626 | * the same, and any reference read depends on any reference read without |
| 1627 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1628 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1629 | * The internal representation uses 38-bit and is described in the table below. |
| 1630 | * The first line indicates the side effect, and for field/array accesses the |
| 1631 | * 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] | 1632 | * DataType::Type enum). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1633 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1634 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1635 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1636 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1637 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1638 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1639 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1640 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1641 | * |
| 1642 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1643 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1644 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1645 | class SideEffects : public ValueObject { |
| 1646 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1647 | SideEffects() : flags_(0) {} |
| 1648 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1649 | static SideEffects None() { |
| 1650 | return SideEffects(0); |
| 1651 | } |
| 1652 | |
| 1653 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1654 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1655 | } |
| 1656 | |
| 1657 | static SideEffects AllChanges() { |
| 1658 | return SideEffects(kAllChangeBits); |
| 1659 | } |
| 1660 | |
| 1661 | static SideEffects AllDependencies() { |
| 1662 | return SideEffects(kAllDependOnBits); |
| 1663 | } |
| 1664 | |
| 1665 | static SideEffects AllExceptGCDependency() { |
| 1666 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1667 | } |
| 1668 | |
| 1669 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1670 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1671 | } |
| 1672 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1673 | static SideEffects AllWrites() { |
| 1674 | return SideEffects(kAllWrites); |
| 1675 | } |
| 1676 | |
| 1677 | static SideEffects AllReads() { |
| 1678 | return SideEffects(kAllReads); |
| 1679 | } |
| 1680 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1681 | static SideEffects FieldWriteOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1682 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1683 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1684 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1685 | } |
| 1686 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1687 | static SideEffects ArrayWriteOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1688 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1689 | } |
| 1690 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1691 | static SideEffects FieldReadOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1692 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1693 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1694 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1697 | static SideEffects ArrayReadOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1698 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1701 | static SideEffects CanTriggerGC() { |
| 1702 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1703 | } |
| 1704 | |
| 1705 | static SideEffects DependsOnGC() { |
| 1706 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1707 | } |
| 1708 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1709 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1710 | SideEffects Union(SideEffects other) const { |
| 1711 | return SideEffects(flags_ | other.flags_); |
| 1712 | } |
| 1713 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1714 | SideEffects Exclusion(SideEffects other) const { |
| 1715 | return SideEffects(flags_ & ~other.flags_); |
| 1716 | } |
| 1717 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1718 | void Add(SideEffects other) { |
| 1719 | flags_ |= other.flags_; |
| 1720 | } |
| 1721 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1722 | bool Includes(SideEffects other) const { |
| 1723 | return (other.flags_ & flags_) == other.flags_; |
| 1724 | } |
| 1725 | |
| 1726 | bool HasSideEffects() const { |
| 1727 | return (flags_ & kAllChangeBits); |
| 1728 | } |
| 1729 | |
| 1730 | bool HasDependencies() const { |
| 1731 | return (flags_ & kAllDependOnBits); |
| 1732 | } |
| 1733 | |
| 1734 | // Returns true if there are no side effects or dependencies. |
| 1735 | bool DoesNothing() const { |
| 1736 | return flags_ == 0; |
| 1737 | } |
| 1738 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1739 | // Returns true if something is written. |
| 1740 | bool DoesAnyWrite() const { |
| 1741 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1742 | } |
| 1743 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1744 | // Returns true if something is read. |
| 1745 | bool DoesAnyRead() const { |
| 1746 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1747 | } |
| 1748 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1749 | // Returns true if potentially everything is written and read |
| 1750 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1751 | bool DoesAllReadWrite() const { |
| 1752 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1753 | } |
| 1754 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1755 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1756 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1759 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1760 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1761 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1762 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1766 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1767 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1768 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1769 | for (int s = kLastBit; s >= 0; s--) { |
| 1770 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1771 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1772 | // This is a bit for the GC side effect. |
| 1773 | if (current_bit_is_set) { |
| 1774 | flags += "GC"; |
| 1775 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1776 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1777 | } else { |
| 1778 | // This is a bit for the array/field analysis. |
| 1779 | // The underscore character stands for the 'can trigger GC' bit. |
| 1780 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1781 | if (current_bit_is_set) { |
| 1782 | flags += kDebug[s]; |
| 1783 | } |
| 1784 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1785 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1786 | flags += "|"; |
| 1787 | } |
| 1788 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1789 | } |
| 1790 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1791 | } |
| 1792 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1793 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1794 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1795 | private: |
| 1796 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1797 | |
| 1798 | static constexpr int kFieldWriteOffset = 0; |
| 1799 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1800 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1801 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1802 | |
| 1803 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1804 | |
| 1805 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1806 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1807 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1808 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1809 | |
| 1810 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1811 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1812 | |
| 1813 | // Aliases. |
| 1814 | |
| 1815 | static_assert(kChangeBits == kDependOnBits, |
| 1816 | "the 'change' bits should match the 'depend on' bits."); |
| 1817 | |
| 1818 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1819 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1820 | static constexpr uint64_t kAllWrites = |
| 1821 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1822 | static constexpr uint64_t kAllReads = |
| 1823 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1824 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1825 | // 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] | 1826 | static uint64_t TypeFlag(DataType::Type type, int offset) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1827 | int shift; |
| 1828 | switch (type) { |
| 1829 | case DataType::Type::kReference: shift = 0; break; |
| 1830 | case DataType::Type::kBool: shift = 1; break; |
| 1831 | case DataType::Type::kInt8: shift = 2; break; |
| 1832 | case DataType::Type::kUint16: shift = 3; break; |
| 1833 | case DataType::Type::kInt16: shift = 4; break; |
| 1834 | case DataType::Type::kInt32: shift = 5; break; |
| 1835 | case DataType::Type::kInt64: shift = 6; break; |
| 1836 | case DataType::Type::kFloat32: shift = 7; break; |
| 1837 | case DataType::Type::kFloat64: shift = 8; break; |
| 1838 | default: |
| 1839 | LOG(FATAL) << "Unexpected data type " << type; |
| 1840 | UNREACHABLE(); |
| 1841 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1842 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1843 | DCHECK_LT(shift, kArrayWriteOffset); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1844 | return UINT64_C(1) << (shift + offset); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | // Private constructor on direct flags value. |
| 1848 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1849 | |
| 1850 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1851 | }; |
| 1852 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1853 | // 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] | 1854 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1855 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1856 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1857 | size_t number_of_vregs, |
| 1858 | ArtMethod* method, |
| 1859 | uint32_t dex_pc, |
| 1860 | HInstruction* holder) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1861 | : vregs_(number_of_vregs, allocator->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1862 | locations_(allocator->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1863 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1864 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1865 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1866 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1867 | } |
| 1868 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1869 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
| 1870 | const HEnvironment& to_copy, |
| 1871 | HInstruction* holder) |
| 1872 | : HEnvironment(allocator, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1873 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1874 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1875 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1876 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1877 | |
Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 1878 | void AllocateLocations() { |
| 1879 | DCHECK(locations_.empty()); |
| 1880 | locations_.resize(vregs_.size()); |
| 1881 | } |
| 1882 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1883 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1884 | if (parent_ != nullptr) { |
| 1885 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1886 | } else { |
| 1887 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1888 | parent_->CopyFrom(parent); |
| 1889 | if (parent->GetParent() != nullptr) { |
| 1890 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1891 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1892 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 1895 | void CopyFrom(ArrayRef<HInstruction* const> locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1896 | void CopyFrom(HEnvironment* environment); |
| 1897 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1898 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1899 | // input to the loop phi instead. This is for inserting instructions that |
| 1900 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1901 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1902 | |
| 1903 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1904 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1908 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1911 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1912 | |
Artem Serov | ca210e3 | 2017-12-15 13:43:20 +0000 | [diff] [blame] | 1913 | // Replaces the input at the position 'index' with the replacement; the replacement and old |
| 1914 | // input instructions' env_uses_ lists are adjusted. The function works similar to |
| 1915 | // HInstruction::ReplaceInput. |
| 1916 | void ReplaceInput(HInstruction* replacement, size_t index); |
| 1917 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1918 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1919 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1920 | HEnvironment* GetParent() const { return parent_; } |
| 1921 | |
| 1922 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1923 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1927 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | uint32_t GetDexPc() const { |
| 1931 | return dex_pc_; |
| 1932 | } |
| 1933 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1934 | ArtMethod* GetMethod() const { |
| 1935 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1936 | } |
| 1937 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1938 | HInstruction* GetHolder() const { |
| 1939 | return holder_; |
| 1940 | } |
| 1941 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1942 | |
| 1943 | bool IsFromInlinedInvoke() const { |
| 1944 | return GetParent() != nullptr; |
| 1945 | } |
| 1946 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1947 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1948 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1949 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1950 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1951 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1952 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1953 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1954 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1955 | HInstruction* const holder_; |
| 1956 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1957 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1958 | |
| 1959 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1960 | }; |
| 1961 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1962 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1963 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 1964 | #define DECLARE_KIND(type, super) k##type, |
| 1965 | enum InstructionKind { |
Vladimir Marko | e394622 | 2018-05-04 14:18:47 +0100 | [diff] [blame] | 1966 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_KIND) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 1967 | kLastInstructionKind |
| 1968 | }; |
| 1969 | #undef DECLARE_KIND |
| 1970 | |
| 1971 | HInstruction(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 1972 | : HInstruction(kind, DataType::Type::kVoid, side_effects, dex_pc) {} |
| 1973 | |
| 1974 | 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] | 1975 | : previous_(nullptr), |
| 1976 | next_(nullptr), |
| 1977 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1978 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1979 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1980 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1981 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1982 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1983 | locations_(nullptr), |
| 1984 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1985 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1986 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1987 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 1988 | SetPackedField<InstructionKindField>(kind); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 1989 | SetPackedField<TypeField>(type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1990 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1991 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1992 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1993 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1994 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1995 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1996 | HInstruction* GetNext() const { return next_; } |
| 1997 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1998 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1999 | HInstruction* GetNextDisregardingMoves() const; |
| 2000 | HInstruction* GetPreviousDisregardingMoves() const; |
| 2001 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2002 | HBasicBlock* GetBlock() const { return block_; } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2003 | ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2004 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 2005 | bool IsInBlock() const { return block_ != nullptr; } |
| 2006 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 2007 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 2008 | bool IsIrreducibleLoopHeaderPhi() const { |
| 2009 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 2010 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2011 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2012 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 2013 | |
| 2014 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 2015 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 2016 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 2017 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 2018 | } |
| 2019 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2020 | HInputsRef GetInputs() { |
| 2021 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2022 | } |
| 2023 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2024 | HConstInputsRef GetInputs() const { |
| 2025 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2029 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2030 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 2031 | bool HasInput(HInstruction* input) const { |
| 2032 | for (const HInstruction* i : GetInputs()) { |
| 2033 | if (i == input) { |
| 2034 | return true; |
| 2035 | } |
| 2036 | } |
| 2037 | return false; |
| 2038 | } |
| 2039 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2040 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 2041 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 2042 | } |
| 2043 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2044 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 2045 | virtual const char* DebugName() const = 0; |
| 2046 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2047 | DataType::Type GetType() const { |
| 2048 | return TypeField::Decode(GetPackedFields()); |
| 2049 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2050 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2051 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2052 | |
| 2053 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2054 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2055 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2056 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2057 | // Can the instruction throw? |
| 2058 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 2059 | // 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] | 2060 | virtual bool CanThrow() const { return false; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2061 | |
| 2062 | // Does the instruction always throw an exception unconditionally? |
| 2063 | virtual bool AlwaysThrows() const { return false; } |
| 2064 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2065 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2066 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2067 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2068 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2069 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2070 | // Does not apply for all instructions, but having this at top level greatly |
| 2071 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 2072 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2073 | virtual bool CanBeNull() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2074 | DCHECK_EQ(GetType(), DataType::Type::kReference) << "CanBeNull only applies to reference types"; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2075 | return true; |
| 2076 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2077 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2078 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 2079 | return false; |
| 2080 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2081 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2082 | virtual bool IsActualObject() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2083 | return GetType() == DataType::Type::kReference; |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 2086 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2087 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2088 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2089 | DCHECK_EQ(GetType(), DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2090 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 2091 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2092 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2093 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2094 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2095 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2096 | // Note: fixup_end remains valid across push_front(). |
| 2097 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 2098 | HUseListNode<HInstruction*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2099 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HInstruction*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2100 | uses_.push_front(*new_node); |
| 2101 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2104 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2105 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2106 | // Note: env_fixup_end remains valid across push_front(). |
| 2107 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2108 | HUseListNode<HEnvironment*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2109 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HEnvironment*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2110 | env_uses_.push_front(*new_node); |
| 2111 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2112 | } |
| 2113 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2114 | void RemoveAsUserOfInput(size_t input) { |
| 2115 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2116 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2117 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2118 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2119 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2120 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2121 | void RemoveAsUserOfAllInputs() { |
| 2122 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2123 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2124 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2125 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2126 | } |
| 2127 | } |
| 2128 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2129 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2130 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2131 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2132 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2133 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2134 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2135 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2136 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2137 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2138 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2139 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2140 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2141 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2142 | !CanThrow() && |
| 2143 | !IsSuspendCheck() && |
| 2144 | !IsControlFlow() && |
| 2145 | !IsNativeDebugInfo() && |
| 2146 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2147 | // If we added an explicit barrier then we should keep it. |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2148 | !IsMemoryBarrier() && |
| 2149 | !IsConstructorFence(); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2152 | bool IsDeadAndRemovable() const { |
| 2153 | return IsRemovable() && !HasUses(); |
| 2154 | } |
| 2155 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2156 | // Does this instruction strictly dominate `other_instruction`? |
| 2157 | // Returns false if this instruction and `other_instruction` are the same. |
| 2158 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2159 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2160 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2161 | int GetId() const { return id_; } |
| 2162 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2163 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2164 | int GetSsaIndex() const { return ssa_index_; } |
| 2165 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2166 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2167 | |
| 2168 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2169 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2170 | // Set the `environment_` field. Raw because this method does not |
| 2171 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2172 | void SetRawEnvironment(HEnvironment* environment) { |
| 2173 | DCHECK(environment_ == nullptr); |
| 2174 | DCHECK_EQ(environment->GetHolder(), this); |
| 2175 | environment_ = environment; |
| 2176 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2177 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2178 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2179 | DCHECK(environment_ != nullptr); |
| 2180 | DCHECK_EQ(environment->GetHolder(), this); |
| 2181 | DCHECK(environment->GetParent() == nullptr); |
| 2182 | environment->parent_ = environment_; |
| 2183 | environment_ = environment; |
| 2184 | } |
| 2185 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2186 | void RemoveEnvironment(); |
| 2187 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2188 | // Set the environment of this instruction, copying it from `environment`. While |
| 2189 | // copying, the uses lists are being updated. |
| 2190 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2191 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2192 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2193 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2194 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2195 | if (environment->GetParent() != nullptr) { |
| 2196 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2197 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2198 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2199 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2200 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2201 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2202 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2203 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2204 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2205 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2206 | if (environment->GetParent() != nullptr) { |
| 2207 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2208 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2209 | } |
| 2210 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2211 | // Returns the number of entries in the environment. Typically, that is the |
| 2212 | // number of dex registers in a method. It could be more in case of inlining. |
| 2213 | size_t EnvironmentSize() const; |
| 2214 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2215 | LocationSummary* GetLocations() const { return locations_; } |
| 2216 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2217 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2218 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2219 | void ReplaceUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2220 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2221 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2222 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2223 | // uses of this instruction by `other` are *not* updated. |
| 2224 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2225 | ReplaceWith(other); |
| 2226 | other->ReplaceInput(this, use_index); |
| 2227 | } |
| 2228 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2229 | // Move `this` instruction before `cursor` |
| 2230 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2231 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2232 | // Move `this` before its first user and out of any loops. If there is no |
| 2233 | // out-of-loop user that dominates all other users, move the instruction |
| 2234 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2235 | // |
| 2236 | // This can be used only on non-throwing instructions with no side effects that |
| 2237 | // have at least one use but no environment uses. |
| 2238 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2239 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2240 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2241 | bool Is##type() const; |
| 2242 | |
| 2243 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2244 | #undef INSTRUCTION_TYPE_CHECK |
| 2245 | |
| 2246 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2247 | const H##type* As##type() const; \ |
| 2248 | H##type* As##type(); |
| 2249 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2250 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 2251 | #undef INSTRUCTION_TYPE_CAST |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2252 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2253 | // Return a clone of the instruction if it is clonable (shallow copy by default, custom copy |
| 2254 | // if a custom copy-constructor is provided for a particular type). If IsClonable() is false for |
| 2255 | // the instruction then the behaviour of this function is undefined. |
| 2256 | // |
| 2257 | // Note: It is semantically valid to create a clone of the instruction only until |
| 2258 | // prepare_for_register_allocator phase as lifetime, intervals and codegen info are not |
| 2259 | // copied. |
| 2260 | // |
| 2261 | // Note: HEnvironment and some other fields are not copied and are set to default values, see |
| 2262 | // 'explicit HInstruction(const HInstruction& other)' for details. |
| 2263 | virtual HInstruction* Clone(ArenaAllocator* arena ATTRIBUTE_UNUSED) const { |
| 2264 | LOG(FATAL) << "Cloning is not implemented for the instruction " << |
| 2265 | DebugName() << " " << GetId(); |
| 2266 | UNREACHABLE(); |
| 2267 | } |
| 2268 | |
| 2269 | // Return whether instruction can be cloned (copied). |
| 2270 | virtual bool IsClonable() const { return false; } |
| 2271 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2272 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2273 | // TODO: this method is used by LICM and GVN with possibly different |
| 2274 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2275 | virtual bool CanBeMoved() const { return false; } |
| 2276 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2277 | // Returns whether any data encoded in the two instructions is equal. |
| 2278 | // This method does not look at the inputs. Both instructions must be |
| 2279 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2280 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2281 | return false; |
| 2282 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2283 | |
| 2284 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2285 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2286 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2287 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2288 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2289 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2290 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2291 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2292 | // apply the strong requirement for virtual functions, preventing optimizations. |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2293 | InstructionKind GetKind() const { return GetPackedField<InstructionKindField>(); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2294 | |
| 2295 | virtual size_t ComputeHashCode() const { |
| 2296 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2297 | for (const HInstruction* input : GetInputs()) { |
| 2298 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2299 | } |
| 2300 | return result; |
| 2301 | } |
| 2302 | |
| 2303 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2304 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2305 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2306 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2307 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2308 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2309 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2310 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2311 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2312 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2313 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2314 | |
| 2315 | // Returns whether the code generation of the instruction will require to have access |
| 2316 | // to the current method. Such instructions are: |
| 2317 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2318 | // 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] | 2319 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2320 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2321 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2322 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2325 | // Returns whether the code generation of the instruction will require to have access |
| 2326 | // to the dex cache of the current method's declaring class via the current method. |
| 2327 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2328 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2329 | // Does this instruction have any use in an environment before |
| 2330 | // control flow hits 'other'? |
| 2331 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2332 | |
| 2333 | // Remove all references to environment uses of this instruction. |
| 2334 | // The caller must ensure that this is safe to do. |
| 2335 | void RemoveEnvironmentUsers(); |
| 2336 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2337 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2338 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2339 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2340 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2341 | // If set, the machine code for this instruction is assumed to be generated by |
| 2342 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2343 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2344 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2345 | static constexpr size_t kFieldInstructionKind = kFlagReferenceTypeIsExact + 1; |
| 2346 | static constexpr size_t kFieldInstructionKindSize = |
| 2347 | MinimumBitsToStore(static_cast<size_t>(InstructionKind::kLastInstructionKind - 1)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2348 | static constexpr size_t kFieldType = |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2349 | kFieldInstructionKind + kFieldInstructionKindSize; |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2350 | static constexpr size_t kFieldTypeSize = |
| 2351 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
| 2352 | static constexpr size_t kNumberOfGenericPackedBits = kFieldType + kFieldTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2353 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2354 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2355 | static_assert(kNumberOfGenericPackedBits <= kMaxNumberOfPackedBits, |
| 2356 | "Too many generic packed fields"); |
| 2357 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2358 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
| 2359 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2360 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2361 | return GetInputRecords()[i]; |
| 2362 | } |
| 2363 | |
| 2364 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2365 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2366 | input_records[index] = input; |
| 2367 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2368 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2369 | uint32_t GetPackedFields() const { |
| 2370 | return packed_fields_; |
| 2371 | } |
| 2372 | |
| 2373 | template <size_t flag> |
| 2374 | bool GetPackedFlag() const { |
| 2375 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2376 | } |
| 2377 | |
| 2378 | template <size_t flag> |
| 2379 | void SetPackedFlag(bool value = true) { |
| 2380 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2381 | } |
| 2382 | |
| 2383 | template <typename BitFieldType> |
| 2384 | typename BitFieldType::value_type GetPackedField() const { |
| 2385 | return BitFieldType::Decode(packed_fields_); |
| 2386 | } |
| 2387 | |
| 2388 | template <typename BitFieldType> |
| 2389 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2390 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2391 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2392 | } |
| 2393 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2394 | // Copy construction for the instruction (used for Clone function). |
| 2395 | // |
| 2396 | // Fields (e.g. lifetime, intervals and codegen info) associated with phases starting from |
| 2397 | // prepare_for_register_allocator are not copied (set to default values). |
| 2398 | // |
| 2399 | // Copy constructors must be provided for every HInstruction type; default copy constructor is |
| 2400 | // fine for most of them. However for some of the instructions a custom copy constructor must be |
| 2401 | // specified (when instruction has non-trivially copyable fields and must have a special behaviour |
| 2402 | // for copying them). |
| 2403 | explicit HInstruction(const HInstruction& other) |
| 2404 | : previous_(nullptr), |
| 2405 | next_(nullptr), |
| 2406 | block_(nullptr), |
| 2407 | dex_pc_(other.dex_pc_), |
| 2408 | id_(-1), |
| 2409 | ssa_index_(-1), |
| 2410 | packed_fields_(other.packed_fields_), |
| 2411 | environment_(nullptr), |
| 2412 | locations_(nullptr), |
| 2413 | live_interval_(nullptr), |
| 2414 | lifetime_position_(kNoLifetime), |
| 2415 | side_effects_(other.side_effects_), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2416 | reference_type_handle_(other.reference_type_handle_) { |
| 2417 | } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2418 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2419 | private: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2420 | using InstructionKindField = |
| 2421 | BitField<InstructionKind, kFieldInstructionKind, kFieldInstructionKindSize>; |
| 2422 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2423 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2424 | auto before_use_node = uses_.before_begin(); |
| 2425 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2426 | HInstruction* user = use_node->GetUser(); |
| 2427 | size_t input_index = use_node->GetIndex(); |
| 2428 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2429 | before_use_node = use_node; |
| 2430 | } |
| 2431 | } |
| 2432 | |
| 2433 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2434 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2435 | if (next != uses_.end()) { |
| 2436 | HInstruction* next_user = next->GetUser(); |
| 2437 | size_t next_index = next->GetIndex(); |
| 2438 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2439 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2444 | auto before_env_use_node = env_uses_.before_begin(); |
| 2445 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2446 | HEnvironment* user = env_use_node->GetUser(); |
| 2447 | size_t input_index = env_use_node->GetIndex(); |
| 2448 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2449 | before_env_use_node = env_use_node; |
| 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2454 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2455 | if (next != env_uses_.end()) { |
| 2456 | HEnvironment* next_user = next->GetUser(); |
| 2457 | size_t next_index = next->GetIndex(); |
| 2458 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2459 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2460 | } |
| 2461 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2462 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2463 | HInstruction* previous_; |
| 2464 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2465 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2466 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2467 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2468 | // An instruction gets an id when it is added to the graph. |
| 2469 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2470 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2471 | int id_; |
| 2472 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2473 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2474 | int ssa_index_; |
| 2475 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2476 | // Packed fields. |
| 2477 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2478 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2479 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2480 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2481 | |
| 2482 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2483 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2484 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2485 | // The environment associated with this instruction. Not null if the instruction |
| 2486 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2487 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2488 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2489 | // Set by the code generator. |
| 2490 | LocationSummary* locations_; |
| 2491 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2492 | // Set by the liveness analysis. |
| 2493 | LiveInterval* live_interval_; |
| 2494 | |
| 2495 | // Set by the liveness analysis, this is the position in a linear |
| 2496 | // order of blocks where this instruction's live interval start. |
| 2497 | size_t lifetime_position_; |
| 2498 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2499 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2500 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2501 | // The reference handle part of the reference type info. |
| 2502 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2503 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2504 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2505 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2506 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2507 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2508 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2509 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2510 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2511 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2512 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2513 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2514 | // Iterates over the instructions, while preserving the next instruction |
| 2515 | // in case the current instruction gets removed from the list by the user |
| 2516 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2517 | class HInstructionIterator : public ValueObject { |
| 2518 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2519 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2520 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2521 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2524 | bool Done() const { return instruction_ == nullptr; } |
| 2525 | HInstruction* Current() const { return instruction_; } |
| 2526 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2527 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2528 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | private: |
| 2532 | HInstruction* instruction_; |
| 2533 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2534 | |
| 2535 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2536 | }; |
| 2537 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2538 | // Iterates over the instructions without saving the next instruction, |
| 2539 | // therefore handling changes in the graph potentially made by the user |
| 2540 | // of this iterator. |
| 2541 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2542 | public: |
| 2543 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2544 | : instruction_(instructions.first_instruction_) { |
| 2545 | } |
| 2546 | |
| 2547 | bool Done() const { return instruction_ == nullptr; } |
| 2548 | HInstruction* Current() const { return instruction_; } |
| 2549 | void Advance() { |
| 2550 | instruction_ = instruction_->GetNext(); |
| 2551 | } |
| 2552 | |
| 2553 | private: |
| 2554 | HInstruction* instruction_; |
| 2555 | |
| 2556 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2557 | }; |
| 2558 | |
| 2559 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2560 | class HBackwardInstructionIterator : public ValueObject { |
| 2561 | public: |
| 2562 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2563 | : instruction_(instructions.last_instruction_) { |
| 2564 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2565 | } |
| 2566 | |
| 2567 | bool Done() const { return instruction_ == nullptr; } |
| 2568 | HInstruction* Current() const { return instruction_; } |
| 2569 | void Advance() { |
| 2570 | instruction_ = next_; |
| 2571 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2572 | } |
| 2573 | |
| 2574 | private: |
| 2575 | HInstruction* instruction_; |
| 2576 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2577 | |
| 2578 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2579 | }; |
| 2580 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2581 | class HVariableInputSizeInstruction : public HInstruction { |
| 2582 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2583 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2584 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 2585 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2586 | } |
| 2587 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2588 | void AddInput(HInstruction* input); |
| 2589 | void InsertInputAt(size_t index, HInstruction* input); |
| 2590 | void RemoveInputAt(size_t index); |
| 2591 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2592 | // Removes all the inputs. |
| 2593 | // Also removes this instructions from each input's use list |
| 2594 | // (for non-environment uses only). |
| 2595 | void RemoveAllInputs(); |
| 2596 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2597 | protected: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2598 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2599 | SideEffects side_effects, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2600 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2601 | ArenaAllocator* allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2602 | size_t number_of_inputs, |
| 2603 | ArenaAllocKind kind) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2604 | : HInstruction(inst_kind, side_effects, dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2605 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2606 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2607 | DataType::Type type, |
| 2608 | SideEffects side_effects, |
| 2609 | uint32_t dex_pc, |
| 2610 | ArenaAllocator* allocator, |
| 2611 | size_t number_of_inputs, |
| 2612 | ArenaAllocKind kind) |
| 2613 | : HInstruction(inst_kind, type, side_effects, dex_pc), |
| 2614 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2615 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2616 | DEFAULT_COPY_CONSTRUCTOR(VariableInputSizeInstruction); |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2617 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2618 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2619 | }; |
| 2620 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2621 | template<size_t N> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2622 | class HExpression : public HInstruction { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2623 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2624 | HExpression<N>(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2625 | : HInstruction(kind, side_effects, dex_pc), inputs_() {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2626 | HExpression<N>(InstructionKind kind, |
| 2627 | DataType::Type type, |
| 2628 | SideEffects side_effects, |
| 2629 | uint32_t dex_pc) |
| 2630 | : HInstruction(kind, type, side_effects, dex_pc), inputs_() {} |
| 2631 | virtual ~HExpression() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2632 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2633 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2634 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2635 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2636 | } |
| 2637 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2638 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2639 | DEFAULT_COPY_CONSTRUCTOR(Expression<N>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2640 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2641 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2642 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2643 | |
| 2644 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2645 | }; |
| 2646 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2647 | // HExpression specialization for N=0. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2648 | template<> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2649 | class HExpression<0> : public HInstruction { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2650 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2651 | using HInstruction::HInstruction; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2652 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2653 | virtual ~HExpression() {} |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2654 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2655 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2656 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2657 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2658 | } |
| 2659 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2660 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2661 | DEFAULT_COPY_CONSTRUCTOR(Expression<0>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2662 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2663 | private: |
| 2664 | friend class SsaBuilder; |
| 2665 | }; |
| 2666 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2667 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2668 | // instruction that branches to the exit block. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2669 | class HReturnVoid FINAL : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2670 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2671 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2672 | : HExpression(kReturnVoid, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2673 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2674 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2675 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2676 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2677 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2678 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2679 | protected: |
| 2680 | DEFAULT_COPY_CONSTRUCTOR(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2681 | }; |
| 2682 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2683 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2684 | // instruction that branches to the exit block. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2685 | class HReturn FINAL : public HExpression<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2686 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2687 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2688 | : HExpression(kReturn, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2689 | SetRawInputAt(0, value); |
| 2690 | } |
| 2691 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2692 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2693 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2694 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2695 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2696 | protected: |
| 2697 | DEFAULT_COPY_CONSTRUCTOR(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2698 | }; |
| 2699 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2700 | class HPhi FINAL : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2701 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2702 | HPhi(ArenaAllocator* allocator, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2703 | uint32_t reg_number, |
| 2704 | size_t number_of_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2705 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2706 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2707 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2708 | kPhi, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2709 | ToPhiType(type), |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2710 | SideEffects::None(), |
| 2711 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2712 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2713 | number_of_inputs, |
| 2714 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2715 | reg_number_(reg_number) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2716 | DCHECK_NE(GetType(), DataType::Type::kVoid); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2717 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2718 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2719 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2720 | SetPackedFlag<kFlagIsLive>(true); |
| 2721 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2722 | } |
| 2723 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2724 | bool IsClonable() const OVERRIDE { return true; } |
| 2725 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2726 | // 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] | 2727 | static DataType::Type ToPhiType(DataType::Type type) { |
| 2728 | return DataType::Kind(type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2732 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2733 | void SetType(DataType::Type new_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2734 | // Make sure that only valid type changes occur. The following are allowed: |
| 2735 | // (1) int -> float/ref (primitive type propagation), |
| 2736 | // (2) long -> double (primitive type propagation). |
| 2737 | DCHECK(GetType() == new_type || |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2738 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kFloat32) || |
| 2739 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kReference) || |
| 2740 | (GetType() == DataType::Type::kInt64 && new_type == DataType::Type::kFloat64)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2741 | SetPackedField<TypeField>(new_type); |
| 2742 | } |
| 2743 | |
| 2744 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2745 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2746 | |
| 2747 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2748 | |
| 2749 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2750 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2751 | bool IsDead() const { return !IsLive(); } |
| 2752 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2753 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2754 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2755 | return other != nullptr |
| 2756 | && other->IsPhi() |
| 2757 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2758 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2759 | } |
| 2760 | |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 2761 | bool HasEquivalentPhi() const { |
| 2762 | if (GetPrevious() != nullptr && GetPrevious()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2763 | return true; |
| 2764 | } |
| 2765 | if (GetNext() != nullptr && GetNext()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2766 | return true; |
| 2767 | } |
| 2768 | return false; |
| 2769 | } |
| 2770 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2771 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2772 | // An equivalent phi is a phi having the same dex register and type. |
| 2773 | // It assumes that phis with the same dex register are adjacent. |
| 2774 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2775 | HInstruction* next = GetNext(); |
| 2776 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2777 | if (next->GetType() == GetType()) { |
| 2778 | return next->AsPhi(); |
| 2779 | } |
| 2780 | next = next->GetNext(); |
| 2781 | } |
| 2782 | return nullptr; |
| 2783 | } |
| 2784 | |
| 2785 | DECLARE_INSTRUCTION(Phi); |
| 2786 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2787 | protected: |
| 2788 | DEFAULT_COPY_CONSTRUCTOR(Phi); |
| 2789 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2790 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2791 | static constexpr size_t kFlagIsLive = HInstruction::kNumberOfGenericPackedBits; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2792 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2793 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2794 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2795 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2796 | const uint32_t reg_number_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2797 | }; |
| 2798 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2799 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2800 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2801 | // exit block. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2802 | class HExit FINAL : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2803 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2804 | explicit HExit(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2805 | : HExpression(kExit, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2806 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2807 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2808 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2809 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2810 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2811 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2812 | protected: |
| 2813 | DEFAULT_COPY_CONSTRUCTOR(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2814 | }; |
| 2815 | |
| 2816 | // Jumps from one block to another. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2817 | class HGoto FINAL : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2818 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2819 | explicit HGoto(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2820 | : HExpression(kGoto, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2821 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2822 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2823 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2824 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2825 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2826 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2827 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2828 | } |
| 2829 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2830 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2831 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2832 | protected: |
| 2833 | DEFAULT_COPY_CONSTRUCTOR(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2834 | }; |
| 2835 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2836 | class HConstant : public HExpression<0> { |
| 2837 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2838 | explicit HConstant(InstructionKind kind, DataType::Type type, uint32_t dex_pc = kNoDexPc) |
| 2839 | : HExpression(kind, type, SideEffects::None(), dex_pc) { |
| 2840 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2841 | |
| 2842 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2843 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2844 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2845 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2846 | // Is this constant 0 in the arithmetic sense? |
| 2847 | virtual bool IsArithmeticZero() const { return false; } |
| 2848 | // Is this constant a 0-bit pattern? |
| 2849 | virtual bool IsZeroBitPattern() const { return false; } |
| 2850 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2851 | virtual bool IsOne() const { return false; } |
| 2852 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2853 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2854 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2855 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2856 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2857 | protected: |
| 2858 | DEFAULT_COPY_CONSTRUCTOR(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2859 | }; |
| 2860 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2861 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2862 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2863 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2864 | return true; |
| 2865 | } |
| 2866 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2867 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2868 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2869 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2870 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2871 | // The null constant representation is a 0-bit pattern. |
| 2872 | virtual bool IsZeroBitPattern() const { return true; } |
| 2873 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2874 | DECLARE_INSTRUCTION(NullConstant); |
| 2875 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2876 | protected: |
| 2877 | DEFAULT_COPY_CONSTRUCTOR(NullConstant); |
| 2878 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2879 | private: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2880 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2881 | : HConstant(kNullConstant, DataType::Type::kReference, dex_pc) { |
| 2882 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2883 | |
| 2884 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2885 | }; |
| 2886 | |
| 2887 | // Constants of the type int. Those can be from Dex instructions, or |
| 2888 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2889 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2890 | public: |
| 2891 | int32_t GetValue() const { return value_; } |
| 2892 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2893 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2894 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2895 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2896 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2897 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2898 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2899 | return other->AsIntConstant()->value_ == value_; |
| 2900 | } |
| 2901 | |
| 2902 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2903 | |
| 2904 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2905 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2906 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2907 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2908 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2909 | // Integer constants are used to encode Boolean values as well, |
| 2910 | // where 1 means true and 0 means false. |
| 2911 | bool IsTrue() const { return GetValue() == 1; } |
| 2912 | bool IsFalse() const { return GetValue() == 0; } |
| 2913 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2914 | DECLARE_INSTRUCTION(IntConstant); |
| 2915 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2916 | protected: |
| 2917 | DEFAULT_COPY_CONSTRUCTOR(IntConstant); |
| 2918 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2919 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2920 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2921 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), value_(value) { |
| 2922 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2923 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2924 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), |
| 2925 | value_(value ? 1 : 0) { |
| 2926 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2927 | |
| 2928 | const int32_t value_; |
| 2929 | |
| 2930 | friend class HGraph; |
| 2931 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2932 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2933 | }; |
| 2934 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2935 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2936 | public: |
| 2937 | int64_t GetValue() const { return value_; } |
| 2938 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2939 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2940 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2941 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2942 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2943 | return other->AsLongConstant()->value_ == value_; |
| 2944 | } |
| 2945 | |
| 2946 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2947 | |
| 2948 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2949 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2950 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2951 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2952 | |
| 2953 | DECLARE_INSTRUCTION(LongConstant); |
| 2954 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2955 | protected: |
| 2956 | DEFAULT_COPY_CONSTRUCTOR(LongConstant); |
| 2957 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2958 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2959 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2960 | : HConstant(kLongConstant, DataType::Type::kInt64, dex_pc), |
| 2961 | value_(value) { |
| 2962 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2963 | |
| 2964 | const int64_t value_; |
| 2965 | |
| 2966 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2967 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2968 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2969 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2970 | public: |
| 2971 | float GetValue() const { return value_; } |
| 2972 | |
| 2973 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2974 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2975 | } |
| 2976 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2977 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2978 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2979 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2980 | } |
| 2981 | |
| 2982 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2983 | |
| 2984 | bool IsMinusOne() const OVERRIDE { |
| 2985 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2986 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2987 | bool IsArithmeticZero() const OVERRIDE { |
| 2988 | return std::fpclassify(value_) == FP_ZERO; |
| 2989 | } |
| 2990 | bool IsArithmeticPositiveZero() const { |
| 2991 | return IsArithmeticZero() && !std::signbit(value_); |
| 2992 | } |
| 2993 | bool IsArithmeticNegativeZero() const { |
| 2994 | return IsArithmeticZero() && std::signbit(value_); |
| 2995 | } |
| 2996 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2997 | 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] | 2998 | } |
| 2999 | bool IsOne() const OVERRIDE { |
| 3000 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3001 | } |
| 3002 | bool IsNaN() const { |
| 3003 | return std::isnan(value_); |
| 3004 | } |
| 3005 | |
| 3006 | DECLARE_INSTRUCTION(FloatConstant); |
| 3007 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3008 | protected: |
| 3009 | DEFAULT_COPY_CONSTRUCTOR(FloatConstant); |
| 3010 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3011 | private: |
| 3012 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3013 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3014 | value_(value) { |
| 3015 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3016 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3017 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3018 | value_(bit_cast<float, int32_t>(value)) { |
| 3019 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3020 | |
| 3021 | const float value_; |
| 3022 | |
| 3023 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3024 | friend class SsaBuilder; |
| 3025 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3026 | }; |
| 3027 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3028 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3029 | public: |
| 3030 | double GetValue() const { return value_; } |
| 3031 | |
| 3032 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3033 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3034 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3035 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 3036 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3037 | } |
| 3038 | |
| 3039 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 3040 | |
| 3041 | bool IsMinusOne() const OVERRIDE { |
| 3042 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 3043 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3044 | bool IsArithmeticZero() const OVERRIDE { |
| 3045 | return std::fpclassify(value_) == FP_ZERO; |
| 3046 | } |
| 3047 | bool IsArithmeticPositiveZero() const { |
| 3048 | return IsArithmeticZero() && !std::signbit(value_); |
| 3049 | } |
| 3050 | bool IsArithmeticNegativeZero() const { |
| 3051 | return IsArithmeticZero() && std::signbit(value_); |
| 3052 | } |
| 3053 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3054 | 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] | 3055 | } |
| 3056 | bool IsOne() const OVERRIDE { |
| 3057 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3058 | } |
| 3059 | bool IsNaN() const { |
| 3060 | return std::isnan(value_); |
| 3061 | } |
| 3062 | |
| 3063 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3064 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3065 | protected: |
| 3066 | DEFAULT_COPY_CONSTRUCTOR(DoubleConstant); |
| 3067 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3068 | private: |
| 3069 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3070 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3071 | value_(value) { |
| 3072 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3073 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3074 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3075 | value_(bit_cast<double, int64_t>(value)) { |
| 3076 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3077 | |
| 3078 | const double value_; |
| 3079 | |
| 3080 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3081 | friend class SsaBuilder; |
| 3082 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3083 | }; |
| 3084 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3085 | // Conditional branch. A block ending with an HIf instruction must have |
| 3086 | // two successors. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3087 | class HIf FINAL : public HExpression<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3088 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3089 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3090 | : HExpression(kIf, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3091 | SetRawInputAt(0, input); |
| 3092 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3093 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3094 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3095 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3096 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3097 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3098 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3102 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3103 | } |
| 3104 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3105 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3106 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3107 | protected: |
| 3108 | DEFAULT_COPY_CONSTRUCTOR(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3109 | }; |
| 3110 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3111 | |
| 3112 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 3113 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 3114 | // non-exceptional control flow. |
| 3115 | // Normal-flow successor is stored at index zero, exception handlers under |
| 3116 | // higher indices in no particular order. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3117 | class HTryBoundary FINAL : public HExpression<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3118 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3119 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3120 | kEntry, |
| 3121 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3122 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3123 | }; |
| 3124 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3125 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3126 | : HExpression(kTryBoundary, SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3127 | SetPackedField<BoundaryKindField>(kind); |
| 3128 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3129 | |
| 3130 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3131 | |
| 3132 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3133 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3134 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 3135 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 3136 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 3137 | } |
| 3138 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3139 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 3140 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3141 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 3142 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 3143 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | // If not present already, adds `handler` to its block's list of exception |
| 3147 | // handlers. |
| 3148 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3149 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3150 | GetBlock()->AddSuccessor(handler); |
| 3151 | } |
| 3152 | } |
| 3153 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3154 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 3155 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3156 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3157 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 3158 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3159 | DECLARE_INSTRUCTION(TryBoundary); |
| 3160 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3161 | protected: |
| 3162 | DEFAULT_COPY_CONSTRUCTOR(TryBoundary); |
| 3163 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3164 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3165 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 3166 | static constexpr size_t kFieldBoundaryKindSize = |
| 3167 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 3168 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 3169 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 3170 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 3171 | "Too many packed fields."); |
| 3172 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3173 | }; |
| 3174 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3175 | // Deoptimize to interpreter, upon checking a condition. |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3176 | class HDeoptimize FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3177 | public: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3178 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 3179 | // across. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3180 | HDeoptimize(ArenaAllocator* allocator, |
| 3181 | HInstruction* cond, |
| 3182 | DeoptimizationKind kind, |
| 3183 | uint32_t dex_pc) |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3184 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3185 | kDeoptimize, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3186 | SideEffects::All(), |
| 3187 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3188 | allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3189 | /* number_of_inputs */ 1, |
| 3190 | kArenaAllocMisc) { |
| 3191 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 3192 | SetPackedField<DeoptimizeKindField>(kind); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3193 | SetRawInputAt(0, cond); |
| 3194 | } |
| 3195 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3196 | bool IsClonable() const OVERRIDE { return true; } |
| 3197 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3198 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3199 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3200 | // instead of `guard`. |
| 3201 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3202 | // at the point of the `HDeoptimize`. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3203 | HDeoptimize(ArenaAllocator* allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3204 | HInstruction* cond, |
| 3205 | HInstruction* guard, |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3206 | DeoptimizationKind kind, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3207 | uint32_t dex_pc) |
| 3208 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3209 | kDeoptimize, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3210 | guard->GetType(), |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3211 | SideEffects::CanTriggerGC(), |
| 3212 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3213 | allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3214 | /* number_of_inputs */ 2, |
| 3215 | kArenaAllocMisc) { |
| 3216 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3217 | SetPackedField<DeoptimizeKindField>(kind); |
| 3218 | SetRawInputAt(0, cond); |
| 3219 | SetRawInputAt(1, guard); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3220 | } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3221 | |
| 3222 | bool CanBeMoved() const OVERRIDE { return GetPackedFlag<kFieldCanBeMoved>(); } |
| 3223 | |
| 3224 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 3225 | return (other->CanBeMoved() == CanBeMoved()) && (other->AsDeoptimize()->GetKind() == GetKind()); |
| 3226 | } |
| 3227 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3228 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3229 | |
Aart Bik | 75ff2c9 | 2018-04-21 01:28:11 +0000 | [diff] [blame] | 3230 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3231 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3232 | DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3233 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3234 | bool GuardsAnInput() const { |
| 3235 | return InputCount() == 2; |
| 3236 | } |
| 3237 | |
| 3238 | HInstruction* GuardedInput() const { |
| 3239 | DCHECK(GuardsAnInput()); |
| 3240 | return InputAt(1); |
| 3241 | } |
| 3242 | |
| 3243 | void RemoveGuard() { |
| 3244 | RemoveInputAt(1); |
| 3245 | } |
| 3246 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3247 | DECLARE_INSTRUCTION(Deoptimize); |
| 3248 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3249 | protected: |
| 3250 | DEFAULT_COPY_CONSTRUCTOR(Deoptimize); |
| 3251 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3252 | private: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3253 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3254 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3255 | static constexpr size_t kFieldDeoptimizeKindSize = |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3256 | MinimumBitsToStore(static_cast<size_t>(DeoptimizationKind::kLast)); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3257 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3258 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3259 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3260 | "Too many packed fields."); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3261 | using DeoptimizeKindField = |
| 3262 | BitField<DeoptimizationKind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3263 | }; |
| 3264 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3265 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3266 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3267 | // if it's true, starts to do deoptimization. |
| 3268 | // It has a 4-byte slot on stack. |
| 3269 | // TODO: allocate a register for this flag. |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3270 | class HShouldDeoptimizeFlag FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3271 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3272 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3273 | // with regard to other passes. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3274 | HShouldDeoptimizeFlag(ArenaAllocator* allocator, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3275 | : HVariableInputSizeInstruction(kShouldDeoptimizeFlag, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3276 | DataType::Type::kInt32, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3277 | SideEffects::None(), |
| 3278 | dex_pc, |
| 3279 | allocator, |
| 3280 | 0, |
| 3281 | kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3284 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3285 | // further guard elimination/motion since a guard might have been used for justification |
| 3286 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3287 | // to avoid other optimizations trying to move it. |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3288 | bool CanBeMoved() const OVERRIDE { return false; } |
| 3289 | |
| 3290 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3291 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3292 | protected: |
| 3293 | DEFAULT_COPY_CONSTRUCTOR(ShouldDeoptimizeFlag); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3294 | }; |
| 3295 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3296 | // Represents the ArtMethod that was passed as a first argument to |
| 3297 | // the method. It is used by instructions that depend on it, like |
| 3298 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3299 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3300 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3301 | explicit HCurrentMethod(DataType::Type type, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3302 | : HExpression(kCurrentMethod, type, SideEffects::None(), dex_pc) { |
| 3303 | } |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3304 | |
| 3305 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3306 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3307 | protected: |
| 3308 | DEFAULT_COPY_CONSTRUCTOR(CurrentMethod); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3309 | }; |
| 3310 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3311 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3312 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3313 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3314 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3315 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3316 | kVTable, |
| 3317 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3318 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3319 | }; |
| 3320 | HClassTableGet(HInstruction* cls, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3321 | DataType::Type type, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3322 | TableKind kind, |
| 3323 | size_t index, |
| 3324 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3325 | : HExpression(kClassTableGet, type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3326 | index_(index) { |
| 3327 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3328 | SetRawInputAt(0, cls); |
| 3329 | } |
| 3330 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3331 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3332 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3333 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3334 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3335 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3336 | } |
| 3337 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3338 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3339 | size_t GetIndex() const { return index_; } |
| 3340 | |
| 3341 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3342 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3343 | protected: |
| 3344 | DEFAULT_COPY_CONSTRUCTOR(ClassTableGet); |
| 3345 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3346 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3347 | static constexpr size_t kFieldTableKind = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3348 | static constexpr size_t kFieldTableKindSize = |
| 3349 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3350 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3351 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3352 | "Too many packed fields."); |
| 3353 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3354 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3355 | // The index of the ArtMethod in the table. |
| 3356 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3357 | }; |
| 3358 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3359 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3360 | // have one successor for each entry in the switch table, and the final successor |
| 3361 | // will be the block containing the next Dex opcode. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3362 | class HPackedSwitch FINAL : public HExpression<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3363 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3364 | HPackedSwitch(int32_t start_value, |
| 3365 | uint32_t num_entries, |
| 3366 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3367 | uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3368 | : HExpression(kPackedSwitch, SideEffects::None(), dex_pc), |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3369 | start_value_(start_value), |
| 3370 | num_entries_(num_entries) { |
| 3371 | SetRawInputAt(0, input); |
| 3372 | } |
| 3373 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3374 | bool IsClonable() const OVERRIDE { return true; } |
| 3375 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3376 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3377 | |
| 3378 | int32_t GetStartValue() const { return start_value_; } |
| 3379 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3380 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3381 | |
| 3382 | HBasicBlock* GetDefaultBlock() const { |
| 3383 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3384 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3385 | } |
| 3386 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3387 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3388 | protected: |
| 3389 | DEFAULT_COPY_CONSTRUCTOR(PackedSwitch); |
| 3390 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3391 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3392 | const int32_t start_value_; |
| 3393 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3394 | }; |
| 3395 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3396 | class HUnaryOperation : public HExpression<1> { |
| 3397 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3398 | HUnaryOperation(InstructionKind kind, |
| 3399 | DataType::Type result_type, |
| 3400 | HInstruction* input, |
| 3401 | uint32_t dex_pc = kNoDexPc) |
| 3402 | : HExpression(kind, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3403 | SetRawInputAt(0, input); |
| 3404 | } |
| 3405 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3406 | // All of the UnaryOperation instructions are clonable. |
| 3407 | bool IsClonable() const OVERRIDE { return true; } |
| 3408 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3409 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3410 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3411 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3412 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3413 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3414 | return true; |
| 3415 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3416 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3417 | // Try to statically evaluate `this` and return a HConstant |
| 3418 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3419 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3420 | HConstant* TryStaticEvaluation() const; |
| 3421 | |
| 3422 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3423 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3424 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3425 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3426 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3427 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3428 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3429 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3430 | protected: |
| 3431 | DEFAULT_COPY_CONSTRUCTOR(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3432 | }; |
| 3433 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3434 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3435 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3436 | HBinaryOperation(InstructionKind kind, |
| 3437 | DataType::Type result_type, |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3438 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3439 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3440 | SideEffects side_effects = SideEffects::None(), |
| 3441 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3442 | : HExpression(kind, result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3443 | SetRawInputAt(0, left); |
| 3444 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3445 | } |
| 3446 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3447 | // All of the BinaryOperation instructions are clonable. |
| 3448 | bool IsClonable() const OVERRIDE { return true; } |
| 3449 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3450 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3451 | HInstruction* GetRight() const { return InputAt(1); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3452 | DataType::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3453 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3454 | virtual bool IsCommutative() const { return false; } |
| 3455 | |
| 3456 | // Put constant on the right. |
| 3457 | // Returns whether order is changed. |
| 3458 | bool OrderInputsWithConstantOnTheRight() { |
| 3459 | HInstruction* left = InputAt(0); |
| 3460 | HInstruction* right = InputAt(1); |
| 3461 | if (left->IsConstant() && !right->IsConstant()) { |
| 3462 | ReplaceInput(right, 0); |
| 3463 | ReplaceInput(left, 1); |
| 3464 | return true; |
| 3465 | } |
| 3466 | return false; |
| 3467 | } |
| 3468 | |
| 3469 | // Order inputs by instruction id, but favor constant on the right side. |
| 3470 | // This helps GVN for commutative ops. |
| 3471 | void OrderInputs() { |
| 3472 | DCHECK(IsCommutative()); |
| 3473 | HInstruction* left = InputAt(0); |
| 3474 | HInstruction* right = InputAt(1); |
| 3475 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3476 | return; |
| 3477 | } |
| 3478 | if (OrderInputsWithConstantOnTheRight()) { |
| 3479 | return; |
| 3480 | } |
| 3481 | // Order according to instruction id. |
| 3482 | if (left->GetId() > right->GetId()) { |
| 3483 | ReplaceInput(right, 0); |
| 3484 | ReplaceInput(left, 1); |
| 3485 | } |
| 3486 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3487 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3488 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3489 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3490 | return true; |
| 3491 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3492 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3493 | // Try to statically evaluate `this` and return a HConstant |
| 3494 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3495 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3496 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3497 | |
| 3498 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3499 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3500 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3501 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3502 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3503 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3504 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3505 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3506 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3507 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3508 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3509 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3510 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3511 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3512 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3513 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3514 | // 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] | 3515 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3516 | HConstant* GetConstantRight() const; |
| 3517 | |
| 3518 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3519 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3520 | HInstruction* GetLeastConstantLeft() const; |
| 3521 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3522 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3523 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3524 | protected: |
| 3525 | DEFAULT_COPY_CONSTRUCTOR(BinaryOperation); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3526 | }; |
| 3527 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3528 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3529 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3530 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3531 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3532 | kGtBias, // return 1 for NaN comparisons |
| 3533 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3534 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3535 | }; |
| 3536 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3537 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3538 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3539 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3540 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3541 | HCondition(InstructionKind kind, |
| 3542 | HInstruction* first, |
| 3543 | HInstruction* second, |
| 3544 | uint32_t dex_pc = kNoDexPc) |
| 3545 | : HBinaryOperation(kind, |
| 3546 | DataType::Type::kBool, |
| 3547 | first, |
| 3548 | second, |
| 3549 | SideEffects::None(), |
| 3550 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3551 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3552 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3553 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3554 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3555 | // `instruction`, and disregard moves in between. |
| 3556 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3557 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3558 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3559 | |
| 3560 | virtual IfCondition GetCondition() const = 0; |
| 3561 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3562 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3563 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3564 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3565 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3566 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3567 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3568 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3569 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3570 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3571 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3572 | } |
| 3573 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3574 | bool IsFPConditionTrueIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3575 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3576 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3577 | if (if_cond == kCondNE) { |
| 3578 | return true; |
| 3579 | } else if (if_cond == kCondEQ) { |
| 3580 | return false; |
| 3581 | } |
| 3582 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | bool IsFPConditionFalseIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3586 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3587 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3588 | if (if_cond == kCondEQ) { |
| 3589 | return true; |
| 3590 | } else if (if_cond == kCondNE) { |
| 3591 | return false; |
| 3592 | } |
| 3593 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3594 | } |
| 3595 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3596 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3597 | // Needed if we merge a HCompare into a HCondition. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3598 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3599 | static constexpr size_t kFieldComparisonBiasSize = |
| 3600 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3601 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3602 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3603 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3604 | using ComparisonBiasField = |
| 3605 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3606 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3607 | template <typename T> |
| 3608 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3609 | |
| 3610 | template <typename T> |
| 3611 | int32_t CompareFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3612 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3613 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3614 | // Handle the bias. |
| 3615 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3616 | } |
| 3617 | |
| 3618 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3619 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3620 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3621 | } |
| 3622 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3623 | DEFAULT_COPY_CONSTRUCTOR(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3624 | }; |
| 3625 | |
| 3626 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3627 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3628 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3629 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3630 | : HCondition(kEqual, first, second, dex_pc) { |
| 3631 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3632 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3633 | bool IsCommutative() const OVERRIDE { return true; } |
| 3634 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3635 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3636 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3637 | return MakeConstantCondition(true, GetDexPc()); |
| 3638 | } |
| 3639 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3640 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3641 | } |
| 3642 | // In the following Evaluate methods, a HCompare instruction has |
| 3643 | // been merged into this HEqual instruction; evaluate it as |
| 3644 | // `Compare(x, y) == 0`. |
| 3645 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3646 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3647 | GetDexPc()); |
| 3648 | } |
| 3649 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3650 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3651 | } |
| 3652 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3653 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3654 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3655 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3656 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3657 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3658 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3659 | return kCondEQ; |
| 3660 | } |
| 3661 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3662 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3663 | return kCondNE; |
| 3664 | } |
| 3665 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3666 | protected: |
| 3667 | DEFAULT_COPY_CONSTRUCTOR(Equal); |
| 3668 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3669 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3670 | 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] | 3671 | }; |
| 3672 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3673 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3674 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3675 | HNotEqual(HInstruction* first, HInstruction* second, |
| 3676 | uint32_t dex_pc = kNoDexPc) |
| 3677 | : HCondition(kNotEqual, first, second, dex_pc) { |
| 3678 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3679 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3680 | bool IsCommutative() const OVERRIDE { return true; } |
| 3681 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3682 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3683 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3684 | return MakeConstantCondition(false, GetDexPc()); |
| 3685 | } |
| 3686 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3687 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3688 | } |
| 3689 | // In the following Evaluate methods, a HCompare instruction has |
| 3690 | // been merged into this HNotEqual instruction; evaluate it as |
| 3691 | // `Compare(x, y) != 0`. |
| 3692 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3693 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3694 | } |
| 3695 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3696 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3697 | } |
| 3698 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3699 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3700 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3701 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3702 | DECLARE_INSTRUCTION(NotEqual); |
| 3703 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3704 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3705 | return kCondNE; |
| 3706 | } |
| 3707 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3708 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3709 | return kCondEQ; |
| 3710 | } |
| 3711 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3712 | protected: |
| 3713 | DEFAULT_COPY_CONSTRUCTOR(NotEqual); |
| 3714 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3715 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3716 | 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] | 3717 | }; |
| 3718 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3719 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3720 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3721 | HLessThan(HInstruction* first, HInstruction* second, |
| 3722 | uint32_t dex_pc = kNoDexPc) |
| 3723 | : HCondition(kLessThan, first, second, dex_pc) { |
| 3724 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3725 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3726 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3727 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3728 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3729 | // In the following Evaluate methods, a HCompare instruction has |
| 3730 | // been merged into this HLessThan instruction; evaluate it as |
| 3731 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3732 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3733 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3734 | } |
| 3735 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3736 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3737 | } |
| 3738 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3739 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3740 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3741 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3742 | DECLARE_INSTRUCTION(LessThan); |
| 3743 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3744 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3745 | return kCondLT; |
| 3746 | } |
| 3747 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3748 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3749 | return kCondGE; |
| 3750 | } |
| 3751 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3752 | protected: |
| 3753 | DEFAULT_COPY_CONSTRUCTOR(LessThan); |
| 3754 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3755 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3756 | 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] | 3757 | }; |
| 3758 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3759 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3760 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3761 | HLessThanOrEqual(HInstruction* first, HInstruction* second, |
| 3762 | uint32_t dex_pc = kNoDexPc) |
| 3763 | : HCondition(kLessThanOrEqual, first, second, dex_pc) { |
| 3764 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3765 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3766 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3767 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3768 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3769 | // In the following Evaluate methods, a HCompare instruction has |
| 3770 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3771 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3772 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3773 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3774 | } |
| 3775 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3776 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3777 | } |
| 3778 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3779 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3780 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3781 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3782 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3783 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3784 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3785 | return kCondLE; |
| 3786 | } |
| 3787 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3788 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3789 | return kCondGT; |
| 3790 | } |
| 3791 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3792 | protected: |
| 3793 | DEFAULT_COPY_CONSTRUCTOR(LessThanOrEqual); |
| 3794 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3795 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3796 | 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] | 3797 | }; |
| 3798 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3799 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3800 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3801 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3802 | : HCondition(kGreaterThan, first, second, dex_pc) { |
| 3803 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3804 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3805 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3806 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3807 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3808 | // In the following Evaluate methods, a HCompare instruction has |
| 3809 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3810 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3811 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3812 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3813 | } |
| 3814 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3815 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3816 | } |
| 3817 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3818 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3819 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3820 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3821 | DECLARE_INSTRUCTION(GreaterThan); |
| 3822 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3823 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3824 | return kCondGT; |
| 3825 | } |
| 3826 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3827 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3828 | return kCondLE; |
| 3829 | } |
| 3830 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3831 | protected: |
| 3832 | DEFAULT_COPY_CONSTRUCTOR(GreaterThan); |
| 3833 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3834 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3835 | 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] | 3836 | }; |
| 3837 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3838 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3839 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3840 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3841 | : HCondition(kGreaterThanOrEqual, first, second, dex_pc) { |
| 3842 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3843 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3844 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3845 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3846 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3847 | // In the following Evaluate methods, a HCompare instruction has |
| 3848 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3849 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3850 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3851 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3852 | } |
| 3853 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3854 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3855 | } |
| 3856 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3857 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3858 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3859 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3860 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3861 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3862 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3863 | return kCondGE; |
| 3864 | } |
| 3865 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3866 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3867 | return kCondLT; |
| 3868 | } |
| 3869 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3870 | protected: |
| 3871 | DEFAULT_COPY_CONSTRUCTOR(GreaterThanOrEqual); |
| 3872 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3873 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3874 | 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] | 3875 | }; |
| 3876 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3877 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3878 | public: |
| 3879 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3880 | : HCondition(kBelow, first, second, dex_pc) { |
| 3881 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3882 | |
| 3883 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3884 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3885 | } |
| 3886 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3887 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3888 | } |
| 3889 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3890 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3891 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3892 | UNREACHABLE(); |
| 3893 | } |
| 3894 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3895 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3896 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3897 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3898 | } |
| 3899 | |
| 3900 | DECLARE_INSTRUCTION(Below); |
| 3901 | |
| 3902 | IfCondition GetCondition() const OVERRIDE { |
| 3903 | return kCondB; |
| 3904 | } |
| 3905 | |
| 3906 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3907 | return kCondAE; |
| 3908 | } |
| 3909 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3910 | protected: |
| 3911 | DEFAULT_COPY_CONSTRUCTOR(Below); |
| 3912 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3913 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3914 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3915 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3916 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3917 | }; |
| 3918 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3919 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3920 | public: |
| 3921 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3922 | : HCondition(kBelowOrEqual, first, second, dex_pc) { |
| 3923 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3924 | |
| 3925 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3926 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3927 | } |
| 3928 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3929 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3930 | } |
| 3931 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3932 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3933 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3934 | UNREACHABLE(); |
| 3935 | } |
| 3936 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3937 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3938 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3939 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3943 | |
| 3944 | IfCondition GetCondition() const OVERRIDE { |
| 3945 | return kCondBE; |
| 3946 | } |
| 3947 | |
| 3948 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3949 | return kCondA; |
| 3950 | } |
| 3951 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3952 | protected: |
| 3953 | DEFAULT_COPY_CONSTRUCTOR(BelowOrEqual); |
| 3954 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3955 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3956 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3957 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3958 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3959 | }; |
| 3960 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3961 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3962 | public: |
| 3963 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3964 | : HCondition(kAbove, first, second, dex_pc) { |
| 3965 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3966 | |
| 3967 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3968 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3969 | } |
| 3970 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3971 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3972 | } |
| 3973 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3974 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3975 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3976 | UNREACHABLE(); |
| 3977 | } |
| 3978 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3979 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3980 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3981 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | DECLARE_INSTRUCTION(Above); |
| 3985 | |
| 3986 | IfCondition GetCondition() const OVERRIDE { |
| 3987 | return kCondA; |
| 3988 | } |
| 3989 | |
| 3990 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3991 | return kCondBE; |
| 3992 | } |
| 3993 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3994 | protected: |
| 3995 | DEFAULT_COPY_CONSTRUCTOR(Above); |
| 3996 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3997 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3998 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3999 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 4000 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4001 | }; |
| 4002 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4003 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4004 | public: |
| 4005 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4006 | : HCondition(kAboveOrEqual, first, second, dex_pc) { |
| 4007 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4008 | |
| 4009 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4010 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4011 | } |
| 4012 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4013 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4014 | } |
| 4015 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4016 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4017 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4018 | UNREACHABLE(); |
| 4019 | } |
| 4020 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4021 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4022 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4023 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4024 | } |
| 4025 | |
| 4026 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 4027 | |
| 4028 | IfCondition GetCondition() const OVERRIDE { |
| 4029 | return kCondAE; |
| 4030 | } |
| 4031 | |
| 4032 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 4033 | return kCondB; |
| 4034 | } |
| 4035 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4036 | protected: |
| 4037 | DEFAULT_COPY_CONSTRUCTOR(AboveOrEqual); |
| 4038 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4039 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4040 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4041 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 4042 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4043 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4044 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4045 | // Instruction to check how two inputs compare to each other. |
| 4046 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4047 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4048 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4049 | // Note that `comparison_type` is the type of comparison performed |
| 4050 | // between the comparison's inputs, not the type of the instantiated |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4051 | // HCompare instruction (which is always DataType::Type::kInt). |
| 4052 | HCompare(DataType::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4053 | HInstruction* first, |
| 4054 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4055 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4056 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4057 | : HBinaryOperation(kCompare, |
| 4058 | DataType::Type::kInt32, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4059 | first, |
| 4060 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4061 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4062 | dex_pc) { |
| 4063 | SetPackedField<ComparisonBiasField>(bias); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4064 | DCHECK_EQ(comparison_type, DataType::Kind(first->GetType())); |
| 4065 | DCHECK_EQ(comparison_type, DataType::Kind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4066 | } |
| 4067 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4068 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4069 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 4070 | |
| 4071 | template <typename T> |
| 4072 | int32_t ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4073 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4074 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 4075 | // Handle the bias. |
| 4076 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 4077 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4078 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4079 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4080 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 4081 | // reach this code path when processing a freshly built HIR |
| 4082 | // graph. However HCompare integer instructions can be synthesized |
| 4083 | // by the instruction simplifier to implement IntegerCompare and |
| 4084 | // IntegerSignum intrinsics, so we have to handle this case. |
| 4085 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4086 | } |
| 4087 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4088 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4089 | } |
| 4090 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4091 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4092 | } |
| 4093 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4094 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4095 | } |
| 4096 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4097 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4098 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4099 | } |
| 4100 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4101 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4102 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4103 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4104 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4105 | bool IsGtBias() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4106 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4107 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4108 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4109 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4110 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type type ATTRIBUTE_UNUSED) { |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 4111 | // Comparisons do not require a runtime call in any back end. |
| 4112 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4113 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4114 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4115 | DECLARE_INSTRUCTION(Compare); |
| 4116 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4117 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4118 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4119 | static constexpr size_t kFieldComparisonBiasSize = |
| 4120 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 4121 | static constexpr size_t kNumberOfComparePackedBits = |
| 4122 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 4123 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4124 | using ComparisonBiasField = |
| 4125 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 4126 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4127 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 4128 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 4129 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 4130 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 4131 | } |
| 4132 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4133 | DEFAULT_COPY_CONSTRUCTOR(Compare); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4134 | }; |
| 4135 | |
Nicolas Geoffray | 2b615ba | 2017-01-06 14:40:07 +0000 | [diff] [blame] | 4136 | class HNewInstance FINAL : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4137 | public: |
| 4138 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4139 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4140 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4141 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4142 | bool finalizable, |
| 4143 | QuickEntrypointEnum entrypoint) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4144 | : HExpression(kNewInstance, |
| 4145 | DataType::Type::kReference, |
| 4146 | SideEffects::CanTriggerGC(), |
| 4147 | dex_pc), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4148 | type_index_(type_index), |
| 4149 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4150 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4151 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4152 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4153 | } |
| 4154 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4155 | bool IsClonable() const OVERRIDE { return true; } |
| 4156 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4157 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4158 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4159 | |
| 4160 | // Calls runtime so needs an environment. |
| 4161 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4162 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4163 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 4164 | bool CanThrow() const OVERRIDE { return true; } |
| 4165 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4166 | bool NeedsChecks() const { |
| 4167 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 4168 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4169 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4170 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4171 | |
| 4172 | bool CanBeNull() const OVERRIDE { return false; } |
| 4173 | |
| 4174 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4175 | |
| 4176 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 4177 | entrypoint_ = entrypoint; |
| 4178 | } |
| 4179 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4180 | HLoadClass* GetLoadClass() const { |
| 4181 | HInstruction* input = InputAt(0); |
| 4182 | if (input->IsClinitCheck()) { |
| 4183 | input = input->InputAt(0); |
| 4184 | } |
| 4185 | DCHECK(input->IsLoadClass()); |
| 4186 | return input->AsLoadClass(); |
| 4187 | } |
| 4188 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4189 | bool IsStringAlloc() const; |
| 4190 | |
| 4191 | DECLARE_INSTRUCTION(NewInstance); |
| 4192 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4193 | protected: |
| 4194 | DEFAULT_COPY_CONSTRUCTOR(NewInstance); |
| 4195 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4196 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4197 | static constexpr size_t kFlagFinalizable = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4198 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 4199 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 4200 | "Too many packed fields."); |
| 4201 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4202 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4203 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4204 | QuickEntrypointEnum entrypoint_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4205 | }; |
| 4206 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 4207 | enum IntrinsicNeedsEnvironmentOrCache { |
| 4208 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 4209 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4210 | }; |
| 4211 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4212 | enum IntrinsicSideEffects { |
| 4213 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 4214 | kReadSideEffects, // Intrinsic may read heap memory. |
| 4215 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 4216 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 4217 | }; |
| 4218 | |
| 4219 | enum IntrinsicExceptions { |
| 4220 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 4221 | kCanThrow // Intrinsic may throw exceptions. |
| 4222 | }; |
| 4223 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4224 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4225 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4226 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4227 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 4228 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4229 | SetRawInputAt(index, argument); |
| 4230 | } |
| 4231 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4232 | // Return the number of arguments. This number can be lower than |
| 4233 | // the number of inputs returned by InputCount(), as some invoke |
| 4234 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 4235 | // inputs at the end of their list of inputs. |
| 4236 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 4237 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4238 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4239 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4240 | InvokeType GetInvokeType() const { |
| 4241 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4242 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4243 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 4244 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4245 | return intrinsic_; |
| 4246 | } |
| 4247 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4248 | void SetIntrinsic(Intrinsics intrinsic, |
| 4249 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 4250 | IntrinsicSideEffects side_effects, |
| 4251 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4252 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4253 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4254 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4255 | } |
| 4256 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4257 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4258 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4259 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4260 | |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4261 | void SetAlwaysThrows(bool always_throws) { SetPackedFlag<kFlagAlwaysThrows>(always_throws); } |
| 4262 | |
| 4263 | bool AlwaysThrows() const OVERRIDE { return GetPackedFlag<kFlagAlwaysThrows>(); } |
| 4264 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4265 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4266 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4267 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4268 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 4269 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4270 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4271 | uint32_t* GetIntrinsicOptimizations() { |
| 4272 | return &intrinsic_optimizations_; |
| 4273 | } |
| 4274 | |
| 4275 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4276 | return &intrinsic_optimizations_; |
| 4277 | } |
| 4278 | |
| 4279 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4280 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4281 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4282 | void SetResolvedMethod(ArtMethod* method) { resolved_method_ = method; } |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4283 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4284 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4285 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4286 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4287 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4288 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4289 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4290 | static constexpr size_t kFlagCanThrow = kFieldInvokeType + kFieldInvokeTypeSize; |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4291 | static constexpr size_t kFlagAlwaysThrows = kFlagCanThrow + 1; |
| 4292 | static constexpr size_t kNumberOfInvokePackedBits = kFlagAlwaysThrows + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4293 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4294 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4295 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4296 | HInvoke(InstructionKind kind, |
| 4297 | ArenaAllocator* allocator, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4298 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4299 | uint32_t number_of_other_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4300 | DataType::Type return_type, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4301 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4302 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4303 | ArtMethod* resolved_method, |
| 4304 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4305 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4306 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4307 | return_type, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4308 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4309 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4310 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4311 | number_of_arguments + number_of_other_inputs, |
| 4312 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4313 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4314 | resolved_method_(resolved_method), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4315 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4316 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4317 | intrinsic_optimizations_(0) { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4318 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4319 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4320 | } |
| 4321 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4322 | DEFAULT_COPY_CONSTRUCTOR(Invoke); |
| 4323 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4324 | uint32_t number_of_arguments_; |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4325 | ArtMethod* resolved_method_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4326 | const uint32_t dex_method_index_; |
| 4327 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4328 | |
| 4329 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4330 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4331 | }; |
| 4332 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4333 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4334 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4335 | HInvokeUnresolved(ArenaAllocator* allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4336 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4337 | DataType::Type return_type, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4338 | uint32_t dex_pc, |
| 4339 | uint32_t dex_method_index, |
| 4340 | InvokeType invoke_type) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4341 | : HInvoke(kInvokeUnresolved, |
| 4342 | allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4343 | number_of_arguments, |
| 4344 | 0u /* number_of_other_inputs */, |
| 4345 | return_type, |
| 4346 | dex_pc, |
| 4347 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4348 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4349 | invoke_type) { |
| 4350 | } |
| 4351 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4352 | bool IsClonable() const OVERRIDE { return true; } |
| 4353 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4354 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4355 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4356 | protected: |
| 4357 | DEFAULT_COPY_CONSTRUCTOR(InvokeUnresolved); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4358 | }; |
| 4359 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4360 | class HInvokePolymorphic FINAL : public HInvoke { |
| 4361 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4362 | HInvokePolymorphic(ArenaAllocator* allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4363 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4364 | DataType::Type return_type, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4365 | uint32_t dex_pc, |
| 4366 | uint32_t dex_method_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4367 | : HInvoke(kInvokePolymorphic, |
| 4368 | allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4369 | number_of_arguments, |
| 4370 | 0u /* number_of_other_inputs */, |
| 4371 | return_type, |
| 4372 | dex_pc, |
| 4373 | dex_method_index, |
| 4374 | nullptr, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4375 | kVirtual) { |
| 4376 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4377 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4378 | bool IsClonable() const OVERRIDE { return true; } |
| 4379 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4380 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4381 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4382 | protected: |
| 4383 | DEFAULT_COPY_CONSTRUCTOR(InvokePolymorphic); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4384 | }; |
| 4385 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame^] | 4386 | class HInvokeCustom FINAL : public HInvoke { |
| 4387 | public: |
| 4388 | HInvokeCustom(ArenaAllocator* allocator, |
| 4389 | uint32_t number_of_arguments, |
| 4390 | uint32_t call_site_index, |
| 4391 | DataType::Type return_type, |
| 4392 | uint32_t dex_pc) |
| 4393 | : HInvoke(kInvokeCustom, |
| 4394 | allocator, |
| 4395 | number_of_arguments, |
| 4396 | /* number_of_other_inputs */ 0u, |
| 4397 | return_type, |
| 4398 | dex_pc, |
| 4399 | /* dex_method_index */ dex::kDexNoIndex, |
| 4400 | /* resolved_method */ nullptr, |
| 4401 | kStatic), |
| 4402 | call_site_index_(call_site_index) { |
| 4403 | } |
| 4404 | |
| 4405 | uint32_t GetCallSiteIndex() const { return call_site_index_; } |
| 4406 | |
| 4407 | bool IsClonable() const OVERRIDE { return true; } |
| 4408 | |
| 4409 | DECLARE_INSTRUCTION(InvokeCustom); |
| 4410 | |
| 4411 | protected: |
| 4412 | DEFAULT_COPY_CONSTRUCTOR(InvokeCustom); |
| 4413 | |
| 4414 | private: |
| 4415 | uint32_t call_site_index_; |
| 4416 | }; |
| 4417 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4418 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4419 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4420 | // Requirements of this method call regarding the class |
| 4421 | // initialization (clinit) check of its declaring class. |
| 4422 | enum class ClinitCheckRequirement { |
| 4423 | kNone, // Class already initialized. |
| 4424 | kExplicit, // Static call having explicit clinit check as last input. |
| 4425 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4426 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4427 | }; |
| 4428 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4429 | // Determines how to load the target ArtMethod*. |
| 4430 | enum class MethodLoadKind { |
| 4431 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4432 | kStringInit, |
| 4433 | |
| 4434 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4435 | kRecursive, |
| 4436 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4437 | // Use PC-relative boot image ArtMethod* address that will be known at link time. |
| 4438 | // Used for boot image methods referenced by boot image code. |
| 4439 | kBootImageLinkTimePcRelative, |
| 4440 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4441 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4442 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 4443 | kDirectAddress, |
| 4444 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4445 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| 4446 | // Used for app->boot calls with relocatable image. |
| 4447 | kBootImageRelRo, |
| 4448 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4449 | // Load from an entry in the .bss section using a PC-relative load. |
| 4450 | // Used for classes outside boot image when .bss is accessible with a PC-relative load. |
| 4451 | kBssEntry, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4452 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4453 | // Make a runtime call to resolve and call the method. This is the last-resort-kind |
| 4454 | // used when other kinds are unimplemented on a particular architecture. |
| 4455 | kRuntimeCall, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4456 | }; |
| 4457 | |
| 4458 | // Determines the location of the code pointer. |
| 4459 | enum class CodePtrLocation { |
| 4460 | // Recursive call, use local PC-relative call instruction. |
| 4461 | kCallSelf, |
| 4462 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4463 | // Use code pointer from the ArtMethod*. |
| 4464 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4465 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4466 | kCallArtMethod, |
| 4467 | }; |
| 4468 | |
| 4469 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4470 | MethodLoadKind method_load_kind; |
| 4471 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4472 | // The method load data holds |
| 4473 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4474 | // Note that there are multiple string init methods, each having its own offset. |
| 4475 | // - the method address for kDirectAddress |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4476 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4477 | }; |
| 4478 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4479 | HInvokeStaticOrDirect(ArenaAllocator* allocator, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4480 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4481 | DataType::Type return_type, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4482 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4483 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4484 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4485 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4486 | InvokeType invoke_type, |
| 4487 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4488 | ClinitCheckRequirement clinit_check_requirement) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4489 | : HInvoke(kInvokeStaticOrDirect, |
| 4490 | allocator, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4491 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4492 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4493 | // potentially one other if the clinit check is explicit, and potentially |
| 4494 | // one other if the method is a string factory. |
| 4495 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4496 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4497 | return_type, |
| 4498 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4499 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4500 | resolved_method, |
| 4501 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4502 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4503 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4504 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4505 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4506 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4507 | bool IsClonable() const OVERRIDE { return true; } |
| 4508 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4509 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4510 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4511 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4512 | |
| 4513 | // Using the current method is the default and once we find a better |
| 4514 | // method load kind, we should not go back to using the current method. |
| 4515 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4516 | |
| 4517 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4518 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4519 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4520 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4521 | dispatch_info_ = dispatch_info; |
| 4522 | } |
| 4523 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 4524 | DispatchInfo GetDispatchInfo() const { |
| 4525 | return dispatch_info_; |
| 4526 | } |
| 4527 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4528 | void AddSpecialInput(HInstruction* input) { |
| 4529 | // We allow only one special input. |
| 4530 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4531 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4532 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4533 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4534 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4535 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4536 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4537 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4538 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4539 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4540 | DCHECK(!input_records.empty()); |
| 4541 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4542 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4543 | // Note: `last_input` may be null during arguments setup. |
| 4544 | if (last_input != nullptr) { |
| 4545 | // `last_input` is the last input of a static invoke marked as having |
| 4546 | // an explicit clinit check. It must either be: |
| 4547 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4548 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4549 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4550 | } |
| 4551 | } |
| 4552 | return input_records; |
| 4553 | } |
| 4554 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4555 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4556 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4557 | // TODO: for intrinsics we can generate implicit null checks. |
| 4558 | return false; |
| 4559 | } |
| 4560 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4561 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4562 | return GetType() == DataType::Type::kReference && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4563 | } |
| 4564 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4565 | // Get the index of the special input, if any. |
| 4566 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4567 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4568 | // method pointer; otherwise there may be one platform-specific special input, |
| 4569 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4570 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4571 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4572 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4573 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4574 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4575 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4576 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4577 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4578 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4579 | bool HasPcRelativeMethodLoadKind() const { |
| 4580 | return GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4581 | GetMethodLoadKind() == MethodLoadKind::kBootImageRelRo || |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4582 | GetMethodLoadKind() == MethodLoadKind::kBssEntry; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4583 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4584 | bool HasCurrentMethodInput() const { |
| 4585 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4586 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4587 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4588 | return true; |
| 4589 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4590 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4591 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4592 | return false; |
| 4593 | } |
| 4594 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4595 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4596 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4597 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4598 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4599 | } |
| 4600 | |
| 4601 | uint64_t GetMethodAddress() const { |
| 4602 | DCHECK(HasMethodAddress()); |
| 4603 | return dispatch_info_.method_load_data; |
| 4604 | } |
| 4605 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4606 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4607 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4608 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4609 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4610 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4611 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4612 | // Is this instruction a call to a static method? |
| 4613 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4614 | return GetInvokeType() == kStatic; |
| 4615 | } |
| 4616 | |
| 4617 | MethodReference GetTargetMethod() const { |
| 4618 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4619 | } |
| 4620 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4621 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4622 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4623 | // instruction; only relevant for static calls with explicit clinit check. |
| 4624 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4625 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4626 | size_t last_input_index = inputs_.size() - 1u; |
| 4627 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4628 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4629 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4630 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4631 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4632 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4633 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4634 | } |
| 4635 | |
| 4636 | // 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] | 4637 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4638 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4639 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4640 | } |
| 4641 | |
| 4642 | // Is this a call to a static method whose declaring class has an |
| 4643 | // implicit intialization check requirement? |
| 4644 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4645 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4646 | } |
| 4647 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4648 | // Does this method load kind need the current method as an input? |
| 4649 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4650 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kRuntimeCall; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4651 | } |
| 4652 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4653 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4654 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4655 | protected: |
| 4656 | DEFAULT_COPY_CONSTRUCTOR(InvokeStaticOrDirect); |
| 4657 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4658 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4659 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4660 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4661 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4662 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4663 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4664 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4665 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4666 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4667 | kFieldClinitCheckRequirement, |
| 4668 | kFieldClinitCheckRequirementSize>; |
| 4669 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4670 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | ea179f4 | 2018-02-08 22:30:18 +0000 | [diff] [blame] | 4671 | const MethodReference target_method_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4672 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4673 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4674 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4675 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4676 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4677 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4678 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4679 | HInvokeVirtual(ArenaAllocator* allocator, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4680 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4681 | DataType::Type return_type, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4682 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4683 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4684 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4685 | uint32_t vtable_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4686 | : HInvoke(kInvokeVirtual, |
| 4687 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4688 | number_of_arguments, |
| 4689 | 0u, |
| 4690 | return_type, |
| 4691 | dex_pc, |
| 4692 | dex_method_index, |
| 4693 | resolved_method, |
| 4694 | kVirtual), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4695 | vtable_index_(vtable_index) { |
| 4696 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4697 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4698 | bool IsClonable() const OVERRIDE { return true; } |
| 4699 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4700 | bool CanBeNull() const OVERRIDE { |
| 4701 | switch (GetIntrinsic()) { |
| 4702 | case Intrinsics::kThreadCurrentThread: |
| 4703 | case Intrinsics::kStringBufferAppend: |
| 4704 | case Intrinsics::kStringBufferToString: |
| 4705 | case Intrinsics::kStringBuilderAppend: |
| 4706 | case Intrinsics::kStringBuilderToString: |
| 4707 | return false; |
| 4708 | default: |
| 4709 | return HInvoke::CanBeNull(); |
| 4710 | } |
| 4711 | } |
| 4712 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4713 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4714 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4715 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4718 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4719 | |
| 4720 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4721 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4722 | protected: |
| 4723 | DEFAULT_COPY_CONSTRUCTOR(InvokeVirtual); |
| 4724 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4725 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4726 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4727 | const uint32_t vtable_index_; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4728 | }; |
| 4729 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4730 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4731 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4732 | HInvokeInterface(ArenaAllocator* allocator, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4733 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4734 | DataType::Type return_type, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4735 | uint32_t dex_pc, |
| 4736 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4737 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4738 | uint32_t imt_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4739 | : HInvoke(kInvokeInterface, |
| 4740 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4741 | number_of_arguments, |
| 4742 | 0u, |
| 4743 | return_type, |
| 4744 | dex_pc, |
| 4745 | dex_method_index, |
| 4746 | resolved_method, |
| 4747 | kInterface), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4748 | imt_index_(imt_index) { |
| 4749 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4750 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4751 | bool IsClonable() const OVERRIDE { return true; } |
| 4752 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4753 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4754 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4755 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4756 | } |
| 4757 | |
Nicolas Geoffray | fbdfa6d | 2017-02-03 10:43:13 +0000 | [diff] [blame] | 4758 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 4759 | // The assembly stub currently needs it. |
| 4760 | return true; |
| 4761 | } |
| 4762 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4763 | uint32_t GetImtIndex() const { return imt_index_; } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4764 | |
| 4765 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4766 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4767 | protected: |
| 4768 | DEFAULT_COPY_CONSTRUCTOR(InvokeInterface); |
| 4769 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4770 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4771 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4772 | const uint32_t imt_index_; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4773 | }; |
| 4774 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4775 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4776 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4777 | 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] | 4778 | : HUnaryOperation(kNeg, result_type, input, dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4779 | DCHECK_EQ(result_type, DataType::Kind(input->GetType())); |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4780 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4781 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4782 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4783 | |
| 4784 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4785 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4786 | } |
| 4787 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4788 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4789 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4790 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4791 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4792 | } |
| 4793 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4794 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4795 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4796 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4797 | DECLARE_INSTRUCTION(Neg); |
| 4798 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4799 | protected: |
| 4800 | DEFAULT_COPY_CONSTRUCTOR(Neg); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4801 | }; |
| 4802 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4803 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4804 | public: |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4805 | HNewArray(HInstruction* cls, HInstruction* length, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4806 | : HExpression(kNewArray, DataType::Type::kReference, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4807 | SetRawInputAt(0, cls); |
| 4808 | SetRawInputAt(1, length); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4809 | } |
| 4810 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4811 | bool IsClonable() const OVERRIDE { return true; } |
| 4812 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4813 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4814 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4815 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4816 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4817 | bool CanThrow() const OVERRIDE { return true; } |
| 4818 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4819 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4820 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4821 | HLoadClass* GetLoadClass() const { |
| 4822 | DCHECK(InputAt(0)->IsLoadClass()); |
| 4823 | return InputAt(0)->AsLoadClass(); |
| 4824 | } |
| 4825 | |
| 4826 | HInstruction* GetLength() const { |
| 4827 | return InputAt(1); |
| 4828 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4829 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4830 | DECLARE_INSTRUCTION(NewArray); |
| 4831 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4832 | protected: |
| 4833 | DEFAULT_COPY_CONSTRUCTOR(NewArray); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4834 | }; |
| 4835 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4836 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4837 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4838 | HAdd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4839 | HInstruction* left, |
| 4840 | HInstruction* right, |
| 4841 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4842 | : HBinaryOperation(kAdd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4843 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4844 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4845 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4846 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4847 | 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] | 4848 | |
| 4849 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4850 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4851 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4852 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4853 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4854 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4855 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4856 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4857 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4858 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4859 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4860 | } |
| 4861 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4862 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4863 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4864 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4865 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4866 | DECLARE_INSTRUCTION(Add); |
| 4867 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4868 | protected: |
| 4869 | DEFAULT_COPY_CONSTRUCTOR(Add); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4870 | }; |
| 4871 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4872 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4873 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4874 | HSub(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4875 | HInstruction* left, |
| 4876 | HInstruction* right, |
| 4877 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4878 | : HBinaryOperation(kSub, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4879 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4880 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4881 | 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] | 4882 | |
| 4883 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4884 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4885 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4886 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4887 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4888 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4889 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4890 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4891 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4892 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4893 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4894 | } |
| 4895 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4896 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4897 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4898 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4899 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4900 | DECLARE_INSTRUCTION(Sub); |
| 4901 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4902 | protected: |
| 4903 | DEFAULT_COPY_CONSTRUCTOR(Sub); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4904 | }; |
| 4905 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4906 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4907 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4908 | HMul(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4909 | HInstruction* left, |
| 4910 | HInstruction* right, |
| 4911 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4912 | : HBinaryOperation(kMul, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4913 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4914 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4915 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4916 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4917 | 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] | 4918 | |
| 4919 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4920 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4921 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4922 | } |
| 4923 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4924 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4925 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4926 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4927 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4928 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4929 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4930 | } |
| 4931 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4932 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4933 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4934 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4935 | |
| 4936 | DECLARE_INSTRUCTION(Mul); |
| 4937 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4938 | protected: |
| 4939 | DEFAULT_COPY_CONSTRUCTOR(Mul); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4940 | }; |
| 4941 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4942 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4943 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4944 | HDiv(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4945 | HInstruction* left, |
| 4946 | HInstruction* right, |
| 4947 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4948 | : HBinaryOperation(kDiv, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4949 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4950 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4951 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4952 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4953 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4954 | // Our graph structure ensures we never have 0 for `y` during |
| 4955 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4956 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4957 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4958 | return (y == -1) ? -x : x / y; |
| 4959 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4960 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4961 | template <typename T> |
| 4962 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4963 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4964 | return x / y; |
| 4965 | } |
| 4966 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4967 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4968 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4969 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4970 | } |
| 4971 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4972 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4973 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4974 | } |
| 4975 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4976 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4977 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4978 | } |
| 4979 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4980 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4981 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4982 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4983 | |
| 4984 | DECLARE_INSTRUCTION(Div); |
| 4985 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4986 | protected: |
| 4987 | DEFAULT_COPY_CONSTRUCTOR(Div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4988 | }; |
| 4989 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4990 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4991 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4992 | HRem(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4993 | HInstruction* left, |
| 4994 | HInstruction* right, |
| 4995 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4996 | : HBinaryOperation(kRem, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4997 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4998 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4999 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5000 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5001 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5002 | // Our graph structure ensures we never have 0 for `y` during |
| 5003 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5004 | DCHECK_NE(y, 0); |
| 5005 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 5006 | return (y == -1) ? 0 : x % y; |
| 5007 | } |
| 5008 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5009 | template <typename T> |
| 5010 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5011 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5012 | return std::fmod(x, y); |
| 5013 | } |
| 5014 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5015 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5016 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5017 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5018 | } |
| 5019 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5020 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5021 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5022 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5023 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 5024 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5025 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5026 | } |
| 5027 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 5028 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5029 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5030 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5031 | |
| 5032 | DECLARE_INSTRUCTION(Rem); |
| 5033 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5034 | protected: |
| 5035 | DEFAULT_COPY_CONSTRUCTOR(Rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5036 | }; |
| 5037 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5038 | class HMin FINAL : public HBinaryOperation { |
| 5039 | public: |
| 5040 | HMin(DataType::Type result_type, |
| 5041 | HInstruction* left, |
| 5042 | HInstruction* right, |
| 5043 | uint32_t dex_pc) |
| 5044 | : HBinaryOperation(kMin, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5045 | |
| 5046 | bool IsCommutative() const OVERRIDE { return true; } |
| 5047 | |
| 5048 | // Evaluation for integral values. |
| 5049 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5050 | return (x <= y) ? x : y; |
| 5051 | } |
| 5052 | |
| 5053 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 5054 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5055 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5056 | } |
| 5057 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 5058 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5059 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5060 | } |
| 5061 | // TODO: Evaluation for floating-point values. |
| 5062 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5063 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { return nullptr; } |
| 5064 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5065 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { return nullptr; } |
| 5066 | |
| 5067 | DECLARE_INSTRUCTION(Min); |
| 5068 | |
| 5069 | protected: |
| 5070 | DEFAULT_COPY_CONSTRUCTOR(Min); |
| 5071 | }; |
| 5072 | |
| 5073 | class HMax FINAL : public HBinaryOperation { |
| 5074 | public: |
| 5075 | HMax(DataType::Type result_type, |
| 5076 | HInstruction* left, |
| 5077 | HInstruction* right, |
| 5078 | uint32_t dex_pc) |
| 5079 | : HBinaryOperation(kMax, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5080 | |
| 5081 | bool IsCommutative() const OVERRIDE { return true; } |
| 5082 | |
| 5083 | // Evaluation for integral values. |
| 5084 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5085 | return (x >= y) ? x : y; |
| 5086 | } |
| 5087 | |
| 5088 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 5089 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5090 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5091 | } |
| 5092 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 5093 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5094 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5095 | } |
| 5096 | // TODO: Evaluation for floating-point values. |
| 5097 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5098 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { return nullptr; } |
| 5099 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5100 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { return nullptr; } |
| 5101 | |
| 5102 | DECLARE_INSTRUCTION(Max); |
| 5103 | |
| 5104 | protected: |
| 5105 | DEFAULT_COPY_CONSTRUCTOR(Max); |
| 5106 | }; |
| 5107 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5108 | class HAbs FINAL : public HUnaryOperation { |
| 5109 | public: |
| 5110 | HAbs(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5111 | : HUnaryOperation(kAbs, result_type, input, dex_pc) {} |
| 5112 | |
| 5113 | // Evaluation for integral values. |
| 5114 | template <typename T> static T ComputeIntegral(T x) { |
| 5115 | return x < 0 ? -x : x; |
| 5116 | } |
| 5117 | |
| 5118 | // Evaluation for floating-point values. |
| 5119 | // Note, as a "quality of implementation", rather than pure "spec compliance", |
| 5120 | // we require that Math.abs() clears the sign bit (but changes nothing else) |
| 5121 | // for all floating-point numbers, including NaN (signaling NaN may become quiet though). |
| 5122 | // http://b/30758343 |
| 5123 | template <typename T, typename S> static T ComputeFP(T x) { |
| 5124 | S bits = bit_cast<S, T>(x); |
| 5125 | return bit_cast<T, S>(bits & std::numeric_limits<S>::max()); |
| 5126 | } |
| 5127 | |
| 5128 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
| 5129 | return GetBlock()->GetGraph()->GetIntConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5130 | } |
| 5131 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
| 5132 | return GetBlock()->GetGraph()->GetLongConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5133 | } |
| 5134 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 5135 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5136 | ComputeFP<float, int32_t>(x->GetValue()), GetDexPc()); |
| 5137 | } |
| 5138 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 5139 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5140 | ComputeFP<double, int64_t>(x->GetValue()), GetDexPc()); |
| 5141 | } |
| 5142 | |
| 5143 | DECLARE_INSTRUCTION(Abs); |
| 5144 | |
| 5145 | protected: |
| 5146 | DEFAULT_COPY_CONSTRUCTOR(Abs); |
| 5147 | }; |
| 5148 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5149 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5150 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 5151 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 5152 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5153 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5154 | : HExpression(kDivZeroCheck, value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5155 | SetRawInputAt(0, value); |
| 5156 | } |
| 5157 | |
| 5158 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5159 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5160 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5161 | return true; |
| 5162 | } |
| 5163 | |
| 5164 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5165 | bool CanThrow() const OVERRIDE { return true; } |
| 5166 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5167 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 5168 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5169 | protected: |
| 5170 | DEFAULT_COPY_CONSTRUCTOR(DivZeroCheck); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5171 | }; |
| 5172 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5173 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5174 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5175 | HShl(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5176 | HInstruction* value, |
| 5177 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5178 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5179 | : HBinaryOperation(kShl, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5180 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5181 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5182 | } |
| 5183 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5184 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5185 | 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] | 5186 | return value << (distance & max_shift_distance); |
| 5187 | } |
| 5188 | |
| 5189 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5190 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5191 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5192 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5193 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5194 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5195 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5196 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5197 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5198 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5199 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5200 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5201 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5202 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5203 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5204 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5205 | UNREACHABLE(); |
| 5206 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5207 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5208 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5209 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5210 | UNREACHABLE(); |
| 5211 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5212 | |
| 5213 | DECLARE_INSTRUCTION(Shl); |
| 5214 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5215 | protected: |
| 5216 | DEFAULT_COPY_CONSTRUCTOR(Shl); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5217 | }; |
| 5218 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5219 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5220 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5221 | HShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5222 | HInstruction* value, |
| 5223 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5224 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5225 | : HBinaryOperation(kShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5226 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5227 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5228 | } |
| 5229 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5230 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5231 | 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] | 5232 | return value >> (distance & max_shift_distance); |
| 5233 | } |
| 5234 | |
| 5235 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5236 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5237 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5238 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5239 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5240 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5241 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5242 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5243 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5244 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5245 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5246 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5247 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5248 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5249 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5250 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5251 | UNREACHABLE(); |
| 5252 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5253 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5254 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5255 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5256 | UNREACHABLE(); |
| 5257 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5258 | |
| 5259 | DECLARE_INSTRUCTION(Shr); |
| 5260 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5261 | protected: |
| 5262 | DEFAULT_COPY_CONSTRUCTOR(Shr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5263 | }; |
| 5264 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5265 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5266 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5267 | HUShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5268 | HInstruction* value, |
| 5269 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5270 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5271 | : HBinaryOperation(kUShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5272 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5273 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5274 | } |
| 5275 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5276 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5277 | 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] | 5278 | typedef typename std::make_unsigned<T>::type V; |
| 5279 | V ux = static_cast<V>(value); |
| 5280 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 5281 | } |
| 5282 | |
| 5283 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5284 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5285 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5286 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5287 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5288 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5289 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5290 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5291 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5292 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5293 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5294 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5295 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5296 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5297 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5298 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5299 | UNREACHABLE(); |
| 5300 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5301 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5302 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5303 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5304 | UNREACHABLE(); |
| 5305 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5306 | |
| 5307 | DECLARE_INSTRUCTION(UShr); |
| 5308 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5309 | protected: |
| 5310 | DEFAULT_COPY_CONSTRUCTOR(UShr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5311 | }; |
| 5312 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5313 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5314 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5315 | HAnd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5316 | HInstruction* left, |
| 5317 | HInstruction* right, |
| 5318 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5319 | : HBinaryOperation(kAnd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5320 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5321 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5322 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5323 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5324 | 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] | 5325 | |
| 5326 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5327 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5328 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5329 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5330 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5331 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5332 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5333 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5334 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5335 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5336 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5337 | UNREACHABLE(); |
| 5338 | } |
| 5339 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5340 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5341 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5342 | UNREACHABLE(); |
| 5343 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5344 | |
| 5345 | DECLARE_INSTRUCTION(And); |
| 5346 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5347 | protected: |
| 5348 | DEFAULT_COPY_CONSTRUCTOR(And); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5349 | }; |
| 5350 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5351 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5352 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5353 | HOr(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5354 | HInstruction* left, |
| 5355 | HInstruction* right, |
| 5356 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5357 | : HBinaryOperation(kOr, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5358 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5359 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5360 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5361 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5362 | 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] | 5363 | |
| 5364 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5365 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5366 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5367 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5368 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5369 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5370 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5371 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5372 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5373 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5374 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5375 | UNREACHABLE(); |
| 5376 | } |
| 5377 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5378 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5379 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5380 | UNREACHABLE(); |
| 5381 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5382 | |
| 5383 | DECLARE_INSTRUCTION(Or); |
| 5384 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5385 | protected: |
| 5386 | DEFAULT_COPY_CONSTRUCTOR(Or); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5387 | }; |
| 5388 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5389 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5390 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5391 | HXor(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5392 | HInstruction* left, |
| 5393 | HInstruction* right, |
| 5394 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5395 | : HBinaryOperation(kXor, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5396 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5397 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5398 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5399 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5400 | 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] | 5401 | |
| 5402 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5403 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5404 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5405 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5406 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5407 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5408 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5409 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5410 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5411 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5412 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5413 | UNREACHABLE(); |
| 5414 | } |
| 5415 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5416 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5417 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5418 | UNREACHABLE(); |
| 5419 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5420 | |
| 5421 | DECLARE_INSTRUCTION(Xor); |
| 5422 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5423 | protected: |
| 5424 | DEFAULT_COPY_CONSTRUCTOR(Xor); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5425 | }; |
| 5426 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5427 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5428 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5429 | HRor(DataType::Type result_type, HInstruction* value, HInstruction* distance) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5430 | : HBinaryOperation(kRor, result_type, value, distance) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5431 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5432 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5433 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5434 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5435 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5436 | 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] | 5437 | typedef typename std::make_unsigned<T>::type V; |
| 5438 | V ux = static_cast<V>(value); |
| 5439 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5440 | return static_cast<T>(ux); |
| 5441 | } else { |
| 5442 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5443 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 5444 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5445 | } |
| 5446 | } |
| 5447 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5448 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5449 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5450 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5451 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5452 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5453 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5454 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5455 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5456 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5457 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5458 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5459 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5460 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5461 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5462 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5463 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5464 | UNREACHABLE(); |
| 5465 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5466 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5467 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5468 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5469 | UNREACHABLE(); |
| 5470 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5471 | |
| 5472 | DECLARE_INSTRUCTION(Ror); |
| 5473 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5474 | protected: |
| 5475 | DEFAULT_COPY_CONSTRUCTOR(Ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5476 | }; |
| 5477 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5478 | // The value of a parameter in this method. Its location depends on |
| 5479 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5480 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5481 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5482 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5483 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5484 | uint8_t index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5485 | DataType::Type parameter_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5486 | bool is_this = false) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5487 | : HExpression(kParameterValue, parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5488 | dex_file_(dex_file), |
| 5489 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5490 | index_(index) { |
| 5491 | SetPackedFlag<kFlagIsThis>(is_this); |
| 5492 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 5493 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5494 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5495 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5496 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5497 | uint8_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5498 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5499 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5500 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 5501 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5502 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5503 | DECLARE_INSTRUCTION(ParameterValue); |
| 5504 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5505 | protected: |
| 5506 | DEFAULT_COPY_CONSTRUCTOR(ParameterValue); |
| 5507 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5508 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5509 | // Whether or not the parameter value corresponds to 'this' argument. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5510 | static constexpr size_t kFlagIsThis = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5511 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 5512 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 5513 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 5514 | "Too many packed fields."); |
| 5515 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5516 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5517 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5518 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5519 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5520 | const uint8_t index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5521 | }; |
| 5522 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5523 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5524 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5525 | 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] | 5526 | : HUnaryOperation(kNot, result_type, input, dex_pc) { |
| 5527 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5528 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5529 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5530 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5531 | return true; |
| 5532 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5533 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5534 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5535 | |
| 5536 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5537 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5538 | } |
| 5539 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5540 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5541 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5542 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5543 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5544 | UNREACHABLE(); |
| 5545 | } |
| 5546 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5547 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5548 | UNREACHABLE(); |
| 5549 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5550 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5551 | DECLARE_INSTRUCTION(Not); |
| 5552 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5553 | protected: |
| 5554 | DEFAULT_COPY_CONSTRUCTOR(Not); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5555 | }; |
| 5556 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5557 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5558 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5559 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5560 | : HUnaryOperation(kBooleanNot, DataType::Type::kBool, input, dex_pc) { |
| 5561 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5562 | |
| 5563 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5564 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5565 | return true; |
| 5566 | } |
| 5567 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5568 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5569 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5570 | return !x; |
| 5571 | } |
| 5572 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5573 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5574 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5575 | } |
| 5576 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5577 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5578 | UNREACHABLE(); |
| 5579 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5580 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5581 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5582 | UNREACHABLE(); |
| 5583 | } |
| 5584 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5585 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5586 | UNREACHABLE(); |
| 5587 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5588 | |
| 5589 | DECLARE_INSTRUCTION(BooleanNot); |
| 5590 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5591 | protected: |
| 5592 | DEFAULT_COPY_CONSTRUCTOR(BooleanNot); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5593 | }; |
| 5594 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5595 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5596 | public: |
| 5597 | // Instantiate a type conversion of `input` to `result_type`. |
Vladimir Marko | c8fb211 | 2017-10-03 11:37:52 +0100 | [diff] [blame] | 5598 | 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] | 5599 | : HExpression(kTypeConversion, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5600 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5601 | // Invariant: We should never generate a conversion to a Boolean value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5602 | DCHECK_NE(DataType::Type::kBool, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5606 | DataType::Type GetInputType() const { return GetInput()->GetType(); } |
| 5607 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5608 | |
| 5609 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5610 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5611 | return true; |
| 5612 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5613 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5614 | // Try to statically evaluate the conversion and return a HConstant |
| 5615 | // containing the result. If the input cannot be converted, return nullptr. |
| 5616 | HConstant* TryStaticEvaluation() const; |
| 5617 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5618 | DECLARE_INSTRUCTION(TypeConversion); |
| 5619 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5620 | protected: |
| 5621 | DEFAULT_COPY_CONSTRUCTOR(TypeConversion); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5622 | }; |
| 5623 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5624 | static constexpr uint32_t kNoRegNumber = -1; |
| 5625 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5626 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5627 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5628 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 5629 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5630 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5631 | : HExpression(kNullCheck, value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5632 | SetRawInputAt(0, value); |
| 5633 | } |
| 5634 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5635 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5636 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5637 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5638 | return true; |
| 5639 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5640 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5641 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5642 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5643 | bool CanThrow() const OVERRIDE { return true; } |
| 5644 | |
| 5645 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5646 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5647 | DECLARE_INSTRUCTION(NullCheck); |
| 5648 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5649 | protected: |
| 5650 | DEFAULT_COPY_CONSTRUCTOR(NullCheck); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5651 | }; |
| 5652 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5653 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5654 | // 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] | 5655 | class FieldInfo : public ValueObject { |
| 5656 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5657 | FieldInfo(ArtField* field, |
| 5658 | MemberOffset field_offset, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5659 | DataType::Type field_type, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5660 | bool is_volatile, |
| 5661 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5662 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5663 | const DexFile& dex_file) |
| 5664 | : field_(field), |
| 5665 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5666 | field_type_(field_type), |
| 5667 | is_volatile_(is_volatile), |
| 5668 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5669 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5670 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5671 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5672 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5673 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5674 | DataType::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5675 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5676 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5677 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5678 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5679 | |
| 5680 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5681 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5682 | const MemberOffset field_offset_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5683 | const DataType::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5684 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5685 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5686 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5687 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5688 | }; |
| 5689 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5690 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5691 | public: |
| 5692 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5693 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5694 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5695 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5696 | bool is_volatile, |
| 5697 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5698 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5699 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5700 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5701 | : HExpression(kInstanceFieldGet, |
| 5702 | field_type, |
| 5703 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5704 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5705 | field_info_(field, |
| 5706 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5707 | field_type, |
| 5708 | is_volatile, |
| 5709 | field_idx, |
| 5710 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5711 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5712 | SetRawInputAt(0, value); |
| 5713 | } |
| 5714 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5715 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5716 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5717 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5718 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5719 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5720 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5721 | } |
| 5722 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5723 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5724 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5725 | } |
| 5726 | |
| 5727 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5728 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5729 | } |
| 5730 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5731 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5732 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5733 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5734 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5735 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5736 | void SetType(DataType::Type new_type) { |
| 5737 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5738 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5739 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5740 | SetPackedField<TypeField>(new_type); |
| 5741 | } |
| 5742 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5743 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5744 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5745 | protected: |
| 5746 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldGet); |
| 5747 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5748 | private: |
| 5749 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5750 | }; |
| 5751 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5752 | class HInstanceFieldSet FINAL : public HExpression<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5753 | public: |
| 5754 | HInstanceFieldSet(HInstruction* object, |
| 5755 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5756 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5757 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5758 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5759 | bool is_volatile, |
| 5760 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5761 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5762 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5763 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5764 | : HExpression(kInstanceFieldSet, |
| 5765 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5766 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5767 | field_info_(field, |
| 5768 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5769 | field_type, |
| 5770 | is_volatile, |
| 5771 | field_idx, |
| 5772 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5773 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5774 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5775 | SetRawInputAt(0, object); |
| 5776 | SetRawInputAt(1, value); |
| 5777 | } |
| 5778 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5779 | bool IsClonable() const OVERRIDE { return true; } |
| 5780 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5781 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5782 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5783 | } |
| 5784 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5785 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5786 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5787 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5788 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5789 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5790 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5791 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5792 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5793 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5794 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5795 | protected: |
| 5796 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldSet); |
| 5797 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5798 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5799 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5800 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5801 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5802 | "Too many packed fields."); |
| 5803 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5804 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5805 | }; |
| 5806 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5807 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5808 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5809 | HArrayGet(HInstruction* array, |
| 5810 | HInstruction* index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5811 | DataType::Type type, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5812 | uint32_t dex_pc) |
| 5813 | : HArrayGet(array, |
| 5814 | index, |
| 5815 | type, |
| 5816 | SideEffects::ArrayReadOfType(type), |
| 5817 | dex_pc, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5818 | /* is_string_char_at */ false) { |
| 5819 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5820 | |
| 5821 | HArrayGet(HInstruction* array, |
| 5822 | HInstruction* index, |
| 5823 | DataType::Type type, |
| 5824 | SideEffects side_effects, |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5825 | uint32_t dex_pc, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5826 | bool is_string_char_at) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5827 | : HExpression(kArrayGet, type, side_effects, dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5828 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5829 | SetRawInputAt(0, array); |
| 5830 | SetRawInputAt(1, index); |
| 5831 | } |
| 5832 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5833 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5834 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5835 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5836 | return true; |
| 5837 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5838 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5839 | // TODO: We can be smarter here. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5840 | // Currently, unless the array is the result of NewArray, the array access is always |
| 5841 | // preceded by some form of null NullCheck necessary for the bounds check, usually |
| 5842 | // implicit null check on the ArrayLength input to BoundsCheck or Deoptimize for |
| 5843 | // dynamic BCE. There are cases when these could be removed to produce better code. |
| 5844 | // If we ever add optimizations to do so we should allow an implicit check here |
| 5845 | // (as long as the address falls in the first page). |
| 5846 | // |
| 5847 | // As an example of such fancy optimization, we could eliminate BoundsCheck for |
| 5848 | // a = cond ? new int[1] : null; |
| 5849 | // a[0]; // The Phi does not need bounds check for either input. |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5850 | return false; |
| 5851 | } |
| 5852 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5853 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5854 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5855 | if (kIsDebugBuild && result) { |
| 5856 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5857 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5858 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5859 | if (DataType::IsIntOrLongType(GetType())) { |
| 5860 | DCHECK(DataType::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5861 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5862 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| 5863 | DCHECK(DataType::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5864 | } |
| 5865 | } |
| 5866 | return result; |
| 5867 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5868 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5869 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5870 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5871 | HInstruction* GetArray() const { return InputAt(0); } |
| 5872 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5873 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5874 | void SetType(DataType::Type new_type) { |
| 5875 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5876 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5877 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5878 | SetPackedField<TypeField>(new_type); |
| 5879 | } |
| 5880 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5881 | DECLARE_INSTRUCTION(ArrayGet); |
| 5882 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5883 | protected: |
| 5884 | DEFAULT_COPY_CONSTRUCTOR(ArrayGet); |
| 5885 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5886 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5887 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5888 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5889 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5890 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5891 | // 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] | 5892 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5893 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5894 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5895 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5896 | }; |
| 5897 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5898 | class HArraySet FINAL : public HExpression<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5899 | public: |
| 5900 | HArraySet(HInstruction* array, |
| 5901 | HInstruction* index, |
| 5902 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5903 | DataType::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5904 | uint32_t dex_pc) |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5905 | : HArraySet(array, |
| 5906 | index, |
| 5907 | value, |
| 5908 | expected_component_type, |
| 5909 | // Make a best guess for side effects now, may be refined during SSA building. |
| 5910 | ComputeSideEffects(GetComponentType(value->GetType(), expected_component_type)), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5911 | dex_pc) { |
| 5912 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5913 | |
| 5914 | HArraySet(HInstruction* array, |
| 5915 | HInstruction* index, |
| 5916 | HInstruction* value, |
| 5917 | DataType::Type expected_component_type, |
| 5918 | SideEffects side_effects, |
| 5919 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5920 | : HExpression(kArraySet, side_effects, dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5921 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5922 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5923 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5924 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5925 | SetRawInputAt(0, array); |
| 5926 | SetRawInputAt(1, index); |
| 5927 | SetRawInputAt(2, value); |
| 5928 | } |
| 5929 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5930 | bool IsClonable() const OVERRIDE { return true; } |
| 5931 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5932 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5933 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5934 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5935 | } |
| 5936 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5937 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5938 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5939 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5940 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5941 | // TODO: Same as for ArrayGet. |
| 5942 | return false; |
| 5943 | } |
| 5944 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5945 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5946 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5947 | } |
| 5948 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5949 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5950 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5951 | } |
| 5952 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5953 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5954 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5955 | } |
| 5956 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5957 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5958 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5959 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5960 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5961 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5962 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5963 | HInstruction* GetArray() const { return InputAt(0); } |
| 5964 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5965 | HInstruction* GetValue() const { return InputAt(2); } |
| 5966 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5967 | DataType::Type GetComponentType() const { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5968 | return GetComponentType(GetValue()->GetType(), GetRawExpectedComponentType()); |
| 5969 | } |
| 5970 | |
| 5971 | static DataType::Type GetComponentType(DataType::Type value_type, |
| 5972 | DataType::Type expected_component_type) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5973 | // The Dex format does not type floating point index operations. Since the |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5974 | // `expected_component_type` comes from SSA building and can therefore not |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5975 | // be correct, we also check what is the value type. If it is a floating |
| 5976 | // point type, we must use that type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5977 | return ((value_type == DataType::Type::kFloat32) || (value_type == DataType::Type::kFloat64)) |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5978 | ? value_type |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5979 | : expected_component_type; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5980 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5981 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5982 | DataType::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5983 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5984 | } |
| 5985 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5986 | static SideEffects ComputeSideEffects(DataType::Type type) { |
| 5987 | return SideEffects::ArrayWriteOfType(type).Union(SideEffectsForArchRuntimeCalls(type)); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5988 | } |
| 5989 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5990 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type value_type) { |
| 5991 | return (value_type == DataType::Type::kReference) ? SideEffects::CanTriggerGC() |
| 5992 | : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5993 | } |
| 5994 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5995 | DECLARE_INSTRUCTION(ArraySet); |
| 5996 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5997 | protected: |
| 5998 | DEFAULT_COPY_CONSTRUCTOR(ArraySet); |
| 5999 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6000 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6001 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 6002 | static constexpr size_t kFieldExpectedComponentTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6003 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6004 | static constexpr size_t kFlagNeedsTypeCheck = |
| 6005 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 6006 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6007 | // Cached information for the reference_type_info_ so that codegen |
| 6008 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6009 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 6010 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 6011 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 6012 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6013 | using ExpectedComponentTypeField = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6014 | BitField<DataType::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6015 | }; |
| 6016 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6017 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6018 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6019 | 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] | 6020 | : HExpression(kArrayLength, DataType::Type::kInt32, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6021 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6022 | // Note that arrays do not change length, so the instruction does not |
| 6023 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6024 | SetRawInputAt(0, array); |
| 6025 | } |
| 6026 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6027 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6028 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6029 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6030 | return true; |
| 6031 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 6032 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 6033 | return obj == InputAt(0); |
| 6034 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6035 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6036 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 6037 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6038 | DECLARE_INSTRUCTION(ArrayLength); |
| 6039 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6040 | protected: |
| 6041 | DEFAULT_COPY_CONSTRUCTOR(ArrayLength); |
| 6042 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6043 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6044 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 6045 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 6046 | // determine whether a particular HArrayLength is actually a String.length() by |
| 6047 | // looking at the type of the input but that requires holding the mutator lock, so |
| 6048 | // 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] | 6049 | static constexpr size_t kFlagIsStringLength = kNumberOfGenericPackedBits; |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6050 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 6051 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6052 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6053 | }; |
| 6054 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6055 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6056 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 6057 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 6058 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6059 | HBoundsCheck(HInstruction* index, |
| 6060 | HInstruction* length, |
| 6061 | uint32_t dex_pc, |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6062 | bool is_string_char_at = false) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6063 | : HExpression(kBoundsCheck, index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6064 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(index->GetType())); |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6065 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6066 | SetRawInputAt(0, index); |
| 6067 | SetRawInputAt(1, length); |
| 6068 | } |
| 6069 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6070 | bool IsClonable() const OVERRIDE { return true; } |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6071 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6072 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6073 | return true; |
| 6074 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6075 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6076 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6077 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6078 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 6079 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 6080 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6081 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6082 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6083 | |
| 6084 | DECLARE_INSTRUCTION(BoundsCheck); |
| 6085 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6086 | protected: |
| 6087 | DEFAULT_COPY_CONSTRUCTOR(BoundsCheck); |
| 6088 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6089 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6090 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6091 | }; |
| 6092 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6093 | class HSuspendCheck FINAL : public HExpression<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6094 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 6095 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6096 | : HExpression(kSuspendCheck, SideEffects::CanTriggerGC(), dex_pc), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6097 | slow_path_(nullptr) { |
| 6098 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6099 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6100 | bool IsClonable() const OVERRIDE { return true; } |
| 6101 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6102 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6103 | return true; |
| 6104 | } |
| 6105 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6106 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 6107 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6108 | |
| 6109 | DECLARE_INSTRUCTION(SuspendCheck); |
| 6110 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6111 | protected: |
| 6112 | DEFAULT_COPY_CONSTRUCTOR(SuspendCheck); |
| 6113 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6114 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6115 | // Only used for code generation, in order to share the same slow path between back edges |
| 6116 | // of a same loop. |
| 6117 | SlowPathCode* slow_path_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6118 | }; |
| 6119 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6120 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 6121 | // 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] | 6122 | class HNativeDebugInfo : public HExpression<0> { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6123 | public: |
| 6124 | explicit HNativeDebugInfo(uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6125 | : HExpression<0>(kNativeDebugInfo, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6126 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6127 | |
| 6128 | bool NeedsEnvironment() const OVERRIDE { |
| 6129 | return true; |
| 6130 | } |
| 6131 | |
| 6132 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 6133 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6134 | protected: |
| 6135 | DEFAULT_COPY_CONSTRUCTOR(NativeDebugInfo); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6136 | }; |
| 6137 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6138 | /** |
| 6139 | * Instruction to load a Class object. |
| 6140 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6141 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6142 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6143 | // Determines how to load the Class. |
| 6144 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6145 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 6146 | kInvalid = -1, |
| 6147 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6148 | // Use the Class* from the method's own ArtMethod*. |
| 6149 | kReferrersClass, |
| 6150 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6151 | // 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] | 6152 | // Used for boot image classes referenced by boot image code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6153 | kBootImageLinkTimePcRelative, |
| 6154 | |
| 6155 | // Use a known boot image Class* address, embedded in the code by the codegen. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6156 | // Used for boot image classes referenced by apps in JIT- and AOT-compiled code (non-PIC). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6157 | kBootImageAddress, |
| 6158 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6159 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| 6160 | // Used for boot image classes referenced by apps in AOT-compiled code (PIC). |
| 6161 | kBootImageRelRo, |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6162 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6163 | // Load from an entry in the .bss section using a PC-relative load. |
| 6164 | // Used for classes outside boot image when .bss is accessible with a PC-relative load. |
| 6165 | kBssEntry, |
| 6166 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6167 | // Load from the root table associated with the JIT compiled method. |
| 6168 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6169 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6170 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6171 | // the codegen is unable to use another appropriate kind. |
| 6172 | kRuntimeCall, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6173 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6174 | kLast = kRuntimeCall |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6175 | }; |
| 6176 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6177 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6178 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6179 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6180 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6181 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6182 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6183 | bool needs_access_check) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6184 | : HInstruction(kLoadClass, |
| 6185 | DataType::Type::kReference, |
| 6186 | SideEffectsForArchRuntimeCalls(), |
| 6187 | dex_pc), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6188 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6189 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6190 | dex_file_(dex_file), |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6191 | klass_(klass) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 6192 | // Referrers class should not need access check. We never inline unverified |
| 6193 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6194 | DCHECK(!is_referrers_class || !needs_access_check); |
| 6195 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6196 | SetPackedField<LoadKindField>( |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6197 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kRuntimeCall); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6198 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6199 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6200 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6201 | SetPackedFlag<kFlagValidLoadedClassRTI>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6202 | } |
| 6203 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6204 | bool IsClonable() const OVERRIDE { return true; } |
| 6205 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6206 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6207 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6208 | LoadKind GetLoadKind() const { |
| 6209 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6210 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6211 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6212 | bool HasPcRelativeLoadKind() const { |
| 6213 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6214 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 6215 | GetLoadKind() == LoadKind::kBssEntry; |
| 6216 | } |
| 6217 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6218 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6219 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6220 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6221 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6222 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6223 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 6224 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6225 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6226 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6227 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6228 | } |
| 6229 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 6230 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 6231 | // The entrypoint the code generator is going to call does not do |
| 6232 | // clinit of the class. |
| 6233 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6234 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6235 | } |
| 6236 | |
| 6237 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6238 | return NeedsAccessCheck() || |
| 6239 | MustGenerateClinitCheck() || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6240 | GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6241 | GetLoadKind() == LoadKind::kBssEntry; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6242 | } |
| 6243 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6244 | bool CanThrow() const OVERRIDE { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6245 | return NeedsAccessCheck() || |
| 6246 | MustGenerateClinitCheck() || |
| 6247 | // If the class is in the boot image, the lookup in the runtime call cannot throw. |
| 6248 | // This keeps CanThrow() consistent between non-PIC (using kBootImageAddress) and |
| 6249 | // PIC and subsequently avoids a DCE behavior dependency on the PIC option. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6250 | ((GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6251 | GetLoadKind() == LoadKind::kBssEntry) && |
| 6252 | !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6253 | } |
| 6254 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6255 | ReferenceTypeInfo GetLoadedClassRTI() { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6256 | if (GetPackedFlag<kFlagValidLoadedClassRTI>()) { |
| 6257 | // Note: The is_exact flag from the return value should not be used. |
| 6258 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact */ true); |
| 6259 | } else { |
| 6260 | return ReferenceTypeInfo::CreateInvalid(); |
| 6261 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6262 | } |
| 6263 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6264 | // Loaded class RTI is marked as valid by RTP if the klass_ is admissible. |
| 6265 | void SetValidLoadedClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 6266 | DCHECK(klass_ != nullptr); |
| 6267 | SetPackedFlag<kFlagValidLoadedClassRTI>(true); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6268 | } |
| 6269 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6270 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6271 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6272 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6273 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6274 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6275 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 6276 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6277 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6278 | return SideEffects::CanTriggerGC(); |
| 6279 | } |
| 6280 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6281 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6282 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6283 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6284 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6285 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6286 | void MarkInBootImage() { |
| 6287 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 6288 | } |
| 6289 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6290 | void AddSpecialInput(HInstruction* special_input); |
| 6291 | |
| 6292 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6293 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6294 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6295 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6296 | } |
| 6297 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6298 | Handle<mirror::Class> GetClass() const { |
| 6299 | return klass_; |
| 6300 | } |
| 6301 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6302 | DECLARE_INSTRUCTION(LoadClass); |
| 6303 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6304 | protected: |
| 6305 | DEFAULT_COPY_CONSTRUCTOR(LoadClass); |
| 6306 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6307 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6308 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6309 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6310 | // Whether this instruction must generate the initialization check. |
| 6311 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6312 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6313 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 6314 | static constexpr size_t kFieldLoadKindSize = |
| 6315 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6316 | static constexpr size_t kFlagValidLoadedClassRTI = kFieldLoadKind + kFieldLoadKindSize; |
| 6317 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagValidLoadedClassRTI + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6318 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6319 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 6320 | |
| 6321 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6322 | return load_kind == LoadKind::kReferrersClass || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6323 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6324 | load_kind == LoadKind::kBssEntry || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6325 | load_kind == LoadKind::kRuntimeCall; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6326 | } |
| 6327 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6328 | void SetLoadKindInternal(LoadKind load_kind); |
| 6329 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6330 | // The special input is the HCurrentMethod for kRuntimeCall or kReferrersClass. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6331 | // 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] | 6332 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6333 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6334 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6335 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 6336 | // - The compiling method's dex file if the class is defined there too. |
| 6337 | // - The compiling method's dex file if the class is referenced there. |
| 6338 | // - 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] | 6339 | // kBssEntry or kRuntimeCall, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6340 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6341 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6342 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6343 | Handle<mirror::Class> klass_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6344 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6345 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 6346 | |
| 6347 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6348 | inline void HLoadClass::SetLoadKind(LoadKind load_kind) { |
| 6349 | // The load kind should be determined before inserting the instruction to the graph. |
| 6350 | DCHECK(GetBlock() == nullptr); |
| 6351 | DCHECK(GetEnvironment() == nullptr); |
| 6352 | SetPackedField<LoadKindField>(load_kind); |
| 6353 | if (load_kind != LoadKind::kRuntimeCall && load_kind != LoadKind::kReferrersClass) { |
| 6354 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6355 | } |
| 6356 | if (!NeedsEnvironment()) { |
| 6357 | SetSideEffects(SideEffects::None()); |
| 6358 | } |
| 6359 | } |
| 6360 | |
| 6361 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6362 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6363 | // The special input is used for PC-relative loads on some architectures, |
| 6364 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6365 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6366 | GetLoadKind() == LoadKind::kBootImageAddress || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6367 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6368 | GetLoadKind() == LoadKind::kBssEntry) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6369 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6370 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 6371 | special_input->AddUseAt(this, 0); |
| 6372 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6373 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6374 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6375 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6376 | // Determines how to load the String. |
| 6377 | enum class LoadKind { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6378 | // 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] | 6379 | // Used for boot image strings referenced by boot image code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6380 | kBootImageLinkTimePcRelative, |
| 6381 | |
| 6382 | // Use a known boot image String* address, embedded in the code by the codegen. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6383 | // Used for boot image strings referenced by apps in JIT- and AOT-compiled code (non-PIC). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6384 | kBootImageAddress, |
| 6385 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6386 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| 6387 | // Used for boot image strings referenced by apps in AOT-compiled code (PIC). |
| 6388 | kBootImageRelRo, |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6389 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6390 | // Load from an entry in the .bss section using a PC-relative load. |
| 6391 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 6392 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6393 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6394 | // Load from the root table associated with the JIT compiled method. |
| 6395 | kJitTableAddress, |
| 6396 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6397 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6398 | // the codegen is unable to use another appropriate kind. |
| 6399 | kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6400 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6401 | kLast = kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6402 | }; |
| 6403 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6404 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6405 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6406 | const DexFile& dex_file, |
| 6407 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6408 | : HInstruction(kLoadString, |
| 6409 | DataType::Type::kReference, |
| 6410 | SideEffectsForArchRuntimeCalls(), |
| 6411 | dex_pc), |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6412 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6413 | string_index_(string_index), |
| 6414 | dex_file_(dex_file) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6415 | SetPackedField<LoadKindField>(LoadKind::kRuntimeCall); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6416 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6417 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6418 | bool IsClonable() const OVERRIDE { return true; } |
| 6419 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6420 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6421 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6422 | LoadKind GetLoadKind() const { |
| 6423 | return GetPackedField<LoadKindField>(); |
| 6424 | } |
| 6425 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6426 | bool HasPcRelativeLoadKind() const { |
| 6427 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6428 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 6429 | GetLoadKind() == LoadKind::kBssEntry; |
| 6430 | } |
| 6431 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6432 | const DexFile& GetDexFile() const { |
| 6433 | return dex_file_; |
| 6434 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6435 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6436 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6437 | return string_index_; |
| 6438 | } |
| 6439 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6440 | Handle<mirror::String> GetString() const { |
| 6441 | return string_; |
| 6442 | } |
| 6443 | |
| 6444 | void SetString(Handle<mirror::String> str) { |
| 6445 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6446 | } |
| 6447 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6448 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6449 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6450 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6451 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6452 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6453 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6454 | // Will call the runtime if we need to load the string through |
| 6455 | // the dex cache and the string is not guaranteed to be there yet. |
| 6456 | bool NeedsEnvironment() const OVERRIDE { |
| 6457 | LoadKind load_kind = GetLoadKind(); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6458 | if (load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6459 | load_kind == LoadKind::kBootImageAddress || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6460 | load_kind == LoadKind::kBootImageRelRo || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6461 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6462 | return false; |
| 6463 | } |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6464 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6465 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6466 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6467 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6468 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6469 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6470 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 6471 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6472 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6473 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6474 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6475 | return SideEffects::CanTriggerGC(); |
| 6476 | } |
| 6477 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6478 | void AddSpecialInput(HInstruction* special_input); |
| 6479 | |
| 6480 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6481 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6482 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6483 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6484 | } |
| 6485 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6486 | DECLARE_INSTRUCTION(LoadString); |
| 6487 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6488 | protected: |
| 6489 | DEFAULT_COPY_CONSTRUCTOR(LoadString); |
| 6490 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6491 | private: |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6492 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6493 | static constexpr size_t kFieldLoadKindSize = |
| 6494 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 6495 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6496 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6497 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6498 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6499 | void SetLoadKindInternal(LoadKind load_kind); |
| 6500 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6501 | // The special input is the HCurrentMethod for kRuntimeCall. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6502 | // 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] | 6503 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6504 | HUserRecord<HInstruction*> special_input_; |
| 6505 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6506 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6507 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6508 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6509 | Handle<mirror::String> string_; |
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 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 6512 | |
| 6513 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6514 | inline void HLoadString::SetLoadKind(LoadKind load_kind) { |
| 6515 | // The load kind should be determined before inserting the instruction to the graph. |
| 6516 | DCHECK(GetBlock() == nullptr); |
| 6517 | DCHECK(GetEnvironment() == nullptr); |
| 6518 | DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); |
| 6519 | SetPackedField<LoadKindField>(load_kind); |
| 6520 | if (load_kind != LoadKind::kRuntimeCall) { |
| 6521 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6522 | } |
| 6523 | if (!NeedsEnvironment()) { |
| 6524 | SetSideEffects(SideEffects::None()); |
| 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6529 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6530 | // The special input is used for PC-relative loads on some architectures, |
| 6531 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6532 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6533 | GetLoadKind() == LoadKind::kBootImageAddress || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6534 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6535 | GetLoadKind() == LoadKind::kBssEntry) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6536 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 6537 | // so use the GetInputRecords() from the base class to set the input record. |
| 6538 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6539 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6540 | special_input->AddUseAt(this, 0); |
| 6541 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6542 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6543 | class HLoadMethodHandle FINAL : public HInstruction { |
| 6544 | public: |
| 6545 | HLoadMethodHandle(HCurrentMethod* current_method, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame^] | 6546 | uint16_t method_handle_idx, |
| 6547 | const DexFile& dex_file, |
| 6548 | uint32_t dex_pc) |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6549 | : HInstruction(kLoadMethodHandle, |
| 6550 | DataType::Type::kReference, |
| 6551 | SideEffectsForArchRuntimeCalls(), |
| 6552 | dex_pc), |
| 6553 | special_input_(HUserRecord<HInstruction*>(current_method)), |
| 6554 | method_handle_idx_(method_handle_idx), |
| 6555 | dex_file_(dex_file) { |
| 6556 | } |
| 6557 | |
| 6558 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6559 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6560 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6561 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6562 | } |
| 6563 | |
| 6564 | bool IsClonable() const OVERRIDE { return true; } |
| 6565 | |
| 6566 | uint16_t GetMethodHandleIndex() const { return method_handle_idx_; } |
| 6567 | |
| 6568 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6569 | |
| 6570 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6571 | return SideEffects::CanTriggerGC(); |
| 6572 | } |
| 6573 | |
| 6574 | DECLARE_INSTRUCTION(LoadMethodHandle); |
| 6575 | |
| 6576 | protected: |
| 6577 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodHandle); |
| 6578 | |
| 6579 | private: |
| 6580 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6581 | HUserRecord<HInstruction*> special_input_; |
| 6582 | |
| 6583 | const uint16_t method_handle_idx_; |
| 6584 | const DexFile& dex_file_; |
| 6585 | }; |
| 6586 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6587 | class HLoadMethodType FINAL : public HInstruction { |
| 6588 | public: |
| 6589 | HLoadMethodType(HCurrentMethod* current_method, |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6590 | dex::ProtoIndex proto_index, |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6591 | const DexFile& dex_file, |
| 6592 | uint32_t dex_pc) |
| 6593 | : HInstruction(kLoadMethodType, |
| 6594 | DataType::Type::kReference, |
| 6595 | SideEffectsForArchRuntimeCalls(), |
| 6596 | dex_pc), |
| 6597 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6598 | proto_index_(proto_index), |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6599 | dex_file_(dex_file) { |
| 6600 | } |
| 6601 | |
| 6602 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6603 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6604 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6605 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6606 | } |
| 6607 | |
| 6608 | bool IsClonable() const OVERRIDE { return true; } |
| 6609 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6610 | dex::ProtoIndex GetProtoIndex() const { return proto_index_; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6611 | |
| 6612 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6613 | |
| 6614 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6615 | return SideEffects::CanTriggerGC(); |
| 6616 | } |
| 6617 | |
| 6618 | DECLARE_INSTRUCTION(LoadMethodType); |
| 6619 | |
| 6620 | protected: |
| 6621 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodType); |
| 6622 | |
| 6623 | private: |
| 6624 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6625 | HUserRecord<HInstruction*> special_input_; |
| 6626 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6627 | const dex::ProtoIndex proto_index_; |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6628 | const DexFile& dex_file_; |
| 6629 | }; |
| 6630 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6631 | /** |
| 6632 | * Performs an initialization check on its Class object input. |
| 6633 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6634 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6635 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 6636 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 6637 | : HExpression( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6638 | kClinitCheck, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6639 | DataType::Type::kReference, |
Mingyao Yang | 217eb06 | 2017-12-11 15:20:07 -0800 | [diff] [blame] | 6640 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6641 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6642 | SetRawInputAt(0, constant); |
| 6643 | } |
| 6644 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6645 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6646 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6647 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6648 | return true; |
| 6649 | } |
| 6650 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6651 | bool NeedsEnvironment() const OVERRIDE { |
| 6652 | // May call runtime to initialize the class. |
| 6653 | return true; |
| 6654 | } |
| 6655 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 6656 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6657 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6658 | HLoadClass* GetLoadClass() const { |
| 6659 | DCHECK(InputAt(0)->IsLoadClass()); |
| 6660 | return InputAt(0)->AsLoadClass(); |
| 6661 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6662 | |
| 6663 | DECLARE_INSTRUCTION(ClinitCheck); |
| 6664 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6665 | |
| 6666 | protected: |
| 6667 | DEFAULT_COPY_CONSTRUCTOR(ClinitCheck); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6668 | }; |
| 6669 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6670 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6671 | public: |
| 6672 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6673 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6674 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6675 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6676 | bool is_volatile, |
| 6677 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6678 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6679 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6680 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6681 | : HExpression(kStaticFieldGet, |
| 6682 | field_type, |
| 6683 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 6684 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6685 | field_info_(field, |
| 6686 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6687 | field_type, |
| 6688 | is_volatile, |
| 6689 | field_idx, |
| 6690 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6691 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6692 | SetRawInputAt(0, cls); |
| 6693 | } |
| 6694 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6695 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6696 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 6697 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6698 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6699 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 6700 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6701 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6702 | } |
| 6703 | |
| 6704 | size_t ComputeHashCode() const OVERRIDE { |
| 6705 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6706 | } |
| 6707 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6708 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6709 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6710 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6711 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6712 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6713 | void SetType(DataType::Type new_type) { |
| 6714 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6715 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6716 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6717 | SetPackedField<TypeField>(new_type); |
| 6718 | } |
| 6719 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6720 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 6721 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6722 | protected: |
| 6723 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldGet); |
| 6724 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6725 | private: |
| 6726 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6727 | }; |
| 6728 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6729 | class HStaticFieldSet FINAL : public HExpression<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6730 | public: |
| 6731 | HStaticFieldSet(HInstruction* cls, |
| 6732 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6733 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6734 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6735 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6736 | bool is_volatile, |
| 6737 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6738 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6739 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6740 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6741 | : HExpression(kStaticFieldSet, |
| 6742 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 6743 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6744 | field_info_(field, |
| 6745 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6746 | field_type, |
| 6747 | is_volatile, |
| 6748 | field_idx, |
| 6749 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6750 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6751 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6752 | SetRawInputAt(0, cls); |
| 6753 | SetRawInputAt(1, value); |
| 6754 | } |
| 6755 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6756 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6757 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6758 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6759 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6760 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6761 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6762 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6763 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6764 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6765 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6766 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6767 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6768 | protected: |
| 6769 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldSet); |
| 6770 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6771 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6772 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6773 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6774 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6775 | "Too many packed fields."); |
| 6776 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6777 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6778 | }; |
| 6779 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6780 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6781 | public: |
| 6782 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6783 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6784 | uint32_t field_index, |
| 6785 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6786 | : HExpression(kUnresolvedInstanceFieldGet, |
| 6787 | field_type, |
| 6788 | SideEffects::AllExceptGCDependency(), |
| 6789 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6790 | field_index_(field_index) { |
| 6791 | SetRawInputAt(0, obj); |
| 6792 | } |
| 6793 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6794 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6795 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6796 | bool CanThrow() const OVERRIDE { return true; } |
| 6797 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6798 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6799 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6800 | |
| 6801 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6802 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6803 | protected: |
| 6804 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldGet); |
| 6805 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6806 | private: |
| 6807 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6808 | }; |
| 6809 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6810 | class HUnresolvedInstanceFieldSet FINAL : public HExpression<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6811 | public: |
| 6812 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6813 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6814 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6815 | uint32_t field_index, |
| 6816 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6817 | : HExpression(kUnresolvedInstanceFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6818 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6819 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6820 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6821 | SetRawInputAt(0, obj); |
| 6822 | SetRawInputAt(1, value); |
| 6823 | } |
| 6824 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6825 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6826 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6827 | bool CanThrow() const OVERRIDE { return true; } |
| 6828 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6829 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6830 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6831 | |
| 6832 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6833 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6834 | protected: |
| 6835 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldSet); |
| 6836 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6837 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6838 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6839 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6840 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6841 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6842 | kFieldFieldType + kFieldFieldTypeSize; |
| 6843 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6844 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6845 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6846 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6847 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6848 | }; |
| 6849 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6850 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6851 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6852 | HUnresolvedStaticFieldGet(DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6853 | uint32_t field_index, |
| 6854 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6855 | : HExpression(kUnresolvedStaticFieldGet, |
| 6856 | field_type, |
| 6857 | SideEffects::AllExceptGCDependency(), |
| 6858 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6859 | field_index_(field_index) { |
| 6860 | } |
| 6861 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6862 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6863 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6864 | bool CanThrow() const OVERRIDE { return true; } |
| 6865 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6866 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6867 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6868 | |
| 6869 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6870 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6871 | protected: |
| 6872 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldGet); |
| 6873 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6874 | private: |
| 6875 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6876 | }; |
| 6877 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6878 | class HUnresolvedStaticFieldSet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6879 | public: |
| 6880 | HUnresolvedStaticFieldSet(HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6881 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6882 | uint32_t field_index, |
| 6883 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6884 | : HExpression(kUnresolvedStaticFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6885 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6886 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6887 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6888 | SetRawInputAt(0, value); |
| 6889 | } |
| 6890 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6891 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6892 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6893 | bool CanThrow() const OVERRIDE { return true; } |
| 6894 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6895 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6896 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6897 | |
| 6898 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6899 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6900 | protected: |
| 6901 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldSet); |
| 6902 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6903 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6904 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6905 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6906 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6907 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6908 | kFieldFieldType + kFieldFieldTypeSize; |
| 6909 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6910 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6911 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6912 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6913 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6914 | }; |
| 6915 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6916 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6917 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6918 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6919 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6920 | : HExpression(kLoadException, DataType::Type::kReference, SideEffects::None(), dex_pc) { |
| 6921 | } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6922 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6923 | bool CanBeNull() const OVERRIDE { return false; } |
| 6924 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6925 | DECLARE_INSTRUCTION(LoadException); |
| 6926 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6927 | protected: |
| 6928 | DEFAULT_COPY_CONSTRUCTOR(LoadException); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6929 | }; |
| 6930 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6931 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6932 | // Must not be removed because the runtime expects the TLS to get cleared. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6933 | class HClearException FINAL : public HExpression<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6934 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6935 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6936 | : HExpression(kClearException, SideEffects::AllWrites(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6937 | } |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6938 | |
| 6939 | DECLARE_INSTRUCTION(ClearException); |
| 6940 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6941 | protected: |
| 6942 | DEFAULT_COPY_CONSTRUCTOR(ClearException); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6943 | }; |
| 6944 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6945 | class HThrow FINAL : public HExpression<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6946 | public: |
| 6947 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6948 | : HExpression(kThrow, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6949 | SetRawInputAt(0, exception); |
| 6950 | } |
| 6951 | |
| 6952 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6953 | |
| 6954 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6955 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6956 | bool CanThrow() const OVERRIDE { return true; } |
| 6957 | |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 6958 | bool AlwaysThrows() const OVERRIDE { return true; } |
| 6959 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6960 | DECLARE_INSTRUCTION(Throw); |
| 6961 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6962 | protected: |
| 6963 | DEFAULT_COPY_CONSTRUCTOR(Throw); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6964 | }; |
| 6965 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6966 | /** |
| 6967 | * Implementation strategies for the code generator of a HInstanceOf |
| 6968 | * or `HCheckCast`. |
| 6969 | */ |
| 6970 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6971 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6972 | kExactCheck, // Can do a single class compare. |
| 6973 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6974 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6975 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6976 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6977 | kArrayCheck, // No optimization yet when checking against a generic array. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6978 | kBitstringCheck, // Compare the type check bitstring. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6979 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6980 | }; |
| 6981 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6982 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6983 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6984 | // Note: HTypeCheckInstruction is just a helper class, not an abstract instruction with an |
| 6985 | // `IsTypeCheckInstruction()`. (New virtual methods in the HInstruction class have a high cost.) |
| 6986 | class HTypeCheckInstruction : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6987 | public: |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6988 | HTypeCheckInstruction(InstructionKind kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6989 | DataType::Type type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6990 | HInstruction* object, |
| 6991 | HInstruction* target_class_or_null, |
| 6992 | TypeCheckKind check_kind, |
| 6993 | Handle<mirror::Class> klass, |
| 6994 | uint32_t dex_pc, |
| 6995 | ArenaAllocator* allocator, |
| 6996 | HIntConstant* bitstring_path_to_root, |
| 6997 | HIntConstant* bitstring_mask, |
| 6998 | SideEffects side_effects) |
| 6999 | : HVariableInputSizeInstruction( |
| 7000 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7001 | type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7002 | side_effects, |
| 7003 | dex_pc, |
| 7004 | allocator, |
| 7005 | /* number_of_inputs */ check_kind == TypeCheckKind::kBitstringCheck ? 4u : 2u, |
| 7006 | kArenaAllocTypeCheckInputs), |
| 7007 | klass_(klass) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7008 | SetPackedField<TypeCheckKindField>(check_kind); |
| 7009 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7010 | SetPackedFlag<kFlagValidTargetClassRTI>(false); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7011 | SetRawInputAt(0, object); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7012 | SetRawInputAt(1, target_class_or_null); |
| 7013 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_path_to_root != nullptr); |
| 7014 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_mask != nullptr); |
| 7015 | if (check_kind == TypeCheckKind::kBitstringCheck) { |
| 7016 | DCHECK(target_class_or_null->IsNullConstant()); |
| 7017 | SetRawInputAt(2, bitstring_path_to_root); |
| 7018 | SetRawInputAt(3, bitstring_mask); |
| 7019 | } else { |
| 7020 | DCHECK(target_class_or_null->IsLoadClass()); |
| 7021 | } |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7022 | } |
| 7023 | |
| 7024 | HLoadClass* GetTargetClass() const { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7025 | DCHECK_NE(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7026 | HInstruction* load_class = InputAt(1); |
| 7027 | DCHECK(load_class->IsLoadClass()); |
| 7028 | return load_class->AsLoadClass(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7029 | } |
| 7030 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7031 | uint32_t GetBitstringPathToRoot() const { |
| 7032 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7033 | HInstruction* path_to_root = InputAt(2); |
| 7034 | DCHECK(path_to_root->IsIntConstant()); |
| 7035 | return static_cast<uint32_t>(path_to_root->AsIntConstant()->GetValue()); |
| 7036 | } |
| 7037 | |
| 7038 | uint32_t GetBitstringMask() const { |
| 7039 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7040 | HInstruction* mask = InputAt(3); |
| 7041 | DCHECK(mask->IsIntConstant()); |
| 7042 | return static_cast<uint32_t>(mask->AsIntConstant()->GetValue()); |
| 7043 | } |
| 7044 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7045 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7046 | bool CanBeMoved() const OVERRIDE { return true; } |
| 7047 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7048 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 7049 | DCHECK(other->IsInstanceOf() || other->IsCheckCast()) << other->DebugName(); |
| 7050 | return GetPackedFields() == down_cast<const HTypeCheckInstruction*>(other)->GetPackedFields(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7051 | } |
| 7052 | |
Andreas Gampe | 3fbd3ad | 2018-03-26 21:14:46 +0000 | [diff] [blame] | 7053 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 7054 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 7055 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 7056 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
| 7057 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7058 | ReferenceTypeInfo GetTargetClassRTI() { |
| 7059 | if (GetPackedFlag<kFlagValidTargetClassRTI>()) { |
| 7060 | // Note: The is_exact flag from the return value should not be used. |
| 7061 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact */ true); |
| 7062 | } else { |
| 7063 | return ReferenceTypeInfo::CreateInvalid(); |
| 7064 | } |
| 7065 | } |
| 7066 | |
| 7067 | // Target class RTI is marked as valid by RTP if the klass_ is admissible. |
| 7068 | void SetValidTargetClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 7069 | DCHECK(klass_ != nullptr); |
| 7070 | SetPackedFlag<kFlagValidTargetClassRTI>(true); |
| 7071 | } |
| 7072 | |
| 7073 | Handle<mirror::Class> GetClass() const { |
| 7074 | return klass_; |
| 7075 | } |
| 7076 | |
| 7077 | protected: |
| 7078 | DEFAULT_COPY_CONSTRUCTOR(TypeCheckInstruction); |
| 7079 | |
| 7080 | private: |
| 7081 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 7082 | static constexpr size_t kFieldTypeCheckKindSize = |
| 7083 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 7084 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 7085 | static constexpr size_t kFlagValidTargetClassRTI = kFlagMustDoNullCheck + 1; |
| 7086 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagValidTargetClassRTI + 1; |
| 7087 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7088 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
| 7089 | |
| 7090 | Handle<mirror::Class> klass_; |
| 7091 | }; |
| 7092 | |
| 7093 | class HInstanceOf FINAL : public HTypeCheckInstruction { |
| 7094 | public: |
| 7095 | HInstanceOf(HInstruction* object, |
| 7096 | HInstruction* target_class_or_null, |
| 7097 | TypeCheckKind check_kind, |
| 7098 | Handle<mirror::Class> klass, |
| 7099 | uint32_t dex_pc, |
| 7100 | ArenaAllocator* allocator, |
| 7101 | HIntConstant* bitstring_path_to_root, |
| 7102 | HIntConstant* bitstring_mask) |
| 7103 | : HTypeCheckInstruction(kInstanceOf, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7104 | DataType::Type::kBool, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7105 | object, |
| 7106 | target_class_or_null, |
| 7107 | check_kind, |
| 7108 | klass, |
| 7109 | dex_pc, |
| 7110 | allocator, |
| 7111 | bitstring_path_to_root, |
| 7112 | bitstring_mask, |
| 7113 | SideEffectsForArchRuntimeCalls(check_kind)) {} |
| 7114 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7115 | bool NeedsEnvironment() const OVERRIDE { |
| 7116 | return CanCallRuntime(GetTypeCheckKind()); |
| 7117 | } |
| 7118 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7119 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 7120 | // Mips currently does runtime calls for any other checks. |
| 7121 | return check_kind != TypeCheckKind::kExactCheck; |
| 7122 | } |
| 7123 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7124 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7125 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7126 | } |
| 7127 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7128 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7129 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7130 | protected: |
| 7131 | DEFAULT_COPY_CONSTRUCTOR(InstanceOf); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7132 | }; |
| 7133 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 7134 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7135 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 7136 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7137 | : HExpression(kBoundType, DataType::Type::kReference, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7138 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 7139 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 7140 | SetPackedFlag<kFlagCanBeNull>(true); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7141 | DCHECK_EQ(input->GetType(), DataType::Type::kReference); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7142 | SetRawInputAt(0, input); |
| 7143 | } |
| 7144 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7145 | bool IsClonable() const OVERRIDE { return true; } |
| 7146 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7147 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7148 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7149 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7150 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7151 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7152 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7153 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 7154 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7155 | } |
| 7156 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7157 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7158 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7159 | DECLARE_INSTRUCTION(BoundType); |
| 7160 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7161 | protected: |
| 7162 | DEFAULT_COPY_CONSTRUCTOR(BoundType); |
| 7163 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7164 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7165 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 7166 | // is false then CanBeNull() cannot be true). |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7167 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7168 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 7169 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 7170 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7171 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7172 | // 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] | 7173 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 7174 | // It is used to bound the type in cases like: |
| 7175 | // if (x instanceof ClassX) { |
| 7176 | // // uper_bound_ will be ClassX |
| 7177 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7178 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7179 | }; |
| 7180 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7181 | class HCheckCast FINAL : public HTypeCheckInstruction { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7182 | public: |
| 7183 | HCheckCast(HInstruction* object, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7184 | HInstruction* target_class_or_null, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7185 | TypeCheckKind check_kind, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7186 | Handle<mirror::Class> klass, |
| 7187 | uint32_t dex_pc, |
| 7188 | ArenaAllocator* allocator, |
| 7189 | HIntConstant* bitstring_path_to_root, |
| 7190 | HIntConstant* bitstring_mask) |
| 7191 | : HTypeCheckInstruction(kCheckCast, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7192 | DataType::Type::kVoid, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7193 | object, |
| 7194 | target_class_or_null, |
| 7195 | check_kind, |
| 7196 | klass, |
| 7197 | dex_pc, |
| 7198 | allocator, |
| 7199 | bitstring_path_to_root, |
| 7200 | bitstring_mask, |
| 7201 | SideEffects::CanTriggerGC()) {} |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7202 | |
| 7203 | bool NeedsEnvironment() const OVERRIDE { |
| 7204 | // Instruction may throw a CheckCastError. |
| 7205 | return true; |
| 7206 | } |
| 7207 | |
| 7208 | bool CanThrow() const OVERRIDE { return true; } |
| 7209 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7210 | DECLARE_INSTRUCTION(CheckCast); |
| 7211 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7212 | protected: |
| 7213 | DEFAULT_COPY_CONSTRUCTOR(CheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7214 | }; |
| 7215 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 7216 | /** |
| 7217 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 7218 | * @details We define the combined barrier types that are actually required |
| 7219 | * by the Java Memory Model, rather than using exactly the terminology from |
| 7220 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 7221 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 7222 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 7223 | * The current recipe is as follows: |
| 7224 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 7225 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 7226 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 7227 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 7228 | * class has final fields. |
| 7229 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 7230 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 7231 | */ |
| 7232 | enum MemBarrierKind { |
| 7233 | kAnyStore, |
| 7234 | kLoadAny, |
| 7235 | kStoreStore, |
| 7236 | kAnyAny, |
| 7237 | kNTStoreStore, |
| 7238 | kLastBarrierKind = kNTStoreStore |
| 7239 | }; |
| 7240 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 7241 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7242 | class HMemoryBarrier FINAL : public HExpression<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7243 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7244 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7245 | : HExpression(kMemoryBarrier, |
| 7246 | SideEffects::AllWritesAndReads(), // Assume write/read on all fields/arrays. |
| 7247 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7248 | SetPackedField<BarrierKindField>(barrier_kind); |
| 7249 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7250 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7251 | bool IsClonable() const OVERRIDE { return true; } |
| 7252 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7253 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7254 | |
| 7255 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 7256 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7257 | protected: |
| 7258 | DEFAULT_COPY_CONSTRUCTOR(MemoryBarrier); |
| 7259 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7260 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7261 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 7262 | static constexpr size_t kFieldBarrierKindSize = |
| 7263 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 7264 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 7265 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 7266 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 7267 | "Too many packed fields."); |
| 7268 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7269 | }; |
| 7270 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7271 | // A constructor fence orders all prior stores to fields that could be accessed via a final field of |
| 7272 | // the specified object(s), with respect to any subsequent store that might "publish" |
| 7273 | // (i.e. make visible) the specified object to another thread. |
| 7274 | // |
| 7275 | // JLS 17.5.1 "Semantics of final fields" states that a freeze action happens |
| 7276 | // for all final fields (that were set) at the end of the invoked constructor. |
| 7277 | // |
| 7278 | // The constructor fence models the freeze actions for the final fields of an object |
| 7279 | // being constructed (semantically at the end of the constructor). Constructor fences |
| 7280 | // have a per-object affinity; two separate objects being constructed get two separate |
| 7281 | // constructor fences. |
| 7282 | // |
| 7283 | // (Note: that if calling a super-constructor or forwarding to another constructor, |
| 7284 | // the freezes would happen at the end of *that* constructor being invoked). |
| 7285 | // |
| 7286 | // The memory model guarantees that when the object being constructed is "published" after |
| 7287 | // constructor completion (i.e. escapes the current thread via a store), then any final field |
| 7288 | // writes must be observable on other threads (once they observe that publication). |
| 7289 | // |
| 7290 | // Further, anything written before the freeze, and read by dereferencing through the final field, |
| 7291 | // must also be visible (so final object field could itself have an object with non-final fields; |
| 7292 | // yet the freeze must also extend to them). |
| 7293 | // |
| 7294 | // Constructor example: |
| 7295 | // |
| 7296 | // class HasFinal { |
| 7297 | // final int field; Optimizing IR for <init>()V: |
| 7298 | // HasFinal() { |
| 7299 | // field = 123; HInstanceFieldSet(this, HasFinal.field, 123) |
| 7300 | // // freeze(this.field); HConstructorFence(this) |
| 7301 | // } HReturn |
| 7302 | // } |
| 7303 | // |
| 7304 | // HConstructorFence can serve double duty as a fence for new-instance/new-array allocations of |
| 7305 | // already-initialized classes; in that case the allocation must act as a "default-initializer" |
| 7306 | // of the object which effectively writes the class pointer "final field". |
| 7307 | // |
| 7308 | // For example, we can model default-initialiation as roughly the equivalent of the following: |
| 7309 | // |
| 7310 | // class Object { |
| 7311 | // private final Class header; |
| 7312 | // } |
| 7313 | // |
| 7314 | // Java code: Optimizing IR: |
| 7315 | // |
| 7316 | // T new_instance<T>() { |
| 7317 | // Object obj = allocate_memory(T.class.size); obj = HInvoke(art_quick_alloc_object, T) |
| 7318 | // obj.header = T.class; // header write is done by above call. |
| 7319 | // // freeze(obj.header) HConstructorFence(obj) |
| 7320 | // return (T)obj; |
| 7321 | // } |
| 7322 | // |
| 7323 | // See also: |
| 7324 | // * CompilerDriver::RequiresConstructorBarrier |
| 7325 | // * QuasiAtomic::ThreadFenceForConstructor |
| 7326 | // |
| 7327 | class HConstructorFence FINAL : public HVariableInputSizeInstruction { |
| 7328 | // A fence has variable inputs because the inputs can be removed |
| 7329 | // after prepare_for_register_allocation phase. |
| 7330 | // (TODO: In the future a fence could freeze multiple objects |
| 7331 | // after merging two fences together.) |
| 7332 | public: |
| 7333 | // `fence_object` is the reference that needs to be protected for correct publication. |
| 7334 | // |
| 7335 | // It makes sense in the following situations: |
| 7336 | // * <init> constructors, it's the "this" parameter (i.e. HParameterValue, s.t. IsThis() == true). |
| 7337 | // * new-instance-like instructions, it's the return value (i.e. HNewInstance). |
| 7338 | // |
| 7339 | // After construction the `fence_object` becomes the 0th input. |
| 7340 | // This is not an input in a real sense, but just a convenient place to stash the information |
| 7341 | // about the associated object. |
| 7342 | HConstructorFence(HInstruction* fence_object, |
| 7343 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7344 | ArenaAllocator* allocator) |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7345 | // We strongly suspect there is not a more accurate way to describe the fine-grained reordering |
| 7346 | // constraints described in the class header. We claim that these SideEffects constraints |
| 7347 | // enforce a superset of the real constraints. |
| 7348 | // |
| 7349 | // The ordering described above is conservatively modeled with SideEffects as follows: |
| 7350 | // |
| 7351 | // * To prevent reordering of the publication stores: |
| 7352 | // ----> "Reads of objects" is the initial SideEffect. |
| 7353 | // * For every primitive final field store in the constructor: |
| 7354 | // ----> Union that field's type as a read (e.g. "Read of T") into the SideEffect. |
| 7355 | // * If there are any stores to reference final fields in the constructor: |
| 7356 | // ----> Use a more conservative "AllReads" SideEffect because any stores to any references |
| 7357 | // that are reachable from `fence_object` also need to be prevented for reordering |
| 7358 | // (and we do not want to do alias analysis to figure out what those stores are). |
| 7359 | // |
| 7360 | // In the implementation, this initially starts out as an "all reads" side effect; this is an |
| 7361 | // even more conservative approach than the one described above, and prevents all of the |
| 7362 | // above reordering without analyzing any of the instructions in the constructor. |
| 7363 | // |
| 7364 | // If in a later phase we discover that there are no writes to reference final fields, |
| 7365 | // 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] | 7366 | : HVariableInputSizeInstruction(kConstructorFence, |
| 7367 | SideEffects::AllReads(), |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7368 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7369 | allocator, |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7370 | /* number_of_inputs */ 1, |
| 7371 | kArenaAllocConstructorFenceInputs) { |
| 7372 | DCHECK(fence_object != nullptr); |
| 7373 | SetRawInputAt(0, fence_object); |
| 7374 | } |
| 7375 | |
| 7376 | // The object associated with this constructor fence. |
| 7377 | // |
| 7378 | // (Note: This will be null after the prepare_for_register_allocation phase, |
| 7379 | // as all constructor fence inputs are removed there). |
| 7380 | HInstruction* GetFenceObject() const { |
| 7381 | return InputAt(0); |
| 7382 | } |
| 7383 | |
| 7384 | // Find all the HConstructorFence uses (`fence_use`) for `this` and: |
| 7385 | // - Delete `fence_use` from `this`'s use list. |
| 7386 | // - Delete `this` from `fence_use`'s inputs list. |
| 7387 | // - If the `fence_use` is dead, remove it from the graph. |
| 7388 | // |
| 7389 | // A fence is considered dead once it no longer has any uses |
| 7390 | // and all of the inputs are dead. |
| 7391 | // |
| 7392 | // This must *not* be called during/after prepare_for_register_allocation, |
| 7393 | // because that removes all the inputs to the fences but the fence is actually |
| 7394 | // still considered live. |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7395 | // |
| 7396 | // Returns how many HConstructorFence instructions were removed from graph. |
| 7397 | static size_t RemoveConstructorFences(HInstruction* instruction); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7398 | |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7399 | // Combine all inputs of `this` and `other` instruction and remove |
| 7400 | // `other` from the graph. |
| 7401 | // |
| 7402 | // Inputs are unique after the merge. |
| 7403 | // |
| 7404 | // Requirement: `this` must not be the same as `other. |
| 7405 | void Merge(HConstructorFence* other); |
| 7406 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7407 | // Check if this constructor fence is protecting |
| 7408 | // an HNewInstance or HNewArray that is also the immediate |
| 7409 | // predecessor of `this`. |
| 7410 | // |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7411 | // If `ignore_inputs` is true, then the immediate predecessor doesn't need |
| 7412 | // to be one of the inputs of `this`. |
| 7413 | // |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7414 | // Returns the associated HNewArray or HNewInstance, |
| 7415 | // or null otherwise. |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7416 | HInstruction* GetAssociatedAllocation(bool ignore_inputs = false); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7417 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7418 | DECLARE_INSTRUCTION(ConstructorFence); |
| 7419 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7420 | protected: |
| 7421 | DEFAULT_COPY_CONSTRUCTOR(ConstructorFence); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7422 | }; |
| 7423 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7424 | class HMonitorOperation FINAL : public HExpression<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7425 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7426 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7427 | kEnter, |
| 7428 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7429 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7430 | }; |
| 7431 | |
| 7432 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7433 | : HExpression(kMonitorOperation, |
| 7434 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 7435 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7436 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7437 | SetRawInputAt(0, object); |
| 7438 | } |
| 7439 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7440 | // Instruction may go into runtime, so we need an environment. |
| 7441 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 7442 | |
| 7443 | bool CanThrow() const OVERRIDE { |
| 7444 | // Verifier guarantees that monitor-exit cannot throw. |
| 7445 | // This is important because it allows the HGraphBuilder to remove |
| 7446 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 7447 | return IsEnter(); |
| 7448 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7449 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7450 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 7451 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7452 | |
| 7453 | DECLARE_INSTRUCTION(MonitorOperation); |
| 7454 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7455 | protected: |
| 7456 | DEFAULT_COPY_CONSTRUCTOR(MonitorOperation); |
| 7457 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7458 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7459 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 7460 | static constexpr size_t kFieldOperationKindSize = |
| 7461 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 7462 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 7463 | kFieldOperationKind + kFieldOperationKindSize; |
| 7464 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7465 | "Too many packed fields."); |
| 7466 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7467 | }; |
| 7468 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 7469 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7470 | public: |
| 7471 | HSelect(HInstruction* condition, |
| 7472 | HInstruction* true_value, |
| 7473 | HInstruction* false_value, |
| 7474 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7475 | : HExpression(kSelect, HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7476 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 7477 | |
| 7478 | // First input must be `true_value` or `false_value` to allow codegens to |
| 7479 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 7480 | // that architectures which implement HSelect as a conditional move also |
| 7481 | // will not need to invert the condition. |
| 7482 | SetRawInputAt(0, false_value); |
| 7483 | SetRawInputAt(1, true_value); |
| 7484 | SetRawInputAt(2, condition); |
| 7485 | } |
| 7486 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7487 | bool IsClonable() const OVERRIDE { return true; } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7488 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 7489 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 7490 | HInstruction* GetCondition() const { return InputAt(2); } |
| 7491 | |
| 7492 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7493 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 7494 | return true; |
| 7495 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7496 | |
| 7497 | bool CanBeNull() const OVERRIDE { |
| 7498 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 7499 | } |
| 7500 | |
| 7501 | DECLARE_INSTRUCTION(Select); |
| 7502 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7503 | protected: |
| 7504 | DEFAULT_COPY_CONSTRUCTOR(Select); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7505 | }; |
| 7506 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 7507 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7508 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7509 | MoveOperands(Location source, |
| 7510 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7511 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7512 | HInstruction* instruction) |
| 7513 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7514 | |
| 7515 | Location GetSource() const { return source_; } |
| 7516 | Location GetDestination() const { return destination_; } |
| 7517 | |
| 7518 | void SetSource(Location value) { source_ = value; } |
| 7519 | void SetDestination(Location value) { destination_ = value; } |
| 7520 | |
| 7521 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 7522 | // destination (but not the source). |
| 7523 | Location MarkPending() { |
| 7524 | DCHECK(!IsPending()); |
| 7525 | Location dest = destination_; |
| 7526 | destination_ = Location::NoLocation(); |
| 7527 | return dest; |
| 7528 | } |
| 7529 | |
| 7530 | void ClearPending(Location dest) { |
| 7531 | DCHECK(IsPending()); |
| 7532 | destination_ = dest; |
| 7533 | } |
| 7534 | |
| 7535 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7536 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 7537 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7538 | } |
| 7539 | |
| 7540 | // True if this blocks a move from the given location. |
| 7541 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 7542 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7543 | } |
| 7544 | |
| 7545 | // A move is redundant if it's been eliminated, if its source and |
| 7546 | // destination are the same, or if its destination is unneeded. |
| 7547 | bool IsRedundant() const { |
| 7548 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 7549 | } |
| 7550 | |
| 7551 | // We clear both operands to indicate move that's been eliminated. |
| 7552 | void Eliminate() { |
| 7553 | source_ = destination_ = Location::NoLocation(); |
| 7554 | } |
| 7555 | |
| 7556 | bool IsEliminated() const { |
| 7557 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 7558 | return source_.IsInvalid(); |
| 7559 | } |
| 7560 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7561 | DataType::Type GetType() const { return type_; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7562 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7563 | bool Is64BitMove() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7564 | return DataType::Is64BitType(type_); |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7565 | } |
| 7566 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7567 | HInstruction* GetInstruction() const { return instruction_; } |
| 7568 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7569 | private: |
| 7570 | Location source_; |
| 7571 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7572 | // The type this move is for. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7573 | DataType::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7574 | // The instruction this move is assocatied with. Null when this move is |
| 7575 | // for moving an input in the expected locations of user (including a phi user). |
| 7576 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 7577 | // in the same parallel move. |
| 7578 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7579 | }; |
| 7580 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7581 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 7582 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7583 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 7584 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7585 | class HParallelMove FINAL : public HExpression<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7586 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7587 | explicit HParallelMove(ArenaAllocator* allocator, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7588 | : HExpression(kParallelMove, SideEffects::None(), dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7589 | moves_(allocator->Adapter(kArenaAllocMoveOperands)) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7590 | moves_.reserve(kDefaultNumberOfMoves); |
| 7591 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7592 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7593 | void AddMove(Location source, |
| 7594 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7595 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7596 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 7597 | DCHECK(source.IsValid()); |
| 7598 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7599 | if (kIsDebugBuild) { |
| 7600 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7601 | for (const MoveOperands& move : moves_) { |
| 7602 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7603 | // Special case the situation where the move is for the spill slot |
| 7604 | // of the instruction. |
| 7605 | if ((GetPrevious() == instruction) |
| 7606 | || ((GetPrevious() == nullptr) |
| 7607 | && instruction->IsPhi() |
| 7608 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7609 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7610 | << "Doing parallel moves for the same instruction."; |
| 7611 | } else { |
| 7612 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 7613 | } |
| 7614 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 7615 | } |
| 7616 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7617 | for (const MoveOperands& move : moves_) { |
| 7618 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7619 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7620 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7621 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7622 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7623 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7624 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7625 | } |
| 7626 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7627 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7628 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7629 | } |
| 7630 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7631 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7632 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 7633 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7634 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7635 | protected: |
| 7636 | DEFAULT_COPY_CONSTRUCTOR(ParallelMove); |
| 7637 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7638 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7639 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7640 | }; |
| 7641 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7642 | // This instruction computes an intermediate address pointing in the 'middle' of an object. The |
| 7643 | // result pointer cannot be handled by GC, so extra care is taken to make sure that this value is |
| 7644 | // never used across anything that can trigger GC. |
| 7645 | // The result of this instruction is not a pointer in the sense of `DataType::Type::kreference`. |
| 7646 | // So we represent it by the type `DataType::Type::kInt`. |
| 7647 | class HIntermediateAddress FINAL : public HExpression<2> { |
| 7648 | public: |
| 7649 | HIntermediateAddress(HInstruction* base_address, HInstruction* offset, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7650 | : HExpression(kIntermediateAddress, |
| 7651 | DataType::Type::kInt32, |
| 7652 | SideEffects::DependsOnGC(), |
| 7653 | dex_pc) { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7654 | DCHECK_EQ(DataType::Size(DataType::Type::kInt32), |
| 7655 | DataType::Size(DataType::Type::kReference)) |
| 7656 | << "kPrimInt and kPrimNot have different sizes."; |
| 7657 | SetRawInputAt(0, base_address); |
| 7658 | SetRawInputAt(1, offset); |
| 7659 | } |
| 7660 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7661 | bool IsClonable() const OVERRIDE { return true; } |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7662 | bool CanBeMoved() const OVERRIDE { return true; } |
| 7663 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 7664 | return true; |
| 7665 | } |
| 7666 | bool IsActualObject() const OVERRIDE { return false; } |
| 7667 | |
| 7668 | HInstruction* GetBaseAddress() const { return InputAt(0); } |
| 7669 | HInstruction* GetOffset() const { return InputAt(1); } |
| 7670 | |
| 7671 | DECLARE_INSTRUCTION(IntermediateAddress); |
| 7672 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7673 | protected: |
| 7674 | DEFAULT_COPY_CONSTRUCTOR(IntermediateAddress); |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7675 | }; |
| 7676 | |
| 7677 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7678 | } // namespace art |
| 7679 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 7680 | #include "nodes_vector.h" |
| 7681 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7682 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 7683 | #include "nodes_shared.h" |
| 7684 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7685 | #ifdef ART_ENABLE_CODEGEN_mips |
| 7686 | #include "nodes_mips.h" |
| 7687 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7688 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 7689 | #include "nodes_x86.h" |
| 7690 | #endif |
| 7691 | |
| 7692 | namespace art { |
| 7693 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7694 | class OptimizingCompilerStats; |
| 7695 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7696 | class HGraphVisitor : public ValueObject { |
| 7697 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7698 | explicit HGraphVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7699 | : stats_(stats), |
| 7700 | graph_(graph) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 7701 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7702 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7703 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7704 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 7705 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7706 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7707 | void VisitInsertionOrder(); |
| 7708 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7709 | // Visit the graph following dominator tree reverse post-order. |
| 7710 | void VisitReversePostOrder(); |
| 7711 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 7712 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7713 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7714 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7715 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7716 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 7717 | |
| 7718 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7719 | |
| 7720 | #undef DECLARE_VISIT_INSTRUCTION |
| 7721 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7722 | protected: |
| 7723 | OptimizingCompilerStats* stats_; |
| 7724 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7725 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 7726 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7727 | |
| 7728 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 7729 | }; |
| 7730 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7731 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 7732 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7733 | explicit HGraphDelegateVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7734 | : HGraphVisitor(graph, stats) {} |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7735 | virtual ~HGraphDelegateVisitor() {} |
| 7736 | |
| 7737 | // Visit functions that delegate to to super class. |
| 7738 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 7739 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7740 | |
| 7741 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7742 | |
| 7743 | #undef DECLARE_VISIT_INSTRUCTION |
| 7744 | |
| 7745 | private: |
| 7746 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 7747 | }; |
| 7748 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7749 | // Create a clone of the instruction, insert it into the graph; replace the old one with a new |
| 7750 | // and remove the old instruction. |
| 7751 | HInstruction* ReplaceInstrOrPhiByClone(HInstruction* instr); |
| 7752 | |
| 7753 | // Create a clone for each clonable instructions/phis and replace the original with the clone. |
| 7754 | // |
| 7755 | // Used for testing individual instruction cloner. |
| 7756 | class CloneAndReplaceInstructionVisitor : public HGraphDelegateVisitor { |
| 7757 | public: |
| 7758 | explicit CloneAndReplaceInstructionVisitor(HGraph* graph) |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7759 | : HGraphDelegateVisitor(graph), instr_replaced_by_clones_count_(0) {} |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7760 | |
| 7761 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 7762 | if (instruction->IsClonable()) { |
| 7763 | ReplaceInstrOrPhiByClone(instruction); |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7764 | instr_replaced_by_clones_count_++; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7765 | } |
| 7766 | } |
| 7767 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7768 | size_t GetInstrReplacedByClonesCount() const { return instr_replaced_by_clones_count_; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7769 | |
| 7770 | private: |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7771 | size_t instr_replaced_by_clones_count_; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7772 | |
| 7773 | DISALLOW_COPY_AND_ASSIGN(CloneAndReplaceInstructionVisitor); |
| 7774 | }; |
| 7775 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7776 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7777 | // of an inner loop. The order in which the blocks are iterated is on their |
| 7778 | // block id. |
| 7779 | class HBlocksInLoopIterator : public ValueObject { |
| 7780 | public: |
| 7781 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 7782 | : blocks_in_loop_(info.GetBlocks()), |
| 7783 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 7784 | index_(0) { |
| 7785 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 7786 | Advance(); |
| 7787 | } |
| 7788 | } |
| 7789 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7790 | bool Done() const { return index_ == blocks_.size(); } |
| 7791 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7792 | void Advance() { |
| 7793 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7794 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7795 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 7796 | break; |
| 7797 | } |
| 7798 | } |
| 7799 | } |
| 7800 | |
| 7801 | private: |
| 7802 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7803 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7804 | size_t index_; |
| 7805 | |
| 7806 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 7807 | }; |
| 7808 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7809 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7810 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 7811 | // post order. |
| 7812 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 7813 | public: |
| 7814 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 7815 | : blocks_in_loop_(info.GetBlocks()), |
| 7816 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 7817 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7818 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7819 | Advance(); |
| 7820 | } |
| 7821 | } |
| 7822 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7823 | bool Done() const { return index_ == blocks_.size(); } |
| 7824 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7825 | void Advance() { |
| 7826 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7827 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 7828 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7829 | break; |
| 7830 | } |
| 7831 | } |
| 7832 | } |
| 7833 | |
| 7834 | private: |
| 7835 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7836 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7837 | size_t index_; |
| 7838 | |
| 7839 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 7840 | }; |
| 7841 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7842 | // Returns int64_t value of a properly typed constant. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7843 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7844 | if (constant->IsIntConstant()) { |
| 7845 | return constant->AsIntConstant()->GetValue(); |
| 7846 | } else if (constant->IsLongConstant()) { |
| 7847 | return constant->AsLongConstant()->GetValue(); |
| 7848 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 7849 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7850 | return 0; |
| 7851 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7852 | } |
| 7853 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7854 | // Returns true iff instruction is an integral constant (and sets value on success). |
| 7855 | inline bool IsInt64AndGet(HInstruction* instruction, /*out*/ int64_t* value) { |
| 7856 | if (instruction->IsIntConstant()) { |
| 7857 | *value = instruction->AsIntConstant()->GetValue(); |
| 7858 | return true; |
| 7859 | } else if (instruction->IsLongConstant()) { |
| 7860 | *value = instruction->AsLongConstant()->GetValue(); |
| 7861 | return true; |
| 7862 | } else if (instruction->IsNullConstant()) { |
| 7863 | *value = 0; |
| 7864 | return true; |
| 7865 | } |
| 7866 | return false; |
| 7867 | } |
| 7868 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 7869 | // Returns true iff instruction is the given integral constant. |
| 7870 | inline bool IsInt64Value(HInstruction* instruction, int64_t value) { |
| 7871 | int64_t val = 0; |
| 7872 | return IsInt64AndGet(instruction, &val) && val == value; |
| 7873 | } |
| 7874 | |
| 7875 | // Returns true iff instruction is a zero bit pattern. |
| 7876 | inline bool IsZeroBitPattern(HInstruction* instruction) { |
| 7877 | return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern(); |
| 7878 | } |
| 7879 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7880 | // Implement HInstruction::Is##type() for concrete instructions. |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7881 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7882 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } |
| 7883 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7884 | #undef INSTRUCTION_TYPE_CHECK |
| 7885 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7886 | // Implement HInstruction::Is##type() for abstract instructions. |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7887 | #define INSTRUCTION_TYPE_CHECK_RESULT(type, super) \ |
| 7888 | std::is_base_of<BaseType, H##type>::value, |
| 7889 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 7890 | inline bool HInstruction::Is##type() const { \ |
| 7891 | DCHECK_LT(GetKind(), kLastInstructionKind); \ |
| 7892 | using BaseType = H##type; \ |
| 7893 | static constexpr bool results[] = { \ |
| 7894 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK_RESULT) \ |
| 7895 | }; \ |
| 7896 | return results[static_cast<size_t>(GetKind())]; \ |
| 7897 | } |
| 7898 | |
| 7899 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7900 | #undef INSTRUCTION_TYPE_CHECK |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7901 | #undef INSTRUCTION_TYPE_CHECK_RESULT |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7902 | |
| 7903 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7904 | inline const H##type* HInstruction::As##type() const { \ |
| 7905 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 7906 | } \ |
| 7907 | inline H##type* HInstruction::As##type() { \ |
| 7908 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 7909 | } |
| 7910 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7911 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 7912 | #undef INSTRUCTION_TYPE_CAST |
| 7913 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7914 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 7915 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 7916 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 7917 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 7918 | size_t number_of_new_blocks, |
| 7919 | size_t after) { |
| 7920 | DCHECK_LT(after, blocks->size()); |
| 7921 | size_t old_size = blocks->size(); |
| 7922 | size_t new_size = old_size + number_of_new_blocks; |
| 7923 | blocks->resize(new_size); |
| 7924 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 7925 | } |
| 7926 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7927 | /* |
| 7928 | * Hunt "under the hood" of array lengths (leading to array references), |
| 7929 | * null checks (also leading to array references), and new arrays |
| 7930 | * (leading to the actual length). This makes it more likely related |
| 7931 | * instructions become actually comparable. |
| 7932 | */ |
| 7933 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 7934 | while (instruction->IsArrayLength() || |
| 7935 | instruction->IsNullCheck() || |
| 7936 | instruction->IsNewArray()) { |
| 7937 | instruction = instruction->IsNewArray() |
| 7938 | ? instruction->AsNewArray()->GetLength() |
| 7939 | : instruction->InputAt(0); |
| 7940 | } |
| 7941 | return instruction; |
| 7942 | } |
| 7943 | |
Artem Serov | 21c7e6f | 2017-07-27 16:04:42 +0100 | [diff] [blame] | 7944 | void RemoveEnvironmentUses(HInstruction* instruction); |
| 7945 | bool HasEnvironmentUsedByOthers(HInstruction* instruction); |
| 7946 | void ResetEnvironmentInputRecords(HInstruction* instruction); |
| 7947 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7948 | } // namespace art |
| 7949 | |
| 7950 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |