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" |
Andreas Gampe | 7fbc4a5 | 2018-11-28 08:26:47 -0800 | [diff] [blame] | 29 | #include "base/mutex.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 30 | #include "base/quasi_atomic.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 31 | #include "base/stl_util.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 32 | #include "base/transform_array_ref.h" |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 33 | #include "art_method.h" |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 34 | #include "data_type.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 35 | #include "deoptimization_kind.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 36 | #include "dex/dex_file.h" |
| 37 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 38 | #include "dex/invoke_type.h" |
David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 39 | #include "dex/method_reference.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 40 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 41 | #include "handle.h" |
| 42 | #include "handle_scope.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 43 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 44 | #include "locations.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 45 | #include "mirror/class.h" |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 46 | #include "mirror/method_type.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 47 | #include "offsets.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 48 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 49 | |
| 50 | namespace art { |
| 51 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 52 | class ArenaStack; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 53 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 54 | class HBasicBlock; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 55 | class HConstructorFence; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 56 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 57 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 58 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 59 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 60 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 61 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 62 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 63 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 64 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 65 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 66 | class HNullConstant; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 67 | class HParameterValue; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 68 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 69 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 70 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 71 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 72 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 73 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 74 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 75 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 76 | namespace mirror { |
| 77 | class DexCache; |
| 78 | } // namespace mirror |
| 79 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 80 | static const int kDefaultNumberOfBlocks = 8; |
| 81 | static const int kDefaultNumberOfSuccessors = 2; |
| 82 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 83 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 84 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 85 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 86 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 87 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 88 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 89 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 90 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 91 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 92 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 93 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 94 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 95 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 96 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 97 | static constexpr uint32_t kNoDexPc = -1; |
| 98 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 99 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 100 | // For the purposes of the compiler, the dex files must actually be the same object |
| 101 | // if we want to safely treat them as the same. This is especially important for JIT |
| 102 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 103 | // times and provide different class resolution but no two class loaders should ever |
| 104 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 105 | // all sorts of weird failures. |
| 106 | return &lhs == &rhs; |
| 107 | } |
| 108 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 109 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 110 | // All types. |
| 111 | kCondEQ, // == |
| 112 | kCondNE, // != |
| 113 | // Signed integers and floating-point numbers. |
| 114 | kCondLT, // < |
| 115 | kCondLE, // <= |
| 116 | kCondGT, // > |
| 117 | kCondGE, // >= |
| 118 | // Unsigned integers. |
| 119 | kCondB, // < |
| 120 | kCondBE, // <= |
| 121 | kCondA, // > |
| 122 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 123 | // First and last aliases. |
| 124 | kCondFirst = kCondEQ, |
| 125 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 128 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 129 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 130 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 131 | kAnalysisFailThrowCatchLoop, |
| 132 | kAnalysisFailAmbiguousArrayOp, |
Nicolas Geoffray | 0846a8f | 2018-09-12 15:21:07 +0100 | [diff] [blame] | 133 | kAnalysisFailIrreducibleLoopAndStringInit, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 134 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 137 | template <typename T> |
| 138 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 139 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 140 | } |
| 141 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 142 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 143 | public: |
| 144 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 145 | |
| 146 | void AddInstruction(HInstruction* instruction); |
| 147 | void RemoveInstruction(HInstruction* instruction); |
| 148 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 149 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 150 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 151 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 152 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 153 | // Return true if this list contains `instruction`. |
| 154 | bool Contains(HInstruction* instruction) const; |
| 155 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 156 | // Return true if `instruction1` is found before `instruction2` in |
| 157 | // this instruction list and false otherwise. Abort if none |
| 158 | // of these instructions is found. |
| 159 | bool FoundBefore(const HInstruction* instruction1, |
| 160 | const HInstruction* instruction2) const; |
| 161 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 162 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 163 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 164 | |
| 165 | // Update the block of all instructions to be `block`. |
| 166 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 167 | |
| 168 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 169 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 170 | void Add(const HInstructionList& instruction_list); |
| 171 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 172 | // Return the number of instructions in the list. This is an expensive operation. |
| 173 | size_t CountSize() const; |
| 174 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 175 | private: |
| 176 | HInstruction* first_instruction_; |
| 177 | HInstruction* last_instruction_; |
| 178 | |
| 179 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 180 | friend class HGraph; |
| 181 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 182 | friend class HInstructionIterator; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 183 | friend class HInstructionIteratorHandleChanges; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 184 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 185 | |
| 186 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 187 | }; |
| 188 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 189 | class ReferenceTypeInfo : ValueObject { |
| 190 | public: |
| 191 | typedef Handle<mirror::Class> TypeHandle; |
| 192 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 193 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 194 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 195 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 196 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 197 | } |
| 198 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 199 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 200 | return ReferenceTypeInfo(type_handle, is_exact); |
| 201 | } |
| 202 | |
| 203 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 204 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 205 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 206 | return handle.GetReference() != nullptr; |
| 207 | } |
| 208 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 209 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 210 | return IsValidHandle(type_handle_); |
| 211 | } |
| 212 | |
| 213 | bool IsExact() const { return is_exact_; } |
| 214 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 215 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 216 | DCHECK(IsValid()); |
| 217 | return GetTypeHandle()->IsObjectClass(); |
| 218 | } |
| 219 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 220 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 221 | DCHECK(IsValid()); |
| 222 | return GetTypeHandle()->IsStringClass(); |
| 223 | } |
| 224 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 225 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 226 | DCHECK(IsValid()); |
| 227 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 228 | } |
| 229 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 230 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 231 | DCHECK(IsValid()); |
| 232 | return GetTypeHandle()->IsInterface(); |
| 233 | } |
| 234 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 235 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 236 | DCHECK(IsValid()); |
| 237 | return GetTypeHandle()->IsArrayClass(); |
| 238 | } |
| 239 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 240 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 241 | DCHECK(IsValid()); |
| 242 | return GetTypeHandle()->IsPrimitiveArray(); |
| 243 | } |
| 244 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 245 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 246 | DCHECK(IsValid()); |
| 247 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 248 | } |
| 249 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 250 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 251 | DCHECK(IsValid()); |
| 252 | if (!IsExact()) return false; |
| 253 | if (!IsArrayClass()) return false; |
| 254 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 255 | } |
| 256 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 257 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 258 | DCHECK(IsValid()); |
| 259 | if (!IsExact()) return false; |
| 260 | if (!IsArrayClass()) return false; |
| 261 | if (!rti.IsArrayClass()) return false; |
| 262 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 263 | rti.GetTypeHandle()->GetComponentType()); |
| 264 | } |
| 265 | |
| 266 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 267 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 268 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 269 | DCHECK(IsValid()); |
| 270 | DCHECK(rti.IsValid()); |
| 271 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 272 | } |
| 273 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 274 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 275 | DCHECK(IsValid()); |
| 276 | DCHECK(rti.IsValid()); |
| 277 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 278 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 279 | } |
| 280 | |
| 281 | // Returns true if the type information provide the same amount of details. |
| 282 | // Note that it does not mean that the instructions have the same actual type |
| 283 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 284 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 285 | if (!IsValid() && !rti.IsValid()) { |
| 286 | // Invalid types are equal. |
| 287 | return true; |
| 288 | } |
| 289 | if (!IsValid() || !rti.IsValid()) { |
| 290 | // One is valid, the other not. |
| 291 | return false; |
| 292 | } |
| 293 | return IsExact() == rti.IsExact() |
| 294 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 295 | } |
| 296 | |
| 297 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 298 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 299 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 300 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 301 | |
| 302 | // The class of the object. |
| 303 | TypeHandle type_handle_; |
| 304 | // Whether or not the type is exact or a superclass of the actual type. |
| 305 | // Whether or not we have any information about this type. |
| 306 | bool is_exact_; |
| 307 | }; |
| 308 | |
| 309 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 310 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 311 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 312 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 313 | public: |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 314 | HGraph(ArenaAllocator* allocator, |
| 315 | ArenaStack* arena_stack, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 316 | const DexFile& dex_file, |
| 317 | uint32_t method_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 318 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 319 | InvokeType invoke_type = kInvalidInvokeType, |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 320 | bool dead_reference_safe = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 321 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 322 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 323 | int start_instruction_id = 0) |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 324 | : allocator_(allocator), |
| 325 | arena_stack_(arena_stack), |
| 326 | blocks_(allocator->Adapter(kArenaAllocBlockList)), |
| 327 | reverse_post_order_(allocator->Adapter(kArenaAllocReversePostOrder)), |
| 328 | linear_order_(allocator->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 329 | entry_block_(nullptr), |
| 330 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 331 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 332 | number_of_vregs_(0), |
| 333 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 334 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 335 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 336 | has_try_catch_(false), |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 337 | has_simd_(false), |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 338 | has_loops_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 339 | has_irreducible_loops_(false), |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 340 | dead_reference_safe_(dead_reference_safe), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 341 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 342 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 343 | dex_file_(dex_file), |
| 344 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 345 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 346 | in_ssa_form_(false), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 347 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 348 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 349 | cached_null_constant_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 350 | cached_int_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 351 | cached_float_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 352 | cached_long_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 353 | cached_double_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 354 | cached_current_method_(nullptr), |
Nicolas Geoffray | 53fec08 | 2017-03-27 12:56:16 +0100 | [diff] [blame] | 355 | art_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 356 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 357 | osr_(osr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 358 | cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 359 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 360 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 361 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 362 | // 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] | 363 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 364 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 365 | ArenaAllocator* GetAllocator() const { return allocator_; } |
| 366 | ArenaStack* GetArenaStack() const { return arena_stack_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 367 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 368 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 369 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 370 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 371 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 372 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 373 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 374 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 375 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 376 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 377 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 378 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 379 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 380 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 381 | void ComputeDominanceInformation(); |
| 382 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 383 | void ClearLoopInformation(); |
| 384 | void FindBackEdges(ArenaBitVector* visited); |
| 385 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 386 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 387 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 388 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 389 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 390 | // 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] | 391 | // 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] | 392 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 393 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 394 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 395 | // order and loop information. |
| 396 | void ComputeTryBlockInformation(); |
| 397 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 398 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 399 | // Returns the instruction to replace the invoke expression or null if the |
| 400 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 401 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 402 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 403 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 404 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 405 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 406 | // should be the new back edge. |
| 407 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 408 | HBasicBlock* reference, |
| 409 | bool replace_if_back_edge); |
| 410 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 411 | // Need to add a couple of blocks to test if the loop body is entered and |
| 412 | // put deoptimization instructions, etc. |
| 413 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 414 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 415 | // Adds a new loop directly after the loop with the given header and exit. |
| 416 | // Returns the new preheader. |
| 417 | HBasicBlock* TransformLoopForVectorization(HBasicBlock* header, |
| 418 | HBasicBlock* body, |
| 419 | HBasicBlock* exit); |
| 420 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 421 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 422 | // other blocks and has no instructions or phis. |
| 423 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 424 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 425 | // Splits the edge between `block` and `successor` while preserving the |
| 426 | // indices in the predecessor/successor lists. If there are multiple edges |
| 427 | // between the blocks, the lowest indices are used. |
| 428 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 429 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 430 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 431 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
Artem Serov | c73ee37 | 2017-07-31 15:08:40 +0100 | [diff] [blame] | 432 | void OrderLoopHeaderPredecessors(HBasicBlock* header); |
Artem Serov | 09faaea | 2017-12-07 14:36:01 +0000 | [diff] [blame] | 433 | |
| 434 | // Transform a loop into a format with a single preheader. |
| 435 | // |
| 436 | // Each phi in the header should be split: original one in the header should only hold |
| 437 | // inputs reachable from the back edges and a single input from the preheader. The newly created |
| 438 | // phi in the preheader should collate the inputs from the original multiple incoming blocks. |
| 439 | // |
| 440 | // Loops in the graph typically have a single preheader, so this method is used to "repair" loops |
| 441 | // that no longer have this property. |
| 442 | void TransformLoopToSinglePreheaderFormat(HBasicBlock* header); |
| 443 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 444 | void SimplifyLoop(HBasicBlock* header); |
| 445 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 446 | int32_t GetNextInstructionId() { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 447 | CHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 448 | return current_instruction_id_++; |
| 449 | } |
| 450 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 451 | int32_t GetCurrentInstructionId() const { |
| 452 | return current_instruction_id_; |
| 453 | } |
| 454 | |
| 455 | void SetCurrentInstructionId(int32_t id) { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 456 | CHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 457 | current_instruction_id_ = id; |
| 458 | } |
| 459 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 460 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 461 | return maximum_number_of_out_vregs_; |
| 462 | } |
| 463 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 464 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 465 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 466 | } |
| 467 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 468 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 469 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 470 | } |
| 471 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 472 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 473 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 474 | } |
| 475 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 476 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 477 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 478 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 479 | } |
| 480 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 481 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 482 | number_of_vregs_ = number_of_vregs; |
| 483 | } |
| 484 | |
| 485 | uint16_t GetNumberOfVRegs() const { |
| 486 | return number_of_vregs_; |
| 487 | } |
| 488 | |
| 489 | void SetNumberOfInVRegs(uint16_t value) { |
| 490 | number_of_in_vregs_ = value; |
| 491 | } |
| 492 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 493 | uint16_t GetNumberOfInVRegs() const { |
| 494 | return number_of_in_vregs_; |
| 495 | } |
| 496 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 497 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 498 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 499 | return number_of_vregs_ - number_of_in_vregs_; |
| 500 | } |
| 501 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 502 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 503 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 504 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 505 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 506 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 507 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 508 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 509 | } |
| 510 | |
| 511 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 512 | return ReverseRange(GetReversePostOrder()); |
| 513 | } |
| 514 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 515 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 516 | return linear_order_; |
| 517 | } |
| 518 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 519 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 520 | return ReverseRange(GetLinearOrder()); |
| 521 | } |
| 522 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 523 | bool HasBoundsChecks() const { |
| 524 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 525 | } |
| 526 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 527 | void SetHasBoundsChecks(bool value) { |
| 528 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 529 | } |
| 530 | |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 531 | // Is the code known to be robust against eliminating dead references |
| 532 | // and the effects of early finalization? |
| 533 | bool IsDeadReferenceSafe() const { return dead_reference_safe_; } |
| 534 | |
| 535 | void MarkDeadReferenceUnsafe() { dead_reference_safe_ = false; } |
| 536 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 537 | bool IsDebuggable() const { return debuggable_; } |
| 538 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 539 | // 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] | 540 | // already, it is created and inserted into the graph. This method is only for |
| 541 | // integral types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 542 | 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] | 543 | |
| 544 | // TODO: This is problematic for the consistency of reference type propagation |
| 545 | // because it can be created anytime after the pass and thus it will be left |
| 546 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 547 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 548 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 549 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 550 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 551 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 552 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 553 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 554 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 555 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 556 | 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] | 557 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 558 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 559 | 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] | 560 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 561 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 562 | HCurrentMethod* GetCurrentMethod(); |
| 563 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 564 | const DexFile& GetDexFile() const { |
| 565 | return dex_file_; |
| 566 | } |
| 567 | |
| 568 | uint32_t GetMethodIdx() const { |
| 569 | return method_idx_; |
| 570 | } |
| 571 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 572 | // Get the method name (without the signature), e.g. "<init>" |
| 573 | const char* GetMethodName() const; |
| 574 | |
| 575 | // Get the pretty method name (class + name + optionally signature). |
| 576 | std::string PrettyMethod(bool with_signature = true) const; |
| 577 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 578 | InvokeType GetInvokeType() const { |
| 579 | return invoke_type_; |
| 580 | } |
| 581 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 582 | InstructionSet GetInstructionSet() const { |
| 583 | return instruction_set_; |
| 584 | } |
| 585 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 586 | bool IsCompilingOsr() const { return osr_; } |
| 587 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 588 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 589 | return cha_single_implementation_list_; |
| 590 | } |
| 591 | |
| 592 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 593 | cha_single_implementation_list_.insert(method); |
| 594 | } |
| 595 | |
| 596 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 597 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 598 | } |
| 599 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 600 | bool HasTryCatch() const { return has_try_catch_; } |
| 601 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 602 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 603 | bool HasSIMD() const { return has_simd_; } |
| 604 | void SetHasSIMD(bool value) { has_simd_ = value; } |
| 605 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 606 | bool HasLoops() const { return has_loops_; } |
| 607 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 608 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 609 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 610 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 611 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 612 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 613 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 614 | |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 615 | // Returns an instruction with the opposite Boolean value from 'cond'. |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 616 | // The instruction has been inserted into the graph, either as a constant, or |
| 617 | // before cursor. |
| 618 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 619 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 620 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 621 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 622 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 623 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 624 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 625 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 626 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 627 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 628 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 629 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 630 | template <class InstructionType, typename ValueType> |
| 631 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 632 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 633 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 634 | // Try to find an existing constant of the given value. |
| 635 | InstructionType* constant = nullptr; |
| 636 | auto cached_constant = cache->find(value); |
| 637 | if (cached_constant != cache->end()) { |
| 638 | constant = cached_constant->second; |
| 639 | } |
| 640 | |
| 641 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 642 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 643 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 644 | constant = new (allocator_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 645 | cache->Overwrite(value, constant); |
| 646 | InsertConstant(constant); |
| 647 | } |
| 648 | return constant; |
| 649 | } |
| 650 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 651 | void InsertConstant(HConstant* instruction); |
| 652 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 653 | // Cache a float constant into the graph. This method should only be |
| 654 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 655 | void CacheFloatConstant(HFloatConstant* constant); |
| 656 | |
| 657 | // See CacheFloatConstant comment. |
| 658 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 659 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 660 | ArenaAllocator* const allocator_; |
| 661 | ArenaStack* const arena_stack_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 662 | |
| 663 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 664 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 665 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 666 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 667 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 668 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 669 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 670 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 671 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 672 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 673 | HBasicBlock* entry_block_; |
| 674 | HBasicBlock* exit_block_; |
| 675 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 676 | // 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] | 677 | uint16_t maximum_number_of_out_vregs_; |
| 678 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 679 | // The number of virtual registers in this method. Contains the parameters. |
| 680 | uint16_t number_of_vregs_; |
| 681 | |
| 682 | // The number of virtual registers used by parameters of this method. |
| 683 | uint16_t number_of_in_vregs_; |
| 684 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 685 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 686 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 687 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 688 | // Flag whether there are bounds checks in the graph. We can skip |
| 689 | // BCE if it's false. It's only best effort to keep it up to date in |
| 690 | // the presence of code elimination so there might be false positives. |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 691 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 692 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 693 | // Flag whether there are try/catch blocks in the graph. We will skip |
| 694 | // try/catch-related passes if it's false. It's only best effort to keep |
| 695 | // it up to date in the presence of code elimination so there might be |
| 696 | // false positives. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 697 | bool has_try_catch_; |
| 698 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 699 | // Flag whether SIMD instructions appear in the graph. If true, the |
| 700 | // code generators may have to be more careful spilling the wider |
| 701 | // contents of SIMD registers. |
| 702 | bool has_simd_; |
| 703 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 704 | // Flag whether there are any loops in the graph. We can skip loop |
| 705 | // optimization if it's false. It's only best effort to keep it up |
| 706 | // to date in the presence of code elimination so there might be false |
| 707 | // positives. |
| 708 | bool has_loops_; |
| 709 | |
| 710 | // Flag whether there are any irreducible loops in the graph. It's only |
| 711 | // best effort to keep it up to date in the presence of code elimination |
| 712 | // so there might be false positives. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 713 | bool has_irreducible_loops_; |
| 714 | |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 715 | // Is the code known to be robust against eliminating dead references |
| 716 | // and the effects of early finalization? If false, dead reference variables |
| 717 | // are kept if they might be visible to the garbage collector. |
| 718 | // Currently this means that the class was declared to be dead-reference-safe, |
| 719 | // the method accesses no reachability-sensitive fields or data, and the same |
| 720 | // is true for any methods that were inlined into the current one. |
| 721 | bool dead_reference_safe_; |
| 722 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 723 | // Indicates whether the graph should be compiled in a way that |
| 724 | // ensures full debuggability. If false, we can apply more |
| 725 | // aggressive optimizations that may limit the level of debugging. |
| 726 | const bool debuggable_; |
| 727 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 728 | // 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] | 729 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 730 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 731 | // The dex file from which the method is from. |
| 732 | const DexFile& dex_file_; |
| 733 | |
| 734 | // The method index in the dex file. |
| 735 | const uint32_t method_idx_; |
| 736 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 737 | // If inlined, this encodes how the callee is being invoked. |
| 738 | const InvokeType invoke_type_; |
| 739 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 740 | // Whether the graph has been transformed to SSA form. Only used |
| 741 | // in debug mode to ensure we are not using properties only valid |
| 742 | // for non-SSA form (like the number of temporaries). |
| 743 | bool in_ssa_form_; |
| 744 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 745 | // Number of CHA guards in the graph. Used to short-circuit the |
| 746 | // CHA guard optimization pass when there is no CHA guard left. |
| 747 | uint32_t number_of_cha_guards_; |
| 748 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 749 | const InstructionSet instruction_set_; |
| 750 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 751 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 752 | HNullConstant* cached_null_constant_; |
| 753 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 754 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 755 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 756 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 757 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 758 | HCurrentMethod* cached_current_method_; |
| 759 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 760 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 761 | // for example for methods whose declaring class could not be resolved |
| 762 | // (such as when the superclass could not be found). |
| 763 | ArtMethod* art_method_; |
| 764 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 765 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 766 | // collection pointer to passes which may create NullConstant. |
| 767 | ReferenceTypeInfo inexact_object_rti_; |
| 768 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 769 | // Whether we are compiling this graph for on stack replacement: this will |
| 770 | // make all loops seen as irreducible and emit special stack maps to mark |
| 771 | // compiled code entries which the interpreter can directly jump to. |
| 772 | const bool osr_; |
| 773 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 774 | // List of methods that are assumed to have single implementation. |
| 775 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 776 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 777 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 778 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 779 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 780 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 781 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 782 | }; |
| 783 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 784 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 785 | public: |
| 786 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 787 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 788 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 789 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 790 | contains_irreducible_loop_(false), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 791 | back_edges_(graph->GetAllocator()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 792 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 793 | blocks_(graph->GetAllocator(), |
| 794 | graph->GetBlocks().size(), |
| 795 | true, |
| 796 | kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 797 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 798 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 799 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 800 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 801 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 802 | |
| 803 | void Dump(std::ostream& os); |
| 804 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 805 | HBasicBlock* GetHeader() const { |
| 806 | return header_; |
| 807 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 808 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 809 | void SetHeader(HBasicBlock* block) { |
| 810 | header_ = block; |
| 811 | } |
| 812 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 813 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 814 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 815 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 816 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 817 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 818 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 821 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 822 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 823 | } |
| 824 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 825 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 826 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 827 | } |
| 828 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 829 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 830 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 831 | } |
| 832 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 833 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 834 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 835 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 836 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 837 | } |
| 838 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 839 | // Returns the lifetime position of the back edge that has the |
| 840 | // greatest lifetime position. |
| 841 | size_t GetLifetimeEnd() const; |
| 842 | |
| 843 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 844 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 845 | } |
| 846 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 847 | // Finds blocks that are part of this loop. |
| 848 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 849 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 850 | // Updates blocks population of the loop and all of its outer' ones recursively after the |
| 851 | // population of the inner loop is updated. |
| 852 | void PopulateInnerLoopUpwards(HLoopInformation* inner_loop); |
| 853 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 854 | // Returns whether this loop information contains `block`. |
| 855 | // Note that this loop information *must* be populated before entering this function. |
| 856 | bool Contains(const HBasicBlock& block) const; |
| 857 | |
| 858 | // Returns whether this loop information is an inner loop of `other`. |
| 859 | // Note that `other` *must* be populated before entering this function. |
| 860 | bool IsIn(const HLoopInformation& other) const; |
| 861 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 862 | // Returns true if instruction is not defined within this loop. |
| 863 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 864 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 865 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 866 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 867 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 868 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 869 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 870 | void ClearAllBlocks() { |
| 871 | blocks_.ClearAllBits(); |
| 872 | } |
| 873 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 874 | bool HasBackEdgeNotDominatedByHeader() const; |
| 875 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 876 | bool IsPopulated() const { |
| 877 | return blocks_.GetHighestBitSet() != -1; |
| 878 | } |
| 879 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 880 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 881 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 882 | bool HasExitEdge() const; |
| 883 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 884 | // Resets back edge and blocks-in-loop data. |
| 885 | void ResetBasicBlockData() { |
| 886 | back_edges_.clear(); |
| 887 | ClearAllBlocks(); |
| 888 | } |
| 889 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 890 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 891 | // Internal recursive implementation of `Populate`. |
| 892 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 893 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 894 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 895 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 896 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 897 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 898 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 899 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 900 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 901 | |
| 902 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 903 | }; |
| 904 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 905 | // Stores try/catch information for basic blocks. |
| 906 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 907 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 908 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 909 | public: |
| 910 | // Try block information constructor. |
| 911 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 912 | : try_entry_(&try_entry), |
| 913 | catch_dex_file_(nullptr), |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 914 | catch_type_index_(dex::TypeIndex::Invalid()) { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 915 | DCHECK(try_entry_ != nullptr); |
| 916 | } |
| 917 | |
| 918 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 919 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 920 | : try_entry_(nullptr), |
| 921 | catch_dex_file_(&dex_file), |
| 922 | catch_type_index_(catch_type_index) {} |
| 923 | |
| 924 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 925 | |
| 926 | const HTryBoundary& GetTryEntry() const { |
| 927 | DCHECK(IsTryBlock()); |
| 928 | return *try_entry_; |
| 929 | } |
| 930 | |
| 931 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 932 | |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 933 | bool IsValidTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 934 | DCHECK(IsCatchBlock()); |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 935 | return catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 936 | } |
| 937 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 938 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 939 | DCHECK(IsCatchBlock()); |
| 940 | return catch_type_index_; |
| 941 | } |
| 942 | |
| 943 | const DexFile& GetCatchDexFile() const { |
| 944 | DCHECK(IsCatchBlock()); |
| 945 | return *catch_dex_file_; |
| 946 | } |
| 947 | |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 948 | void SetInvalidTypeIndex() { |
| 949 | catch_type_index_ = dex::TypeIndex::Invalid(); |
| 950 | } |
| 951 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 952 | private: |
| 953 | // One of possibly several TryBoundary instructions entering the block's try. |
| 954 | // Only set for try blocks. |
| 955 | const HTryBoundary* try_entry_; |
| 956 | |
| 957 | // Exception type information. Only set for catch blocks. |
| 958 | const DexFile* catch_dex_file_; |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 959 | dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 960 | }; |
| 961 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 962 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 963 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 964 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 965 | // A block in a method. Contains the list of instructions represented |
| 966 | // as a double linked list. Each block knows its predecessors and |
| 967 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 968 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 969 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 970 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 971 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 972 | : graph_(graph), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 973 | predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), |
| 974 | successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 975 | loop_information_(nullptr), |
| 976 | dominator_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 977 | dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 978 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 979 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 980 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 981 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 982 | try_catch_information_(nullptr) { |
| 983 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 984 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 985 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 986 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 987 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 988 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 989 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 992 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 993 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 994 | } |
| 995 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 996 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 997 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 998 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 999 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 1000 | return ContainsElement(successors_, block, start_from); |
| 1001 | } |
| 1002 | |
| 1003 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1004 | return dominated_blocks_; |
| 1005 | } |
| 1006 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1007 | bool IsEntryBlock() const { |
| 1008 | return graph_->GetEntryBlock() == this; |
| 1009 | } |
| 1010 | |
| 1011 | bool IsExitBlock() const { |
| 1012 | return graph_->GetExitBlock() == this; |
| 1013 | } |
| 1014 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1015 | bool IsSingleGoto() const; |
Mads Ager | 16e5289 | 2017-07-14 13:11:37 +0200 | [diff] [blame] | 1016 | bool IsSingleReturn() const; |
Mingyao Yang | 46721ef | 2017-10-05 14:45:17 -0700 | [diff] [blame] | 1017 | bool IsSingleReturnOrReturnVoidAllowingPhis() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1018 | bool IsSingleTryBoundary() const; |
| 1019 | |
| 1020 | // Returns true if this block emits nothing but a jump. |
| 1021 | bool IsSingleJump() const { |
| 1022 | HLoopInformation* loop_info = GetLoopInformation(); |
| 1023 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 1024 | // Back edges generate a suspend check. |
| 1025 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 1026 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1027 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1028 | void AddBackEdge(HBasicBlock* back_edge) { |
| 1029 | if (loop_information_ == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1030 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1031 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1032 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1033 | loop_information_->AddBackEdge(back_edge); |
| 1034 | } |
| 1035 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 1036 | // Registers a back edge; if the block was not a loop header before the call associates a newly |
| 1037 | // created loop info with it. |
| 1038 | // |
| 1039 | // Used in SuperblockCloner to preserve LoopInformation object instead of reseting loop |
| 1040 | // info for all blocks during back edges recalculation. |
| 1041 | void AddBackEdgeWhileUpdating(HBasicBlock* back_edge) { |
| 1042 | if (loop_information_ == nullptr || loop_information_->GetHeader() != this) { |
| 1043 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
| 1044 | } |
| 1045 | loop_information_->AddBackEdge(back_edge); |
| 1046 | } |
| 1047 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1048 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1049 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1050 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1051 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1052 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1053 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1054 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1055 | HBasicBlock* GetDominator() const { return dominator_; } |
| 1056 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1057 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 1058 | |
| 1059 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 1060 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 1061 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1062 | |
| 1063 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1064 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 1065 | } |
| 1066 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1067 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1068 | |
| 1069 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1070 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1073 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1074 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1075 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1076 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1077 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1078 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1079 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1080 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1081 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1082 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1083 | successors_.push_back(block); |
| 1084 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1087 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1088 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1089 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1090 | new_block->predecessors_.push_back(this); |
| 1091 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1094 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1095 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1096 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1097 | new_block->successors_.push_back(this); |
| 1098 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1101 | // Insert `this` between `predecessor` and `successor. This method |
| 1102 | // preserves the indicies, and will update the first edge found between |
| 1103 | // `predecessor` and `successor`. |
| 1104 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1105 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1106 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1107 | successor->predecessors_[predecessor_index] = this; |
| 1108 | predecessor->successors_[successor_index] = this; |
| 1109 | successors_.push_back(successor); |
| 1110 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1111 | } |
| 1112 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1113 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1114 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1115 | } |
| 1116 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1117 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1118 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1121 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1122 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1126 | predecessors_.push_back(block); |
| 1127 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1128 | } |
| 1129 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1130 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1131 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1132 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1133 | } |
| 1134 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1135 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1136 | DCHECK_EQ(successors_.size(), 2u); |
| 1137 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1138 | } |
| 1139 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1140 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1141 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1142 | } |
| 1143 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1144 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1145 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1146 | } |
| 1147 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1148 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1149 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1150 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1154 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1155 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1159 | // predecessors is at index `idx`. |
| 1160 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1161 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1162 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1163 | } |
| 1164 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1165 | // Create a new block between this block and its predecessors. The new block |
| 1166 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1167 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1168 | // loop and try/catch information are not updated. |
| 1169 | HBasicBlock* CreateImmediateDominator(); |
| 1170 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1171 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1172 | // created, latter block. Note that this method will add the block to the |
| 1173 | // graph, create a Goto at the end of the former block and will create an edge |
| 1174 | // 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] | 1175 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1176 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1177 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1178 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1179 | // created block. Note that this method just updates raw block information, |
| 1180 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1181 | // update the graph, reverse post order, loop information, nor make sure the |
| 1182 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1183 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1184 | |
| 1185 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1186 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1187 | |
| 1188 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1189 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1190 | // that this method does not update the graph, reverse post order, loop |
| 1191 | // information, nor make sure the blocks are consistent (for example ending |
| 1192 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1193 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1194 | |
| 1195 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1196 | // of `this` are moved to `other`. |
| 1197 | // Note that this method does not update the graph, reverse post order, loop |
| 1198 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1199 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1200 | void ReplaceWith(HBasicBlock* other); |
| 1201 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1202 | // Merges the instructions of `other` at the end of `this`. |
| 1203 | void MergeInstructionsWith(HBasicBlock* other); |
| 1204 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1205 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1206 | // order, links to predecessors, successors, dominators and deletes the block |
| 1207 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1208 | // predecessor of `other` and vice versa. |
| 1209 | void MergeWith(HBasicBlock* other); |
| 1210 | |
| 1211 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1212 | // removes it from all loops it is included in and eventually from the graph. |
| 1213 | // The block must not dominate any other block. Predecessors and successors |
| 1214 | // are safely updated. |
| 1215 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1216 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1217 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1218 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1219 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1220 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1221 | // Replace phi `initial` with `replacement` within this block. |
| 1222 | void ReplaceAndRemovePhiWith(HPhi* initial, HPhi* replacement); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1223 | // Replace instruction `initial` with `replacement` within this block. |
| 1224 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1225 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1226 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1227 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1228 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1229 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1230 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1231 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1232 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1233 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1234 | |
| 1235 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1236 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1237 | } |
| 1238 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1239 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1240 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1241 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1242 | } |
| 1243 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1244 | bool IsFirstPredecessorBackEdge() const { |
| 1245 | DCHECK(IsLoopHeader()); |
| 1246 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1247 | } |
| 1248 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1249 | HLoopInformation* GetLoopInformation() const { |
| 1250 | return loop_information_; |
| 1251 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1252 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1253 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1254 | // 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] | 1255 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1256 | void SetInLoop(HLoopInformation* info) { |
| 1257 | if (IsLoopHeader()) { |
| 1258 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1259 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1260 | loop_information_ = info; |
| 1261 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1262 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1263 | // Note that a non loop header having a loop information means this loop information |
| 1264 | // has already been populated |
| 1265 | loop_information_ = info; |
| 1266 | } else { |
| 1267 | // Block is part of an inner loop. Do not update the loop information. |
| 1268 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1269 | // at this point, because this method is being called while populating `info`. |
| 1270 | } |
| 1271 | } |
| 1272 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1273 | // Raw update of the loop information. |
| 1274 | void SetLoopInformation(HLoopInformation* info) { |
| 1275 | loop_information_ = info; |
| 1276 | } |
| 1277 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1278 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1279 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1280 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1281 | |
| 1282 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1283 | try_catch_information_ = try_catch_information; |
| 1284 | } |
| 1285 | |
| 1286 | bool IsTryBlock() const { |
| 1287 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1288 | } |
| 1289 | |
| 1290 | bool IsCatchBlock() const { |
| 1291 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1292 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1293 | |
| 1294 | // Returns the try entry that this block's successors should have. They will |
| 1295 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1296 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1297 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1298 | |
Aart Bik | 75ff2c9 | 2018-04-21 01:28:11 +0000 | [diff] [blame] | 1299 | bool HasThrowingInstructions() const; |
| 1300 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1301 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1302 | bool Dominates(HBasicBlock* block) const; |
| 1303 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1304 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1305 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1306 | |
| 1307 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1308 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1309 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1310 | bool EndsWithControlFlowInstruction() const; |
Aart Bik | 4dc09e7 | 2018-05-11 14:40:31 -0700 | [diff] [blame] | 1311 | bool EndsWithReturn() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1312 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1313 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1314 | bool HasSinglePhi() const; |
| 1315 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1316 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1317 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1318 | ArenaVector<HBasicBlock*> predecessors_; |
| 1319 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1320 | HInstructionList instructions_; |
| 1321 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1322 | HLoopInformation* loop_information_; |
| 1323 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1324 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1325 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1326 | // The dex program counter of the first instruction of this block. |
| 1327 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1328 | size_t lifetime_start_; |
| 1329 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1330 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1331 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1332 | friend class HGraph; |
| 1333 | friend class HInstruction; |
| 1334 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1335 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1336 | }; |
| 1337 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1338 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1339 | // from the innermost to the outermost. |
| 1340 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1341 | public: |
| 1342 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1343 | : current_(block.GetLoopInformation()) {} |
| 1344 | |
| 1345 | bool Done() const { return current_ == nullptr; } |
| 1346 | |
| 1347 | void Advance() { |
| 1348 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1349 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | HLoopInformation* Current() const { |
| 1353 | DCHECK(!Done()); |
| 1354 | return current_; |
| 1355 | } |
| 1356 | |
| 1357 | private: |
| 1358 | HLoopInformation* current_; |
| 1359 | |
| 1360 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1361 | }; |
| 1362 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1363 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1364 | M(Above, Condition) \ |
| 1365 | M(AboveOrEqual, Condition) \ |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 1366 | M(Abs, UnaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1367 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1368 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1369 | M(ArrayGet, Instruction) \ |
| 1370 | M(ArrayLength, Instruction) \ |
| 1371 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1372 | M(Below, Condition) \ |
| 1373 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1374 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1375 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1376 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1377 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1378 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1379 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1380 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1381 | M(Compare, BinaryOperation) \ |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1382 | M(ConstructorFence, Instruction) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1383 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1384 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1385 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1386 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1387 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1388 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1389 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1390 | M(Exit, Instruction) \ |
| 1391 | M(FloatConstant, Constant) \ |
| 1392 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1393 | M(GreaterThan, Condition) \ |
| 1394 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1395 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1396 | M(InstanceFieldGet, Instruction) \ |
| 1397 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1398 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1399 | M(IntConstant, Constant) \ |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 1400 | M(IntermediateAddress, Instruction) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1401 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1402 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1403 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1404 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1405 | M(InvokePolymorphic, Invoke) \ |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1406 | M(InvokeCustom, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1407 | M(LessThan, Condition) \ |
| 1408 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1409 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1410 | M(LoadException, Instruction) \ |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 1411 | M(LoadMethodHandle, Instruction) \ |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 1412 | M(LoadMethodType, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1413 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1414 | M(LongConstant, Constant) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1415 | M(Max, Instruction) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1416 | M(MemoryBarrier, Instruction) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1417 | M(Min, BinaryOperation) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1418 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1419 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1420 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1421 | M(Neg, UnaryOperation) \ |
| 1422 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1423 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1424 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1425 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1426 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1427 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1428 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1429 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1430 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1431 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1432 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1433 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1434 | M(Return, Instruction) \ |
| 1435 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1436 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1437 | M(Shl, BinaryOperation) \ |
| 1438 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1439 | M(StaticFieldGet, Instruction) \ |
| 1440 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1441 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1442 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1443 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1444 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1445 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1446 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1447 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1448 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1449 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1450 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1451 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1452 | M(Xor, BinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1453 | M(VecReplicateScalar, VecUnaryOperation) \ |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1454 | M(VecExtractScalar, VecUnaryOperation) \ |
| 1455 | M(VecReduce, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1456 | M(VecCnv, VecUnaryOperation) \ |
| 1457 | M(VecNeg, VecUnaryOperation) \ |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1458 | M(VecAbs, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1459 | M(VecNot, VecUnaryOperation) \ |
| 1460 | M(VecAdd, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1461 | M(VecHalvingAdd, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1462 | M(VecSub, VecBinaryOperation) \ |
| 1463 | M(VecMul, VecBinaryOperation) \ |
| 1464 | M(VecDiv, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1465 | M(VecMin, VecBinaryOperation) \ |
| 1466 | M(VecMax, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1467 | M(VecAnd, VecBinaryOperation) \ |
| 1468 | M(VecAndNot, VecBinaryOperation) \ |
| 1469 | M(VecOr, VecBinaryOperation) \ |
| 1470 | M(VecXor, VecBinaryOperation) \ |
Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1471 | M(VecSaturationAdd, VecBinaryOperation) \ |
| 1472 | M(VecSaturationSub, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1473 | M(VecShl, VecBinaryOperation) \ |
| 1474 | M(VecShr, VecBinaryOperation) \ |
| 1475 | M(VecUShr, VecBinaryOperation) \ |
Aart Bik | 8de5916 | 2017-04-21 09:42:01 -0700 | [diff] [blame] | 1476 | M(VecSetScalars, VecOperation) \ |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1477 | M(VecMultiplyAccumulate, VecOperation) \ |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1478 | M(VecSADAccumulate, VecOperation) \ |
Artem Serov | aaac0e3 | 2018-08-07 00:52:22 +0100 | [diff] [blame] | 1479 | M(VecDotProd, VecOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1480 | M(VecLoad, VecMemoryOperation) \ |
| 1481 | M(VecStore, VecMemoryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1482 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1483 | /* |
| 1484 | * Instructions, shared across several (not all) architectures. |
| 1485 | */ |
| 1486 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1487 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1488 | #else |
| 1489 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1490 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1491 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1492 | M(MultiplyAccumulate, Instruction) \ |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 1493 | M(IntermediateAddressIndex, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1494 | #endif |
| 1495 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1496 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1497 | |
| 1498 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1499 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1500 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1501 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1502 | #else |
| 1503 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1504 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 1505 | M(MipsPackedSwitch, Instruction) \ |
| 1506 | M(IntermediateArrayAddressIndex, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1507 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1508 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1509 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1510 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1511 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1512 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1513 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1514 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1515 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1516 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1517 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1518 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1519 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1520 | |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 1521 | #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64) |
| 1522 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) \ |
| 1523 | M(X86AndNot, Instruction) \ |
| 1524 | M(X86MaskOrResetLeastSetBit, Instruction) |
| 1525 | #else |
| 1526 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) |
| 1527 | #endif |
| 1528 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1529 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1530 | |
| 1531 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1532 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1533 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1534 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1535 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1536 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1537 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1538 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 1539 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) \ |
| 1540 | FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1541 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1542 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1543 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1544 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1545 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1546 | M(BinaryOperation, Instruction) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1547 | M(Invoke, Instruction) \ |
| 1548 | M(VecOperation, Instruction) \ |
| 1549 | M(VecUnaryOperation, VecOperation) \ |
| 1550 | M(VecBinaryOperation, VecOperation) \ |
| 1551 | M(VecMemoryOperation, VecOperation) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1552 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1553 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1554 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1555 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1556 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1557 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1558 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1559 | #undef FORWARD_DECLARATION |
| 1560 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1561 | #define DECLARE_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1562 | private: \ |
| 1563 | H##type& operator=(const H##type&) = delete; \ |
| 1564 | public: \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1565 | const char* DebugName() const override { return #type; } \ |
| 1566 | HInstruction* Clone(ArenaAllocator* arena) const override { \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1567 | DCHECK(IsClonable()); \ |
| 1568 | return new (arena) H##type(*this->As##type()); \ |
| 1569 | } \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1570 | void Accept(HGraphVisitor* visitor) override |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1571 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1572 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1573 | private: \ |
| 1574 | H##type& operator=(const H##type&) = delete; \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 1575 | public: |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1576 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1577 | #define DEFAULT_COPY_CONSTRUCTOR(type) \ |
| 1578 | explicit H##type(const H##type& other) = default; |
| 1579 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1580 | template <typename T> |
Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 1581 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode>, |
| 1582 | public IntrusiveForwardListNode<HUseListNode<T>> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1583 | public: |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1584 | // Get the instruction which has this use as one of the inputs. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1585 | T GetUser() const { return user_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1586 | // Get the position of the input record that this use corresponds to. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1587 | size_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1588 | // Set the position of the input record that this use corresponds to. |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1589 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1590 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1591 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1592 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1593 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1594 | |
| 1595 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1596 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1597 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1598 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1599 | |
| 1600 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1601 | }; |
| 1602 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1603 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1604 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1605 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1606 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1607 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1608 | // by the used instructions. |
| 1609 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1610 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1611 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1612 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1613 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1614 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1615 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1616 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1617 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1618 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1619 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1623 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1624 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1625 | |
| 1626 | private: |
| 1627 | // Instruction used by the user. |
| 1628 | HInstruction* instruction_; |
| 1629 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1630 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1631 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1632 | }; |
| 1633 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1634 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1635 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1636 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1637 | struct HInputExtractor { |
| 1638 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1639 | return record.GetInstruction(); |
| 1640 | } |
| 1641 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1642 | return record.GetInstruction(); |
| 1643 | } |
| 1644 | }; |
| 1645 | |
| 1646 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1647 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1648 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1649 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1650 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1651 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1652 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1653 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1654 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1655 | * modify the value of a reference field read [although it may modify the |
| 1656 | * reference fetch prior to reading the field, which is represented by its own |
| 1657 | * write/read dependence]). The analysis makes conservative points-to |
| 1658 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1659 | * the same, and any reference read depends on any reference read without |
| 1660 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1661 | * |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1662 | * kDependsOnGCBit is defined in the following way: instructions with kDependsOnGCBit must not be |
| 1663 | * alive across the point where garbage collection might happen. |
| 1664 | * |
| 1665 | * Note: Instructions with kCanTriggerGCBit do not depend on each other. |
| 1666 | * |
| 1667 | * kCanTriggerGCBit must be used for instructions for which GC might happen on the path across |
| 1668 | * those instructions from the compiler perspective (between this instruction and the next one |
| 1669 | * in the IR). |
| 1670 | * |
| 1671 | * Note: Instructions which can cause GC only on a fatal slow path do not need |
| 1672 | * kCanTriggerGCBit as the execution never returns to the instruction next to the exceptional |
| 1673 | * one. However the execution may return to compiled code if there is a catch block in the |
| 1674 | * current method; for this purpose the TryBoundary exit instruction has kCanTriggerGCBit |
| 1675 | * set. |
| 1676 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1677 | * The internal representation uses 38-bit and is described in the table below. |
| 1678 | * The first line indicates the side effect, and for field/array accesses the |
| 1679 | * 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] | 1680 | * DataType::Type enum). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1681 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1682 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1683 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1684 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1685 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1686 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1687 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1688 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1689 | * |
| 1690 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1691 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1692 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1693 | class SideEffects : public ValueObject { |
| 1694 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1695 | SideEffects() : flags_(0) {} |
| 1696 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1697 | static SideEffects None() { |
| 1698 | return SideEffects(0); |
| 1699 | } |
| 1700 | |
| 1701 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1702 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1703 | } |
| 1704 | |
| 1705 | static SideEffects AllChanges() { |
| 1706 | return SideEffects(kAllChangeBits); |
| 1707 | } |
| 1708 | |
| 1709 | static SideEffects AllDependencies() { |
| 1710 | return SideEffects(kAllDependOnBits); |
| 1711 | } |
| 1712 | |
| 1713 | static SideEffects AllExceptGCDependency() { |
| 1714 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1715 | } |
| 1716 | |
| 1717 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1718 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1719 | } |
| 1720 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1721 | static SideEffects AllWrites() { |
| 1722 | return SideEffects(kAllWrites); |
| 1723 | } |
| 1724 | |
| 1725 | static SideEffects AllReads() { |
| 1726 | return SideEffects(kAllReads); |
| 1727 | } |
| 1728 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1729 | static SideEffects FieldWriteOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1730 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1731 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1732 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1733 | } |
| 1734 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1735 | static SideEffects ArrayWriteOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1736 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1737 | } |
| 1738 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1739 | static SideEffects FieldReadOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1740 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1741 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1742 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1745 | static SideEffects ArrayReadOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1746 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1749 | // Returns whether GC might happen across this instruction from the compiler perspective so |
| 1750 | // the next instruction in the IR would see that. |
| 1751 | // |
| 1752 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1753 | static SideEffects CanTriggerGC() { |
| 1754 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1755 | } |
| 1756 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1757 | // Returns whether the instruction must not be alive across a GC point. |
| 1758 | // |
| 1759 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1760 | static SideEffects DependsOnGC() { |
| 1761 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1762 | } |
| 1763 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1764 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1765 | SideEffects Union(SideEffects other) const { |
| 1766 | return SideEffects(flags_ | other.flags_); |
| 1767 | } |
| 1768 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1769 | SideEffects Exclusion(SideEffects other) const { |
| 1770 | return SideEffects(flags_ & ~other.flags_); |
| 1771 | } |
| 1772 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1773 | void Add(SideEffects other) { |
| 1774 | flags_ |= other.flags_; |
| 1775 | } |
| 1776 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1777 | bool Includes(SideEffects other) const { |
| 1778 | return (other.flags_ & flags_) == other.flags_; |
| 1779 | } |
| 1780 | |
| 1781 | bool HasSideEffects() const { |
| 1782 | return (flags_ & kAllChangeBits); |
| 1783 | } |
| 1784 | |
| 1785 | bool HasDependencies() const { |
| 1786 | return (flags_ & kAllDependOnBits); |
| 1787 | } |
| 1788 | |
| 1789 | // Returns true if there are no side effects or dependencies. |
| 1790 | bool DoesNothing() const { |
| 1791 | return flags_ == 0; |
| 1792 | } |
| 1793 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1794 | // Returns true if something is written. |
| 1795 | bool DoesAnyWrite() const { |
| 1796 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1797 | } |
| 1798 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1799 | // Returns true if something is read. |
| 1800 | bool DoesAnyRead() const { |
| 1801 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1802 | } |
| 1803 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1804 | // Returns true if potentially everything is written and read |
| 1805 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1806 | bool DoesAllReadWrite() const { |
| 1807 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1808 | } |
| 1809 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1810 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1811 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1814 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1815 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1816 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1817 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1821 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1822 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1823 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1824 | for (int s = kLastBit; s >= 0; s--) { |
| 1825 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1826 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1827 | // This is a bit for the GC side effect. |
| 1828 | if (current_bit_is_set) { |
| 1829 | flags += "GC"; |
| 1830 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1831 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1832 | } else { |
| 1833 | // This is a bit for the array/field analysis. |
| 1834 | // The underscore character stands for the 'can trigger GC' bit. |
| 1835 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1836 | if (current_bit_is_set) { |
| 1837 | flags += kDebug[s]; |
| 1838 | } |
| 1839 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1840 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1841 | flags += "|"; |
| 1842 | } |
| 1843 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1844 | } |
| 1845 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1846 | } |
| 1847 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1848 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1849 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1850 | private: |
| 1851 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1852 | |
| 1853 | static constexpr int kFieldWriteOffset = 0; |
| 1854 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1855 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1856 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1857 | |
| 1858 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1859 | |
| 1860 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1861 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1862 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1863 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1864 | |
| 1865 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1866 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1867 | |
| 1868 | // Aliases. |
| 1869 | |
| 1870 | static_assert(kChangeBits == kDependOnBits, |
| 1871 | "the 'change' bits should match the 'depend on' bits."); |
| 1872 | |
| 1873 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1874 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1875 | static constexpr uint64_t kAllWrites = |
| 1876 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1877 | static constexpr uint64_t kAllReads = |
| 1878 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1879 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1880 | // 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] | 1881 | static uint64_t TypeFlag(DataType::Type type, int offset) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1882 | int shift; |
| 1883 | switch (type) { |
| 1884 | case DataType::Type::kReference: shift = 0; break; |
| 1885 | case DataType::Type::kBool: shift = 1; break; |
| 1886 | case DataType::Type::kInt8: shift = 2; break; |
| 1887 | case DataType::Type::kUint16: shift = 3; break; |
| 1888 | case DataType::Type::kInt16: shift = 4; break; |
| 1889 | case DataType::Type::kInt32: shift = 5; break; |
| 1890 | case DataType::Type::kInt64: shift = 6; break; |
| 1891 | case DataType::Type::kFloat32: shift = 7; break; |
| 1892 | case DataType::Type::kFloat64: shift = 8; break; |
| 1893 | default: |
| 1894 | LOG(FATAL) << "Unexpected data type " << type; |
| 1895 | UNREACHABLE(); |
| 1896 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1897 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1898 | DCHECK_LT(shift, kArrayWriteOffset); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1899 | return UINT64_C(1) << (shift + offset); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | // Private constructor on direct flags value. |
| 1903 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1904 | |
| 1905 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1906 | }; |
| 1907 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1908 | // 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] | 1909 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1910 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1911 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1912 | size_t number_of_vregs, |
| 1913 | ArtMethod* method, |
| 1914 | uint32_t dex_pc, |
| 1915 | HInstruction* holder) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1916 | : vregs_(number_of_vregs, allocator->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1917 | locations_(allocator->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1918 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1919 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1920 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1921 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1922 | } |
| 1923 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1924 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
| 1925 | const HEnvironment& to_copy, |
| 1926 | HInstruction* holder) |
| 1927 | : HEnvironment(allocator, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1928 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1929 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1930 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1931 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1932 | |
Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 1933 | void AllocateLocations() { |
| 1934 | DCHECK(locations_.empty()); |
| 1935 | locations_.resize(vregs_.size()); |
| 1936 | } |
| 1937 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1938 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1939 | if (parent_ != nullptr) { |
| 1940 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1941 | } else { |
| 1942 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1943 | parent_->CopyFrom(parent); |
| 1944 | if (parent->GetParent() != nullptr) { |
| 1945 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1946 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1947 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1948 | } |
| 1949 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 1950 | void CopyFrom(ArrayRef<HInstruction* const> locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1951 | void CopyFrom(HEnvironment* environment); |
| 1952 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1953 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1954 | // input to the loop phi instead. This is for inserting instructions that |
| 1955 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1956 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1957 | |
| 1958 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1959 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1963 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1966 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1967 | |
Artem Serov | ca210e3 | 2017-12-15 13:43:20 +0000 | [diff] [blame] | 1968 | // Replaces the input at the position 'index' with the replacement; the replacement and old |
| 1969 | // input instructions' env_uses_ lists are adjusted. The function works similar to |
| 1970 | // HInstruction::ReplaceInput. |
| 1971 | void ReplaceInput(HInstruction* replacement, size_t index); |
| 1972 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1973 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1974 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1975 | HEnvironment* GetParent() const { return parent_; } |
| 1976 | |
| 1977 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1978 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1982 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | uint32_t GetDexPc() const { |
| 1986 | return dex_pc_; |
| 1987 | } |
| 1988 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1989 | ArtMethod* GetMethod() const { |
| 1990 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1991 | } |
| 1992 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1993 | HInstruction* GetHolder() const { |
| 1994 | return holder_; |
| 1995 | } |
| 1996 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1997 | |
| 1998 | bool IsFromInlinedInvoke() const { |
| 1999 | return GetParent() != nullptr; |
| 2000 | } |
| 2001 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2002 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2003 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 2004 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2005 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2006 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2007 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2008 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 2009 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2010 | HInstruction* const holder_; |
| 2011 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 2012 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2013 | |
| 2014 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 2015 | }; |
| 2016 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2017 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2018 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2019 | #define DECLARE_KIND(type, super) k##type, |
| 2020 | enum InstructionKind { |
Vladimir Marko | e394622 | 2018-05-04 14:18:47 +0100 | [diff] [blame] | 2021 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_KIND) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2022 | kLastInstructionKind |
| 2023 | }; |
| 2024 | #undef DECLARE_KIND |
| 2025 | |
| 2026 | HInstruction(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2027 | : HInstruction(kind, DataType::Type::kVoid, side_effects, dex_pc) {} |
| 2028 | |
| 2029 | 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] | 2030 | : previous_(nullptr), |
| 2031 | next_(nullptr), |
| 2032 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2033 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2034 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2035 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2036 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2037 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2038 | locations_(nullptr), |
| 2039 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2040 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 2041 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2042 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2043 | SetPackedField<InstructionKindField>(kind); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2044 | SetPackedField<TypeField>(type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2045 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 2046 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2047 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2048 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2049 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2050 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2051 | HInstruction* GetNext() const { return next_; } |
| 2052 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2053 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2054 | HInstruction* GetNextDisregardingMoves() const; |
| 2055 | HInstruction* GetPreviousDisregardingMoves() const; |
| 2056 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2057 | HBasicBlock* GetBlock() const { return block_; } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2058 | ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2059 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 2060 | bool IsInBlock() const { return block_ != nullptr; } |
| 2061 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 2062 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 2063 | bool IsIrreducibleLoopHeaderPhi() const { |
| 2064 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 2065 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2066 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2067 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 2068 | |
| 2069 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 2070 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 2071 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 2072 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 2073 | } |
| 2074 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2075 | HInputsRef GetInputs() { |
| 2076 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2077 | } |
| 2078 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2079 | HConstInputsRef GetInputs() const { |
| 2080 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2084 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2085 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 2086 | bool HasInput(HInstruction* input) const { |
| 2087 | for (const HInstruction* i : GetInputs()) { |
| 2088 | if (i == input) { |
| 2089 | return true; |
| 2090 | } |
| 2091 | } |
| 2092 | return false; |
| 2093 | } |
| 2094 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2095 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 2096 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 2097 | } |
| 2098 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2099 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 2100 | virtual const char* DebugName() const = 0; |
| 2101 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2102 | DataType::Type GetType() const { |
| 2103 | return TypeField::Decode(GetPackedFields()); |
| 2104 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2105 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2106 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2107 | |
| 2108 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2109 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2110 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2111 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2112 | // Can the instruction throw? |
| 2113 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 2114 | // 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] | 2115 | virtual bool CanThrow() const { return false; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2116 | |
| 2117 | // Does the instruction always throw an exception unconditionally? |
| 2118 | virtual bool AlwaysThrows() const { return false; } |
| 2119 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2120 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2121 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2122 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2123 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2124 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2125 | // Does not apply for all instructions, but having this at top level greatly |
| 2126 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 2127 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2128 | virtual bool CanBeNull() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2129 | DCHECK_EQ(GetType(), DataType::Type::kReference) << "CanBeNull only applies to reference types"; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2130 | return true; |
| 2131 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2132 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2133 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 2134 | return false; |
| 2135 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2136 | |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 2137 | // If this instruction will do an implicit null check, return the `HNullCheck` associated |
| 2138 | // with it. Otherwise return null. |
| 2139 | HNullCheck* GetImplicitNullCheck() const { |
| 2140 | // Find the first previous instruction which is not a move. |
| 2141 | HInstruction* first_prev_not_move = GetPreviousDisregardingMoves(); |
| 2142 | if (first_prev_not_move != nullptr && |
| 2143 | first_prev_not_move->IsNullCheck() && |
| 2144 | first_prev_not_move->IsEmittedAtUseSite()) { |
| 2145 | return first_prev_not_move->AsNullCheck(); |
| 2146 | } |
| 2147 | return nullptr; |
| 2148 | } |
| 2149 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2150 | virtual bool IsActualObject() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2151 | return GetType() == DataType::Type::kReference; |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2152 | } |
| 2153 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 2154 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2155 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2156 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2157 | DCHECK_EQ(GetType(), DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2158 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 2159 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2160 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2161 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2162 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2163 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2164 | // Note: fixup_end remains valid across push_front(). |
| 2165 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 2166 | HUseListNode<HInstruction*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2167 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HInstruction*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2168 | uses_.push_front(*new_node); |
| 2169 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2172 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2173 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2174 | // Note: env_fixup_end remains valid across push_front(). |
| 2175 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2176 | HUseListNode<HEnvironment*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2177 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HEnvironment*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2178 | env_uses_.push_front(*new_node); |
| 2179 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2180 | } |
| 2181 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2182 | void RemoveAsUserOfInput(size_t input) { |
| 2183 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2184 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2185 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2186 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2187 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2188 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2189 | void RemoveAsUserOfAllInputs() { |
| 2190 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2191 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2192 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2193 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2194 | } |
| 2195 | } |
| 2196 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2197 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2198 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2199 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2200 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2201 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2202 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2203 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2204 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2205 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2206 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2207 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2208 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2209 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2210 | !CanThrow() && |
| 2211 | !IsSuspendCheck() && |
| 2212 | !IsControlFlow() && |
| 2213 | !IsNativeDebugInfo() && |
| 2214 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2215 | // If we added an explicit barrier then we should keep it. |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2216 | !IsMemoryBarrier() && |
| 2217 | !IsConstructorFence(); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2220 | bool IsDeadAndRemovable() const { |
| 2221 | return IsRemovable() && !HasUses(); |
| 2222 | } |
| 2223 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2224 | // Does this instruction strictly dominate `other_instruction`? |
| 2225 | // Returns false if this instruction and `other_instruction` are the same. |
| 2226 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2227 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2228 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2229 | int GetId() const { return id_; } |
| 2230 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2231 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2232 | int GetSsaIndex() const { return ssa_index_; } |
| 2233 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2234 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2235 | |
| 2236 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2237 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2238 | // Set the `environment_` field. Raw because this method does not |
| 2239 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2240 | void SetRawEnvironment(HEnvironment* environment) { |
| 2241 | DCHECK(environment_ == nullptr); |
| 2242 | DCHECK_EQ(environment->GetHolder(), this); |
| 2243 | environment_ = environment; |
| 2244 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2245 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2246 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2247 | DCHECK(environment_ != nullptr); |
| 2248 | DCHECK_EQ(environment->GetHolder(), this); |
| 2249 | DCHECK(environment->GetParent() == nullptr); |
| 2250 | environment->parent_ = environment_; |
| 2251 | environment_ = environment; |
| 2252 | } |
| 2253 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2254 | void RemoveEnvironment(); |
| 2255 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2256 | // Set the environment of this instruction, copying it from `environment`. While |
| 2257 | // copying, the uses lists are being updated. |
| 2258 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2259 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2260 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2261 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2262 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2263 | if (environment->GetParent() != nullptr) { |
| 2264 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2265 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2266 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2267 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2268 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2269 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2270 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2271 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2272 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2273 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2274 | if (environment->GetParent() != nullptr) { |
| 2275 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2276 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2279 | // Returns the number of entries in the environment. Typically, that is the |
| 2280 | // number of dex registers in a method. It could be more in case of inlining. |
| 2281 | size_t EnvironmentSize() const; |
| 2282 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2283 | LocationSummary* GetLocations() const { return locations_; } |
| 2284 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2285 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2286 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2287 | void ReplaceUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 8a62a4c | 2018-07-03 09:39:07 +0100 | [diff] [blame] | 2288 | void ReplaceEnvUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2289 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2290 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2291 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2292 | // uses of this instruction by `other` are *not* updated. |
| 2293 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2294 | ReplaceWith(other); |
| 2295 | other->ReplaceInput(this, use_index); |
| 2296 | } |
| 2297 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2298 | // Move `this` instruction before `cursor` |
| 2299 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2300 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2301 | // Move `this` before its first user and out of any loops. If there is no |
| 2302 | // out-of-loop user that dominates all other users, move the instruction |
| 2303 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2304 | // |
| 2305 | // This can be used only on non-throwing instructions with no side effects that |
| 2306 | // have at least one use but no environment uses. |
| 2307 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2308 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2309 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2310 | bool Is##type() const; |
| 2311 | |
| 2312 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2313 | #undef INSTRUCTION_TYPE_CHECK |
| 2314 | |
| 2315 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2316 | const H##type* As##type() const; \ |
| 2317 | H##type* As##type(); |
| 2318 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2319 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 2320 | #undef INSTRUCTION_TYPE_CAST |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2321 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2322 | // Return a clone of the instruction if it is clonable (shallow copy by default, custom copy |
| 2323 | // if a custom copy-constructor is provided for a particular type). If IsClonable() is false for |
| 2324 | // the instruction then the behaviour of this function is undefined. |
| 2325 | // |
| 2326 | // Note: It is semantically valid to create a clone of the instruction only until |
| 2327 | // prepare_for_register_allocator phase as lifetime, intervals and codegen info are not |
| 2328 | // copied. |
| 2329 | // |
| 2330 | // Note: HEnvironment and some other fields are not copied and are set to default values, see |
| 2331 | // 'explicit HInstruction(const HInstruction& other)' for details. |
| 2332 | virtual HInstruction* Clone(ArenaAllocator* arena ATTRIBUTE_UNUSED) const { |
| 2333 | LOG(FATAL) << "Cloning is not implemented for the instruction " << |
| 2334 | DebugName() << " " << GetId(); |
| 2335 | UNREACHABLE(); |
| 2336 | } |
| 2337 | |
| 2338 | // Return whether instruction can be cloned (copied). |
| 2339 | virtual bool IsClonable() const { return false; } |
| 2340 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2341 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2342 | // TODO: this method is used by LICM and GVN with possibly different |
| 2343 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2344 | virtual bool CanBeMoved() const { return false; } |
| 2345 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2346 | // Returns whether any data encoded in the two instructions is equal. |
| 2347 | // This method does not look at the inputs. Both instructions must be |
| 2348 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2349 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2350 | return false; |
| 2351 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2352 | |
| 2353 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2354 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2355 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2356 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2357 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2358 | InstructionKind GetKind() const { return GetPackedField<InstructionKindField>(); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2359 | |
| 2360 | virtual size_t ComputeHashCode() const { |
| 2361 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2362 | for (const HInstruction* input : GetInputs()) { |
| 2363 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2364 | } |
| 2365 | return result; |
| 2366 | } |
| 2367 | |
| 2368 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2369 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2370 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2371 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2372 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2373 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2374 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2375 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2376 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2377 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2378 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2379 | |
| 2380 | // Returns whether the code generation of the instruction will require to have access |
| 2381 | // to the current method. Such instructions are: |
| 2382 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2383 | // 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] | 2384 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2385 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2386 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2387 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2388 | } |
| 2389 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2390 | // Returns whether the code generation of the instruction will require to have access |
| 2391 | // to the dex cache of the current method's declaring class via the current method. |
| 2392 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2393 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2394 | // Does this instruction have any use in an environment before |
| 2395 | // control flow hits 'other'? |
| 2396 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2397 | |
| 2398 | // Remove all references to environment uses of this instruction. |
| 2399 | // The caller must ensure that this is safe to do. |
| 2400 | void RemoveEnvironmentUsers(); |
| 2401 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2402 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2403 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2404 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2405 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2406 | // If set, the machine code for this instruction is assumed to be generated by |
| 2407 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2408 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2409 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2410 | static constexpr size_t kFieldInstructionKind = kFlagReferenceTypeIsExact + 1; |
| 2411 | static constexpr size_t kFieldInstructionKindSize = |
| 2412 | MinimumBitsToStore(static_cast<size_t>(InstructionKind::kLastInstructionKind - 1)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2413 | static constexpr size_t kFieldType = |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2414 | kFieldInstructionKind + kFieldInstructionKindSize; |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2415 | static constexpr size_t kFieldTypeSize = |
| 2416 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
| 2417 | static constexpr size_t kNumberOfGenericPackedBits = kFieldType + kFieldTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2418 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2419 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2420 | static_assert(kNumberOfGenericPackedBits <= kMaxNumberOfPackedBits, |
| 2421 | "Too many generic packed fields"); |
| 2422 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2423 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
| 2424 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2425 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2426 | return GetInputRecords()[i]; |
| 2427 | } |
| 2428 | |
| 2429 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2430 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2431 | input_records[index] = input; |
| 2432 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2433 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2434 | uint32_t GetPackedFields() const { |
| 2435 | return packed_fields_; |
| 2436 | } |
| 2437 | |
| 2438 | template <size_t flag> |
| 2439 | bool GetPackedFlag() const { |
| 2440 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2441 | } |
| 2442 | |
| 2443 | template <size_t flag> |
| 2444 | void SetPackedFlag(bool value = true) { |
| 2445 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2446 | } |
| 2447 | |
| 2448 | template <typename BitFieldType> |
| 2449 | typename BitFieldType::value_type GetPackedField() const { |
| 2450 | return BitFieldType::Decode(packed_fields_); |
| 2451 | } |
| 2452 | |
| 2453 | template <typename BitFieldType> |
| 2454 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2455 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2456 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2457 | } |
| 2458 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2459 | // Copy construction for the instruction (used for Clone function). |
| 2460 | // |
| 2461 | // Fields (e.g. lifetime, intervals and codegen info) associated with phases starting from |
| 2462 | // prepare_for_register_allocator are not copied (set to default values). |
| 2463 | // |
| 2464 | // Copy constructors must be provided for every HInstruction type; default copy constructor is |
| 2465 | // fine for most of them. However for some of the instructions a custom copy constructor must be |
| 2466 | // specified (when instruction has non-trivially copyable fields and must have a special behaviour |
| 2467 | // for copying them). |
| 2468 | explicit HInstruction(const HInstruction& other) |
| 2469 | : previous_(nullptr), |
| 2470 | next_(nullptr), |
| 2471 | block_(nullptr), |
| 2472 | dex_pc_(other.dex_pc_), |
| 2473 | id_(-1), |
| 2474 | ssa_index_(-1), |
| 2475 | packed_fields_(other.packed_fields_), |
| 2476 | environment_(nullptr), |
| 2477 | locations_(nullptr), |
| 2478 | live_interval_(nullptr), |
| 2479 | lifetime_position_(kNoLifetime), |
| 2480 | side_effects_(other.side_effects_), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2481 | reference_type_handle_(other.reference_type_handle_) { |
| 2482 | } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2483 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2484 | private: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2485 | using InstructionKindField = |
| 2486 | BitField<InstructionKind, kFieldInstructionKind, kFieldInstructionKindSize>; |
| 2487 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2488 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2489 | auto before_use_node = uses_.before_begin(); |
| 2490 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2491 | HInstruction* user = use_node->GetUser(); |
| 2492 | size_t input_index = use_node->GetIndex(); |
| 2493 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2494 | before_use_node = use_node; |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2499 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2500 | if (next != uses_.end()) { |
| 2501 | HInstruction* next_user = next->GetUser(); |
| 2502 | size_t next_index = next->GetIndex(); |
| 2503 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2504 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2509 | auto before_env_use_node = env_uses_.before_begin(); |
| 2510 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2511 | HEnvironment* user = env_use_node->GetUser(); |
| 2512 | size_t input_index = env_use_node->GetIndex(); |
| 2513 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2514 | before_env_use_node = env_use_node; |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2519 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2520 | if (next != env_uses_.end()) { |
| 2521 | HEnvironment* next_user = next->GetUser(); |
| 2522 | size_t next_index = next->GetIndex(); |
| 2523 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2524 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2525 | } |
| 2526 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2527 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2528 | HInstruction* previous_; |
| 2529 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2530 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2531 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2532 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2533 | // An instruction gets an id when it is added to the graph. |
| 2534 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2535 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2536 | int id_; |
| 2537 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2538 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2539 | int ssa_index_; |
| 2540 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2541 | // Packed fields. |
| 2542 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2543 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2544 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2545 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2546 | |
| 2547 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2548 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2549 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2550 | // The environment associated with this instruction. Not null if the instruction |
| 2551 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2552 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2553 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2554 | // Set by the code generator. |
| 2555 | LocationSummary* locations_; |
| 2556 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2557 | // Set by the liveness analysis. |
| 2558 | LiveInterval* live_interval_; |
| 2559 | |
| 2560 | // Set by the liveness analysis, this is the position in a linear |
| 2561 | // order of blocks where this instruction's live interval start. |
| 2562 | size_t lifetime_position_; |
| 2563 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2564 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2565 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2566 | // The reference handle part of the reference type info. |
| 2567 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2568 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2569 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2570 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2571 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2572 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2573 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2574 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2575 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2576 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2577 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2578 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2579 | // Iterates over the instructions, while preserving the next instruction |
| 2580 | // in case the current instruction gets removed from the list by the user |
| 2581 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2582 | class HInstructionIterator : public ValueObject { |
| 2583 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2584 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2585 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2586 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2589 | bool Done() const { return instruction_ == nullptr; } |
| 2590 | HInstruction* Current() const { return instruction_; } |
| 2591 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2592 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2593 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | private: |
| 2597 | HInstruction* instruction_; |
| 2598 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2599 | |
| 2600 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2601 | }; |
| 2602 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2603 | // Iterates over the instructions without saving the next instruction, |
| 2604 | // therefore handling changes in the graph potentially made by the user |
| 2605 | // of this iterator. |
| 2606 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2607 | public: |
| 2608 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2609 | : instruction_(instructions.first_instruction_) { |
| 2610 | } |
| 2611 | |
| 2612 | bool Done() const { return instruction_ == nullptr; } |
| 2613 | HInstruction* Current() const { return instruction_; } |
| 2614 | void Advance() { |
| 2615 | instruction_ = instruction_->GetNext(); |
| 2616 | } |
| 2617 | |
| 2618 | private: |
| 2619 | HInstruction* instruction_; |
| 2620 | |
| 2621 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2622 | }; |
| 2623 | |
| 2624 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2625 | class HBackwardInstructionIterator : public ValueObject { |
| 2626 | public: |
| 2627 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2628 | : instruction_(instructions.last_instruction_) { |
| 2629 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2630 | } |
| 2631 | |
| 2632 | bool Done() const { return instruction_ == nullptr; } |
| 2633 | HInstruction* Current() const { return instruction_; } |
| 2634 | void Advance() { |
| 2635 | instruction_ = next_; |
| 2636 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2637 | } |
| 2638 | |
| 2639 | private: |
| 2640 | HInstruction* instruction_; |
| 2641 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2642 | |
| 2643 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2644 | }; |
| 2645 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2646 | class HVariableInputSizeInstruction : public HInstruction { |
| 2647 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2648 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2649 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2650 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2651 | } |
| 2652 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2653 | void AddInput(HInstruction* input); |
| 2654 | void InsertInputAt(size_t index, HInstruction* input); |
| 2655 | void RemoveInputAt(size_t index); |
| 2656 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2657 | // Removes all the inputs. |
| 2658 | // Also removes this instructions from each input's use list |
| 2659 | // (for non-environment uses only). |
| 2660 | void RemoveAllInputs(); |
| 2661 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2662 | protected: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2663 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2664 | SideEffects side_effects, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2665 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2666 | ArenaAllocator* allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2667 | size_t number_of_inputs, |
| 2668 | ArenaAllocKind kind) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2669 | : HInstruction(inst_kind, side_effects, dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2670 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2671 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2672 | DataType::Type type, |
| 2673 | SideEffects side_effects, |
| 2674 | uint32_t dex_pc, |
| 2675 | ArenaAllocator* allocator, |
| 2676 | size_t number_of_inputs, |
| 2677 | ArenaAllocKind kind) |
| 2678 | : HInstruction(inst_kind, type, side_effects, dex_pc), |
| 2679 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2680 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2681 | DEFAULT_COPY_CONSTRUCTOR(VariableInputSizeInstruction); |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2682 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2683 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2684 | }; |
| 2685 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2686 | template<size_t N> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2687 | class HExpression : public HInstruction { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2688 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2689 | HExpression<N>(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2690 | : HInstruction(kind, side_effects, dex_pc), inputs_() {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2691 | HExpression<N>(InstructionKind kind, |
| 2692 | DataType::Type type, |
| 2693 | SideEffects side_effects, |
| 2694 | uint32_t dex_pc) |
| 2695 | : HInstruction(kind, type, side_effects, dex_pc), inputs_() {} |
| 2696 | virtual ~HExpression() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2697 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2698 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 2699 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2700 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2703 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2704 | DEFAULT_COPY_CONSTRUCTOR(Expression<N>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2705 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2706 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2707 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2708 | |
| 2709 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2710 | }; |
| 2711 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2712 | // HExpression specialization for N=0. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2713 | template<> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2714 | class HExpression<0> : public HInstruction { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2715 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2716 | using HInstruction::HInstruction; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2717 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2718 | virtual ~HExpression() {} |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2719 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2720 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 2721 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2722 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2723 | } |
| 2724 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2725 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2726 | DEFAULT_COPY_CONSTRUCTOR(Expression<0>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2727 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2728 | private: |
| 2729 | friend class SsaBuilder; |
| 2730 | }; |
| 2731 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2732 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2733 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2734 | class HReturnVoid final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2735 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2736 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2737 | : HExpression(kReturnVoid, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2738 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2739 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2740 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2741 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2742 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2743 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2744 | protected: |
| 2745 | DEFAULT_COPY_CONSTRUCTOR(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2746 | }; |
| 2747 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2748 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2749 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2750 | class HReturn final : public HExpression<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2751 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2752 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2753 | : HExpression(kReturn, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2754 | SetRawInputAt(0, value); |
| 2755 | } |
| 2756 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2757 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2758 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2759 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2760 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2761 | protected: |
| 2762 | DEFAULT_COPY_CONSTRUCTOR(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2763 | }; |
| 2764 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2765 | class HPhi final : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2766 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2767 | HPhi(ArenaAllocator* allocator, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2768 | uint32_t reg_number, |
| 2769 | size_t number_of_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2770 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2771 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2772 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2773 | kPhi, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2774 | ToPhiType(type), |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2775 | SideEffects::None(), |
| 2776 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2777 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2778 | number_of_inputs, |
| 2779 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2780 | reg_number_(reg_number) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2781 | DCHECK_NE(GetType(), DataType::Type::kVoid); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2782 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2783 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2784 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2785 | SetPackedFlag<kFlagIsLive>(true); |
| 2786 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2787 | } |
| 2788 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2789 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2790 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2791 | // 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] | 2792 | static DataType::Type ToPhiType(DataType::Type type) { |
| 2793 | return DataType::Kind(type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2797 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2798 | void SetType(DataType::Type new_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2799 | // Make sure that only valid type changes occur. The following are allowed: |
| 2800 | // (1) int -> float/ref (primitive type propagation), |
| 2801 | // (2) long -> double (primitive type propagation). |
| 2802 | DCHECK(GetType() == new_type || |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2803 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kFloat32) || |
| 2804 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kReference) || |
| 2805 | (GetType() == DataType::Type::kInt64 && new_type == DataType::Type::kFloat64)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2806 | SetPackedField<TypeField>(new_type); |
| 2807 | } |
| 2808 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2809 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2810 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2811 | |
| 2812 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2813 | |
| 2814 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2815 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2816 | bool IsDead() const { return !IsLive(); } |
| 2817 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2818 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2819 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2820 | return other != nullptr |
| 2821 | && other->IsPhi() |
| 2822 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2823 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2824 | } |
| 2825 | |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 2826 | bool HasEquivalentPhi() const { |
| 2827 | if (GetPrevious() != nullptr && GetPrevious()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2828 | return true; |
| 2829 | } |
| 2830 | if (GetNext() != nullptr && GetNext()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2831 | return true; |
| 2832 | } |
| 2833 | return false; |
| 2834 | } |
| 2835 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2836 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2837 | // An equivalent phi is a phi having the same dex register and type. |
| 2838 | // It assumes that phis with the same dex register are adjacent. |
| 2839 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2840 | HInstruction* next = GetNext(); |
| 2841 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2842 | if (next->GetType() == GetType()) { |
| 2843 | return next->AsPhi(); |
| 2844 | } |
| 2845 | next = next->GetNext(); |
| 2846 | } |
| 2847 | return nullptr; |
| 2848 | } |
| 2849 | |
| 2850 | DECLARE_INSTRUCTION(Phi); |
| 2851 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2852 | protected: |
| 2853 | DEFAULT_COPY_CONSTRUCTOR(Phi); |
| 2854 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2855 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2856 | static constexpr size_t kFlagIsLive = HInstruction::kNumberOfGenericPackedBits; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2857 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2858 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2859 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2860 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2861 | const uint32_t reg_number_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2862 | }; |
| 2863 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2864 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2865 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2866 | // exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2867 | class HExit final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2868 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2869 | explicit HExit(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2870 | : HExpression(kExit, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2871 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2872 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2873 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2874 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2875 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2876 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2877 | protected: |
| 2878 | DEFAULT_COPY_CONSTRUCTOR(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2879 | }; |
| 2880 | |
| 2881 | // Jumps from one block to another. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2882 | class HGoto final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2883 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2884 | explicit HGoto(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2885 | : HExpression(kGoto, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2886 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2887 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2888 | bool IsClonable() const override { return true; } |
| 2889 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2890 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2891 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2892 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2893 | } |
| 2894 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2895 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2896 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2897 | protected: |
| 2898 | DEFAULT_COPY_CONSTRUCTOR(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2899 | }; |
| 2900 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2901 | class HConstant : public HExpression<0> { |
| 2902 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2903 | explicit HConstant(InstructionKind kind, DataType::Type type, uint32_t dex_pc = kNoDexPc) |
| 2904 | : HExpression(kind, type, SideEffects::None(), dex_pc) { |
| 2905 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2906 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2907 | bool CanBeMoved() const override { return true; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2908 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2909 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2910 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2911 | // Is this constant 0 in the arithmetic sense? |
| 2912 | virtual bool IsArithmeticZero() const { return false; } |
| 2913 | // Is this constant a 0-bit pattern? |
| 2914 | virtual bool IsZeroBitPattern() const { return false; } |
| 2915 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2916 | virtual bool IsOne() const { return false; } |
| 2917 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2918 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2919 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2920 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2921 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2922 | protected: |
| 2923 | DEFAULT_COPY_CONSTRUCTOR(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2924 | }; |
| 2925 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2926 | class HNullConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2927 | public: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2928 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2929 | return true; |
| 2930 | } |
| 2931 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2932 | uint64_t GetValueAsUint64() const override { return 0; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2933 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2934 | size_t ComputeHashCode() const override { return 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2935 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2936 | // The null constant representation is a 0-bit pattern. |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame^] | 2937 | bool IsZeroBitPattern() const override { return true; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2938 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2939 | DECLARE_INSTRUCTION(NullConstant); |
| 2940 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2941 | protected: |
| 2942 | DEFAULT_COPY_CONSTRUCTOR(NullConstant); |
| 2943 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2944 | private: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2945 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2946 | : HConstant(kNullConstant, DataType::Type::kReference, dex_pc) { |
| 2947 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2948 | |
| 2949 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2950 | }; |
| 2951 | |
| 2952 | // Constants of the type int. Those can be from Dex instructions, or |
| 2953 | // synthesized (for example with the if-eqz instruction). |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2954 | class HIntConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2955 | public: |
| 2956 | int32_t GetValue() const { return value_; } |
| 2957 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2958 | uint64_t GetValueAsUint64() const override { |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2959 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2960 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2961 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2962 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2963 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2964 | return other->AsIntConstant()->value_ == value_; |
| 2965 | } |
| 2966 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2967 | size_t ComputeHashCode() const override { return GetValue(); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2968 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2969 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 2970 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 2971 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 2972 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2973 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2974 | // Integer constants are used to encode Boolean values as well, |
| 2975 | // where 1 means true and 0 means false. |
| 2976 | bool IsTrue() const { return GetValue() == 1; } |
| 2977 | bool IsFalse() const { return GetValue() == 0; } |
| 2978 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2979 | DECLARE_INSTRUCTION(IntConstant); |
| 2980 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2981 | protected: |
| 2982 | DEFAULT_COPY_CONSTRUCTOR(IntConstant); |
| 2983 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2984 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2985 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2986 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), value_(value) { |
| 2987 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2988 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2989 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), |
| 2990 | value_(value ? 1 : 0) { |
| 2991 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2992 | |
| 2993 | const int32_t value_; |
| 2994 | |
| 2995 | friend class HGraph; |
| 2996 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2997 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2998 | }; |
| 2999 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3000 | class HLongConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3001 | public: |
| 3002 | int64_t GetValue() const { return value_; } |
| 3003 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3004 | uint64_t GetValueAsUint64() const override { return value_; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3005 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3006 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3007 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3008 | return other->AsLongConstant()->value_ == value_; |
| 3009 | } |
| 3010 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3011 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3012 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3013 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 3014 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 3015 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 3016 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3017 | |
| 3018 | DECLARE_INSTRUCTION(LongConstant); |
| 3019 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3020 | protected: |
| 3021 | DEFAULT_COPY_CONSTRUCTOR(LongConstant); |
| 3022 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3023 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3024 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3025 | : HConstant(kLongConstant, DataType::Type::kInt64, dex_pc), |
| 3026 | value_(value) { |
| 3027 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3028 | |
| 3029 | const int64_t value_; |
| 3030 | |
| 3031 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3032 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3033 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3034 | class HFloatConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3035 | public: |
| 3036 | float GetValue() const { return value_; } |
| 3037 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3038 | uint64_t GetValueAsUint64() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3039 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3040 | } |
| 3041 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3042 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3043 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 3044 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3045 | } |
| 3046 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3047 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3048 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3049 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3050 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 3051 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3052 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3053 | return std::fpclassify(value_) == FP_ZERO; |
| 3054 | } |
| 3055 | bool IsArithmeticPositiveZero() const { |
| 3056 | return IsArithmeticZero() && !std::signbit(value_); |
| 3057 | } |
| 3058 | bool IsArithmeticNegativeZero() const { |
| 3059 | return IsArithmeticZero() && std::signbit(value_); |
| 3060 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3061 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3062 | 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] | 3063 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3064 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3065 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3066 | } |
| 3067 | bool IsNaN() const { |
| 3068 | return std::isnan(value_); |
| 3069 | } |
| 3070 | |
| 3071 | DECLARE_INSTRUCTION(FloatConstant); |
| 3072 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3073 | protected: |
| 3074 | DEFAULT_COPY_CONSTRUCTOR(FloatConstant); |
| 3075 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3076 | private: |
| 3077 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3078 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3079 | value_(value) { |
| 3080 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3081 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3082 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3083 | value_(bit_cast<float, int32_t>(value)) { |
| 3084 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3085 | |
| 3086 | const float value_; |
| 3087 | |
| 3088 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3089 | friend class SsaBuilder; |
| 3090 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3091 | }; |
| 3092 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3093 | class HDoubleConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3094 | public: |
| 3095 | double GetValue() const { return value_; } |
| 3096 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3097 | uint64_t GetValueAsUint64() const override { return bit_cast<uint64_t, double>(value_); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3098 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3099 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3100 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 3101 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3102 | } |
| 3103 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3104 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3105 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3106 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3107 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 3108 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3109 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3110 | return std::fpclassify(value_) == FP_ZERO; |
| 3111 | } |
| 3112 | bool IsArithmeticPositiveZero() const { |
| 3113 | return IsArithmeticZero() && !std::signbit(value_); |
| 3114 | } |
| 3115 | bool IsArithmeticNegativeZero() const { |
| 3116 | return IsArithmeticZero() && std::signbit(value_); |
| 3117 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3118 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3119 | 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] | 3120 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3121 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3122 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3123 | } |
| 3124 | bool IsNaN() const { |
| 3125 | return std::isnan(value_); |
| 3126 | } |
| 3127 | |
| 3128 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3129 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3130 | protected: |
| 3131 | DEFAULT_COPY_CONSTRUCTOR(DoubleConstant); |
| 3132 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3133 | private: |
| 3134 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3135 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3136 | value_(value) { |
| 3137 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3138 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3139 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3140 | value_(bit_cast<double, int64_t>(value)) { |
| 3141 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3142 | |
| 3143 | const double value_; |
| 3144 | |
| 3145 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3146 | friend class SsaBuilder; |
| 3147 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3148 | }; |
| 3149 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3150 | // Conditional branch. A block ending with an HIf instruction must have |
| 3151 | // two successors. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3152 | class HIf final : public HExpression<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3153 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3154 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3155 | : HExpression(kIf, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3156 | SetRawInputAt(0, input); |
| 3157 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3158 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3159 | bool IsClonable() const override { return true; } |
| 3160 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3161 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3162 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3163 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3167 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3168 | } |
| 3169 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3170 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3171 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3172 | protected: |
| 3173 | DEFAULT_COPY_CONSTRUCTOR(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3174 | }; |
| 3175 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3176 | |
| 3177 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 3178 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 3179 | // non-exceptional control flow. |
| 3180 | // Normal-flow successor is stored at index zero, exception handlers under |
| 3181 | // higher indices in no particular order. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3182 | class HTryBoundary final : public HExpression<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3183 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3184 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3185 | kEntry, |
| 3186 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3187 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3188 | }; |
| 3189 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3190 | // SideEffects::CanTriggerGC prevents instructions with SideEffects::DependOnGC to be alive |
| 3191 | // across the catch block entering edges as GC might happen during throwing an exception. |
| 3192 | // TryBoundary with BoundaryKind::kExit is conservatively used for that as there is no |
| 3193 | // HInstruction which a catch block must start from. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3194 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3195 | : HExpression(kTryBoundary, |
| 3196 | (kind == BoundaryKind::kExit) ? SideEffects::CanTriggerGC() |
| 3197 | : SideEffects::None(), |
| 3198 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3199 | SetPackedField<BoundaryKindField>(kind); |
| 3200 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3201 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3202 | bool IsControlFlow() const override { return true; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3203 | |
| 3204 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3205 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3206 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 3207 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 3208 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 3209 | } |
| 3210 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3211 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 3212 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3213 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 3214 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 3215 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | // If not present already, adds `handler` to its block's list of exception |
| 3219 | // handlers. |
| 3220 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3221 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3222 | GetBlock()->AddSuccessor(handler); |
| 3223 | } |
| 3224 | } |
| 3225 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3226 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 3227 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3228 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3229 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 3230 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3231 | DECLARE_INSTRUCTION(TryBoundary); |
| 3232 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3233 | protected: |
| 3234 | DEFAULT_COPY_CONSTRUCTOR(TryBoundary); |
| 3235 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3236 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3237 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 3238 | static constexpr size_t kFieldBoundaryKindSize = |
| 3239 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 3240 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 3241 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 3242 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 3243 | "Too many packed fields."); |
| 3244 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3245 | }; |
| 3246 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3247 | // Deoptimize to interpreter, upon checking a condition. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3248 | class HDeoptimize final : public HVariableInputSizeInstruction { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3249 | public: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3250 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 3251 | // across. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3252 | HDeoptimize(ArenaAllocator* allocator, |
| 3253 | HInstruction* cond, |
| 3254 | DeoptimizationKind kind, |
| 3255 | uint32_t dex_pc) |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3256 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3257 | kDeoptimize, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3258 | SideEffects::All(), |
| 3259 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3260 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3261 | /* number_of_inputs= */ 1, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3262 | kArenaAllocMisc) { |
| 3263 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 3264 | SetPackedField<DeoptimizeKindField>(kind); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3265 | SetRawInputAt(0, cond); |
| 3266 | } |
| 3267 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3268 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3269 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3270 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3271 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3272 | // instead of `guard`. |
| 3273 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3274 | // at the point of the `HDeoptimize`. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3275 | HDeoptimize(ArenaAllocator* allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3276 | HInstruction* cond, |
| 3277 | HInstruction* guard, |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3278 | DeoptimizationKind kind, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3279 | uint32_t dex_pc) |
| 3280 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3281 | kDeoptimize, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3282 | guard->GetType(), |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3283 | SideEffects::CanTriggerGC(), |
| 3284 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3285 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3286 | /* number_of_inputs= */ 2, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3287 | kArenaAllocMisc) { |
| 3288 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3289 | SetPackedField<DeoptimizeKindField>(kind); |
| 3290 | SetRawInputAt(0, cond); |
| 3291 | SetRawInputAt(1, guard); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3292 | } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3293 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3294 | bool CanBeMoved() const override { return GetPackedFlag<kFieldCanBeMoved>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3295 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3296 | bool InstructionDataEquals(const HInstruction* other) const override { |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3297 | return (other->CanBeMoved() == CanBeMoved()) && (other->AsDeoptimize()->GetKind() == GetKind()); |
| 3298 | } |
| 3299 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3300 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3301 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3302 | bool CanThrow() const override { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3303 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3304 | DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3305 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3306 | bool GuardsAnInput() const { |
| 3307 | return InputCount() == 2; |
| 3308 | } |
| 3309 | |
| 3310 | HInstruction* GuardedInput() const { |
| 3311 | DCHECK(GuardsAnInput()); |
| 3312 | return InputAt(1); |
| 3313 | } |
| 3314 | |
| 3315 | void RemoveGuard() { |
| 3316 | RemoveInputAt(1); |
| 3317 | } |
| 3318 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3319 | DECLARE_INSTRUCTION(Deoptimize); |
| 3320 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3321 | protected: |
| 3322 | DEFAULT_COPY_CONSTRUCTOR(Deoptimize); |
| 3323 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3324 | private: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3325 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3326 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3327 | static constexpr size_t kFieldDeoptimizeKindSize = |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3328 | MinimumBitsToStore(static_cast<size_t>(DeoptimizationKind::kLast)); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3329 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3330 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3331 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3332 | "Too many packed fields."); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3333 | using DeoptimizeKindField = |
| 3334 | BitField<DeoptimizationKind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3335 | }; |
| 3336 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3337 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3338 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3339 | // if it's true, starts to do deoptimization. |
| 3340 | // It has a 4-byte slot on stack. |
| 3341 | // TODO: allocate a register for this flag. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3342 | class HShouldDeoptimizeFlag final : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3343 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3344 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3345 | // with regard to other passes. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3346 | HShouldDeoptimizeFlag(ArenaAllocator* allocator, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3347 | : HVariableInputSizeInstruction(kShouldDeoptimizeFlag, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3348 | DataType::Type::kInt32, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3349 | SideEffects::None(), |
| 3350 | dex_pc, |
| 3351 | allocator, |
| 3352 | 0, |
| 3353 | kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3356 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3357 | // further guard elimination/motion since a guard might have been used for justification |
| 3358 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3359 | // to avoid other optimizations trying to move it. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3360 | bool CanBeMoved() const override { return false; } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3361 | |
| 3362 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3363 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3364 | protected: |
| 3365 | DEFAULT_COPY_CONSTRUCTOR(ShouldDeoptimizeFlag); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3366 | }; |
| 3367 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3368 | // Represents the ArtMethod that was passed as a first argument to |
| 3369 | // the method. It is used by instructions that depend on it, like |
| 3370 | // instructions that work with the dex cache. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3371 | class HCurrentMethod final : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3372 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3373 | explicit HCurrentMethod(DataType::Type type, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3374 | : HExpression(kCurrentMethod, type, SideEffects::None(), dex_pc) { |
| 3375 | } |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3376 | |
| 3377 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3378 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3379 | protected: |
| 3380 | DEFAULT_COPY_CONSTRUCTOR(CurrentMethod); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3381 | }; |
| 3382 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3383 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3384 | // of a class. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3385 | class HClassTableGet final : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3386 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3387 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3388 | kVTable, |
| 3389 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3390 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3391 | }; |
| 3392 | HClassTableGet(HInstruction* cls, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3393 | DataType::Type type, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3394 | TableKind kind, |
| 3395 | size_t index, |
| 3396 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3397 | : HExpression(kClassTableGet, type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3398 | index_(index) { |
| 3399 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3400 | SetRawInputAt(0, cls); |
| 3401 | } |
| 3402 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3403 | bool IsClonable() const override { return true; } |
| 3404 | bool CanBeMoved() const override { return true; } |
| 3405 | bool InstructionDataEquals(const HInstruction* other) const override { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3406 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3407 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3408 | } |
| 3409 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3410 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3411 | size_t GetIndex() const { return index_; } |
| 3412 | |
| 3413 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3414 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3415 | protected: |
| 3416 | DEFAULT_COPY_CONSTRUCTOR(ClassTableGet); |
| 3417 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3418 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3419 | static constexpr size_t kFieldTableKind = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3420 | static constexpr size_t kFieldTableKindSize = |
| 3421 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3422 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3423 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3424 | "Too many packed fields."); |
| 3425 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3426 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3427 | // The index of the ArtMethod in the table. |
| 3428 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3429 | }; |
| 3430 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3431 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3432 | // have one successor for each entry in the switch table, and the final successor |
| 3433 | // will be the block containing the next Dex opcode. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3434 | class HPackedSwitch final : public HExpression<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3435 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3436 | HPackedSwitch(int32_t start_value, |
| 3437 | uint32_t num_entries, |
| 3438 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3439 | uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3440 | : HExpression(kPackedSwitch, SideEffects::None(), dex_pc), |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3441 | start_value_(start_value), |
| 3442 | num_entries_(num_entries) { |
| 3443 | SetRawInputAt(0, input); |
| 3444 | } |
| 3445 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3446 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3447 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3448 | bool IsControlFlow() const override { return true; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3449 | |
| 3450 | int32_t GetStartValue() const { return start_value_; } |
| 3451 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3452 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3453 | |
| 3454 | HBasicBlock* GetDefaultBlock() const { |
| 3455 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3456 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3457 | } |
| 3458 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3459 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3460 | protected: |
| 3461 | DEFAULT_COPY_CONSTRUCTOR(PackedSwitch); |
| 3462 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3463 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3464 | const int32_t start_value_; |
| 3465 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3466 | }; |
| 3467 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3468 | class HUnaryOperation : public HExpression<1> { |
| 3469 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3470 | HUnaryOperation(InstructionKind kind, |
| 3471 | DataType::Type result_type, |
| 3472 | HInstruction* input, |
| 3473 | uint32_t dex_pc = kNoDexPc) |
| 3474 | : HExpression(kind, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3475 | SetRawInputAt(0, input); |
| 3476 | } |
| 3477 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3478 | // All of the UnaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3479 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3480 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3481 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3482 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3483 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3484 | bool CanBeMoved() const override { return true; } |
| 3485 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3486 | return true; |
| 3487 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3488 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3489 | // Try to statically evaluate `this` and return a HConstant |
| 3490 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3491 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3492 | HConstant* TryStaticEvaluation() const; |
| 3493 | |
| 3494 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3495 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3496 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3497 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3498 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3499 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3500 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3501 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3502 | protected: |
| 3503 | DEFAULT_COPY_CONSTRUCTOR(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3504 | }; |
| 3505 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3506 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3507 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3508 | HBinaryOperation(InstructionKind kind, |
| 3509 | DataType::Type result_type, |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3510 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3511 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3512 | SideEffects side_effects = SideEffects::None(), |
| 3513 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3514 | : HExpression(kind, result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3515 | SetRawInputAt(0, left); |
| 3516 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3517 | } |
| 3518 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3519 | // All of the BinaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3520 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3521 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3522 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3523 | HInstruction* GetRight() const { return InputAt(1); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3524 | DataType::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3525 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3526 | virtual bool IsCommutative() const { return false; } |
| 3527 | |
| 3528 | // Put constant on the right. |
| 3529 | // Returns whether order is changed. |
| 3530 | bool OrderInputsWithConstantOnTheRight() { |
| 3531 | HInstruction* left = InputAt(0); |
| 3532 | HInstruction* right = InputAt(1); |
| 3533 | if (left->IsConstant() && !right->IsConstant()) { |
| 3534 | ReplaceInput(right, 0); |
| 3535 | ReplaceInput(left, 1); |
| 3536 | return true; |
| 3537 | } |
| 3538 | return false; |
| 3539 | } |
| 3540 | |
| 3541 | // Order inputs by instruction id, but favor constant on the right side. |
| 3542 | // This helps GVN for commutative ops. |
| 3543 | void OrderInputs() { |
| 3544 | DCHECK(IsCommutative()); |
| 3545 | HInstruction* left = InputAt(0); |
| 3546 | HInstruction* right = InputAt(1); |
| 3547 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3548 | return; |
| 3549 | } |
| 3550 | if (OrderInputsWithConstantOnTheRight()) { |
| 3551 | return; |
| 3552 | } |
| 3553 | // Order according to instruction id. |
| 3554 | if (left->GetId() > right->GetId()) { |
| 3555 | ReplaceInput(right, 0); |
| 3556 | ReplaceInput(left, 1); |
| 3557 | } |
| 3558 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3559 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3560 | bool CanBeMoved() const override { return true; } |
| 3561 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3562 | return true; |
| 3563 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3564 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3565 | // Try to statically evaluate `this` and return a HConstant |
| 3566 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3567 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3568 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3569 | |
| 3570 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3571 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3572 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3573 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3574 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3575 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3576 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3577 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3578 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3579 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3580 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3581 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3582 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3583 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3584 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3585 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3586 | // 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] | 3587 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3588 | HConstant* GetConstantRight() const; |
| 3589 | |
| 3590 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3591 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3592 | HInstruction* GetLeastConstantLeft() const; |
| 3593 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3594 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3595 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3596 | protected: |
| 3597 | DEFAULT_COPY_CONSTRUCTOR(BinaryOperation); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3598 | }; |
| 3599 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3600 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3601 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3602 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3603 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3604 | kGtBias, // return 1 for NaN comparisons |
| 3605 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3606 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3607 | }; |
| 3608 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3609 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3610 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3611 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3612 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3613 | HCondition(InstructionKind kind, |
| 3614 | HInstruction* first, |
| 3615 | HInstruction* second, |
| 3616 | uint32_t dex_pc = kNoDexPc) |
| 3617 | : HBinaryOperation(kind, |
| 3618 | DataType::Type::kBool, |
| 3619 | first, |
| 3620 | second, |
| 3621 | SideEffects::None(), |
| 3622 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3623 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3624 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3625 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3626 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3627 | // `instruction`, and disregard moves in between. |
| 3628 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3629 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3630 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3631 | |
| 3632 | virtual IfCondition GetCondition() const = 0; |
| 3633 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3634 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3635 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3636 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3637 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3638 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3639 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3640 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3641 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3642 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3643 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3644 | } |
| 3645 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3646 | bool IsFPConditionTrueIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3647 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3648 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3649 | if (if_cond == kCondNE) { |
| 3650 | return true; |
| 3651 | } else if (if_cond == kCondEQ) { |
| 3652 | return false; |
| 3653 | } |
| 3654 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | bool IsFPConditionFalseIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3658 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3659 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3660 | if (if_cond == kCondEQ) { |
| 3661 | return true; |
| 3662 | } else if (if_cond == kCondNE) { |
| 3663 | return false; |
| 3664 | } |
| 3665 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3666 | } |
| 3667 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3668 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3669 | // Needed if we merge a HCompare into a HCondition. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3670 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3671 | static constexpr size_t kFieldComparisonBiasSize = |
| 3672 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3673 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3674 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3675 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3676 | using ComparisonBiasField = |
| 3677 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3678 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3679 | template <typename T> |
| 3680 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3681 | |
| 3682 | template <typename T> |
| 3683 | int32_t CompareFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3684 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3685 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3686 | // Handle the bias. |
| 3687 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3688 | } |
| 3689 | |
| 3690 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3691 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3692 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3693 | } |
| 3694 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3695 | DEFAULT_COPY_CONSTRUCTOR(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3696 | }; |
| 3697 | |
| 3698 | // Instruction to check if two inputs are equal to each other. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3699 | class HEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3700 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3701 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3702 | : HCondition(kEqual, first, second, dex_pc) { |
| 3703 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3704 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3705 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3706 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3707 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3708 | HNullConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3709 | return MakeConstantCondition(true, GetDexPc()); |
| 3710 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3711 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3712 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3713 | } |
| 3714 | // In the following Evaluate methods, a HCompare instruction has |
| 3715 | // been merged into this HEqual instruction; evaluate it as |
| 3716 | // `Compare(x, y) == 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3717 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3718 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3719 | GetDexPc()); |
| 3720 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3721 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3722 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3723 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3724 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3725 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3726 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3727 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3728 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3729 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3730 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3731 | return kCondEQ; |
| 3732 | } |
| 3733 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3734 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3735 | return kCondNE; |
| 3736 | } |
| 3737 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3738 | protected: |
| 3739 | DEFAULT_COPY_CONSTRUCTOR(Equal); |
| 3740 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3741 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3742 | 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] | 3743 | }; |
| 3744 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3745 | class HNotEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3746 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3747 | HNotEqual(HInstruction* first, HInstruction* second, |
| 3748 | uint32_t dex_pc = kNoDexPc) |
| 3749 | : HCondition(kNotEqual, first, second, dex_pc) { |
| 3750 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3751 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3752 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3753 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3754 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3755 | HNullConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3756 | return MakeConstantCondition(false, GetDexPc()); |
| 3757 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3758 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3759 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3760 | } |
| 3761 | // In the following Evaluate methods, a HCompare instruction has |
| 3762 | // been merged into this HNotEqual instruction; evaluate it as |
| 3763 | // `Compare(x, y) != 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3764 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3765 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3766 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3767 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3768 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3769 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3770 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3771 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3772 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3773 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3774 | DECLARE_INSTRUCTION(NotEqual); |
| 3775 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3776 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3777 | return kCondNE; |
| 3778 | } |
| 3779 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3780 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3781 | return kCondEQ; |
| 3782 | } |
| 3783 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3784 | protected: |
| 3785 | DEFAULT_COPY_CONSTRUCTOR(NotEqual); |
| 3786 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3787 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3788 | 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] | 3789 | }; |
| 3790 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3791 | class HLessThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3792 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3793 | HLessThan(HInstruction* first, HInstruction* second, |
| 3794 | uint32_t dex_pc = kNoDexPc) |
| 3795 | : HCondition(kLessThan, first, second, dex_pc) { |
| 3796 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3797 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3798 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3799 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3800 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3801 | // In the following Evaluate methods, a HCompare instruction has |
| 3802 | // been merged into this HLessThan instruction; evaluate it as |
| 3803 | // `Compare(x, y) < 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3804 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3805 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3806 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3807 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3808 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3809 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3810 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3811 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3812 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3813 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3814 | DECLARE_INSTRUCTION(LessThan); |
| 3815 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3816 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3817 | return kCondLT; |
| 3818 | } |
| 3819 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3820 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3821 | return kCondGE; |
| 3822 | } |
| 3823 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3824 | protected: |
| 3825 | DEFAULT_COPY_CONSTRUCTOR(LessThan); |
| 3826 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3827 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3828 | 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] | 3829 | }; |
| 3830 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3831 | class HLessThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3832 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3833 | HLessThanOrEqual(HInstruction* first, HInstruction* second, |
| 3834 | uint32_t dex_pc = kNoDexPc) |
| 3835 | : HCondition(kLessThanOrEqual, first, second, dex_pc) { |
| 3836 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3837 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3838 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3839 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3840 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3841 | // In the following Evaluate methods, a HCompare instruction has |
| 3842 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3843 | // `Compare(x, y) <= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3844 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3845 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3846 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3847 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3848 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3849 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3850 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3851 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3852 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3853 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3854 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3855 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3856 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3857 | return kCondLE; |
| 3858 | } |
| 3859 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3860 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3861 | return kCondGT; |
| 3862 | } |
| 3863 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3864 | protected: |
| 3865 | DEFAULT_COPY_CONSTRUCTOR(LessThanOrEqual); |
| 3866 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3867 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3868 | 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] | 3869 | }; |
| 3870 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3871 | class HGreaterThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3872 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3873 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3874 | : HCondition(kGreaterThan, first, second, dex_pc) { |
| 3875 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3876 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3877 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3878 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3879 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3880 | // In the following Evaluate methods, a HCompare instruction has |
| 3881 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3882 | // `Compare(x, y) > 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3883 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3884 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3885 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3886 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3887 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3888 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3889 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3890 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3891 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3892 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3893 | DECLARE_INSTRUCTION(GreaterThan); |
| 3894 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3895 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3896 | return kCondGT; |
| 3897 | } |
| 3898 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3899 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3900 | return kCondLE; |
| 3901 | } |
| 3902 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3903 | protected: |
| 3904 | DEFAULT_COPY_CONSTRUCTOR(GreaterThan); |
| 3905 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3906 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3907 | 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] | 3908 | }; |
| 3909 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3910 | class HGreaterThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3911 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3912 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3913 | : HCondition(kGreaterThanOrEqual, first, second, dex_pc) { |
| 3914 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3915 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3916 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3917 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3918 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3919 | // In the following Evaluate methods, a HCompare instruction has |
| 3920 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3921 | // `Compare(x, y) >= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3922 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3923 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3924 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3925 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3926 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3927 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3928 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3929 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3930 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3931 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3932 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3933 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3934 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3935 | return kCondGE; |
| 3936 | } |
| 3937 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3938 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3939 | return kCondLT; |
| 3940 | } |
| 3941 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3942 | protected: |
| 3943 | DEFAULT_COPY_CONSTRUCTOR(GreaterThanOrEqual); |
| 3944 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3945 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3946 | 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] | 3947 | }; |
| 3948 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3949 | class HBelow final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3950 | public: |
| 3951 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3952 | : HCondition(kBelow, first, second, dex_pc) { |
| 3953 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3954 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3955 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3956 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3957 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3958 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3959 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3960 | } |
| 3961 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3962 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3963 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3964 | UNREACHABLE(); |
| 3965 | } |
| 3966 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3967 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3968 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3969 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | DECLARE_INSTRUCTION(Below); |
| 3973 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3974 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3975 | return kCondB; |
| 3976 | } |
| 3977 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3978 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3979 | return kCondAE; |
| 3980 | } |
| 3981 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3982 | protected: |
| 3983 | DEFAULT_COPY_CONSTRUCTOR(Below); |
| 3984 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3985 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3986 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3987 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3988 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3989 | }; |
| 3990 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3991 | class HBelowOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3992 | public: |
| 3993 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3994 | : HCondition(kBelowOrEqual, first, second, dex_pc) { |
| 3995 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3996 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3997 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3998 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3999 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4000 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4001 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4002 | } |
| 4003 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4004 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4005 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4006 | UNREACHABLE(); |
| 4007 | } |
| 4008 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4009 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4010 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4011 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 4015 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4016 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4017 | return kCondBE; |
| 4018 | } |
| 4019 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4020 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4021 | return kCondA; |
| 4022 | } |
| 4023 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4024 | protected: |
| 4025 | DEFAULT_COPY_CONSTRUCTOR(BelowOrEqual); |
| 4026 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4027 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4028 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4029 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 4030 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4031 | }; |
| 4032 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4033 | class HAbove final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4034 | public: |
| 4035 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4036 | : HCondition(kAbove, first, second, dex_pc) { |
| 4037 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4038 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4039 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4040 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4041 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4042 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4043 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4044 | } |
| 4045 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4046 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4047 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4048 | UNREACHABLE(); |
| 4049 | } |
| 4050 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4051 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4052 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4053 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4054 | } |
| 4055 | |
| 4056 | DECLARE_INSTRUCTION(Above); |
| 4057 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4058 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4059 | return kCondA; |
| 4060 | } |
| 4061 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4062 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4063 | return kCondBE; |
| 4064 | } |
| 4065 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4066 | protected: |
| 4067 | DEFAULT_COPY_CONSTRUCTOR(Above); |
| 4068 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4069 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4070 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4071 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 4072 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4073 | }; |
| 4074 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4075 | class HAboveOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4076 | public: |
| 4077 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4078 | : HCondition(kAboveOrEqual, first, second, dex_pc) { |
| 4079 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4080 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4081 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4082 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4083 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4084 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4085 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4086 | } |
| 4087 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4088 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4089 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4090 | UNREACHABLE(); |
| 4091 | } |
| 4092 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4093 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4094 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4095 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 4099 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4100 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4101 | return kCondAE; |
| 4102 | } |
| 4103 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4104 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4105 | return kCondB; |
| 4106 | } |
| 4107 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4108 | protected: |
| 4109 | DEFAULT_COPY_CONSTRUCTOR(AboveOrEqual); |
| 4110 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4111 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4112 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4113 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 4114 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4115 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4116 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4117 | // Instruction to check how two inputs compare to each other. |
| 4118 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4119 | class HCompare final : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4120 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4121 | // Note that `comparison_type` is the type of comparison performed |
| 4122 | // between the comparison's inputs, not the type of the instantiated |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4123 | // HCompare instruction (which is always DataType::Type::kInt). |
| 4124 | HCompare(DataType::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4125 | HInstruction* first, |
| 4126 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4127 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4128 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4129 | : HBinaryOperation(kCompare, |
| 4130 | DataType::Type::kInt32, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4131 | first, |
| 4132 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4133 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4134 | dex_pc) { |
| 4135 | SetPackedField<ComparisonBiasField>(bias); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4136 | DCHECK_EQ(comparison_type, DataType::Kind(first->GetType())); |
| 4137 | DCHECK_EQ(comparison_type, DataType::Kind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4138 | } |
| 4139 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4140 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4141 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 4142 | |
| 4143 | template <typename T> |
| 4144 | int32_t ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4145 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4146 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 4147 | // Handle the bias. |
| 4148 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 4149 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4150 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4151 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4152 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 4153 | // reach this code path when processing a freshly built HIR |
| 4154 | // graph. However HCompare integer instructions can be synthesized |
| 4155 | // by the instruction simplifier to implement IntegerCompare and |
| 4156 | // IntegerSignum intrinsics, so we have to handle this case. |
| 4157 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4158 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4159 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4160 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4161 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4162 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4163 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4164 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4165 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4166 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4167 | } |
| 4168 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4169 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4170 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4171 | } |
| 4172 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4173 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4174 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4175 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4176 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4177 | bool IsGtBias() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4178 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4179 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4180 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4181 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4182 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type type ATTRIBUTE_UNUSED) { |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 4183 | // Comparisons do not require a runtime call in any back end. |
| 4184 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4185 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4186 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4187 | DECLARE_INSTRUCTION(Compare); |
| 4188 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4189 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4190 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4191 | static constexpr size_t kFieldComparisonBiasSize = |
| 4192 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 4193 | static constexpr size_t kNumberOfComparePackedBits = |
| 4194 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 4195 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4196 | using ComparisonBiasField = |
| 4197 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 4198 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4199 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 4200 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 4201 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 4202 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 4203 | } |
| 4204 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4205 | DEFAULT_COPY_CONSTRUCTOR(Compare); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4206 | }; |
| 4207 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4208 | class HNewInstance final : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4209 | public: |
| 4210 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4211 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4212 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4213 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4214 | bool finalizable, |
| 4215 | QuickEntrypointEnum entrypoint) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4216 | : HExpression(kNewInstance, |
| 4217 | DataType::Type::kReference, |
| 4218 | SideEffects::CanTriggerGC(), |
| 4219 | dex_pc), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4220 | type_index_(type_index), |
| 4221 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4222 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4223 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4224 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4225 | } |
| 4226 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4227 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4228 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4229 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4230 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4231 | |
| 4232 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4233 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4234 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4235 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4236 | bool CanThrow() const override { return true; } |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4237 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4238 | bool NeedsChecks() const { |
| 4239 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 4240 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4241 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4242 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4243 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4244 | bool CanBeNull() const override { return false; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4245 | |
| 4246 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4247 | |
| 4248 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 4249 | entrypoint_ = entrypoint; |
| 4250 | } |
| 4251 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4252 | HLoadClass* GetLoadClass() const { |
| 4253 | HInstruction* input = InputAt(0); |
| 4254 | if (input->IsClinitCheck()) { |
| 4255 | input = input->InputAt(0); |
| 4256 | } |
| 4257 | DCHECK(input->IsLoadClass()); |
| 4258 | return input->AsLoadClass(); |
| 4259 | } |
| 4260 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4261 | bool IsStringAlloc() const; |
| 4262 | |
| 4263 | DECLARE_INSTRUCTION(NewInstance); |
| 4264 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4265 | protected: |
| 4266 | DEFAULT_COPY_CONSTRUCTOR(NewInstance); |
| 4267 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4268 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4269 | static constexpr size_t kFlagFinalizable = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4270 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 4271 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 4272 | "Too many packed fields."); |
| 4273 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4274 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4275 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4276 | QuickEntrypointEnum entrypoint_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4277 | }; |
| 4278 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 4279 | enum IntrinsicNeedsEnvironmentOrCache { |
| 4280 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 4281 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4282 | }; |
| 4283 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4284 | enum IntrinsicSideEffects { |
| 4285 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 4286 | kReadSideEffects, // Intrinsic may read heap memory. |
| 4287 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 4288 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 4289 | }; |
| 4290 | |
| 4291 | enum IntrinsicExceptions { |
| 4292 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 4293 | kCanThrow // Intrinsic may throw exceptions. |
| 4294 | }; |
| 4295 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4296 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4297 | public: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4298 | bool NeedsEnvironment() const override; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4299 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 4300 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4301 | SetRawInputAt(index, argument); |
| 4302 | } |
| 4303 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4304 | // Return the number of arguments. This number can be lower than |
| 4305 | // the number of inputs returned by InputCount(), as some invoke |
| 4306 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 4307 | // inputs at the end of their list of inputs. |
| 4308 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 4309 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4310 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4311 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4312 | InvokeType GetInvokeType() const { |
| 4313 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4314 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4315 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 4316 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4317 | return intrinsic_; |
| 4318 | } |
| 4319 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4320 | void SetIntrinsic(Intrinsics intrinsic, |
| 4321 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 4322 | IntrinsicSideEffects side_effects, |
| 4323 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4324 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4325 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4326 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4327 | } |
| 4328 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4329 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4330 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4331 | bool CanThrow() const override { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4332 | |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4333 | void SetAlwaysThrows(bool always_throws) { SetPackedFlag<kFlagAlwaysThrows>(always_throws); } |
| 4334 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4335 | bool AlwaysThrows() const override { return GetPackedFlag<kFlagAlwaysThrows>(); } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4336 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4337 | bool CanBeMoved() const override { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4338 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4339 | bool InstructionDataEquals(const HInstruction* other) const override { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4340 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 4341 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4342 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4343 | uint32_t* GetIntrinsicOptimizations() { |
| 4344 | return &intrinsic_optimizations_; |
| 4345 | } |
| 4346 | |
| 4347 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4348 | return &intrinsic_optimizations_; |
| 4349 | } |
| 4350 | |
| 4351 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4352 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4353 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 4354 | void SetResolvedMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4355 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4356 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4357 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4358 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4359 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4360 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4361 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4362 | static constexpr size_t kFlagCanThrow = kFieldInvokeType + kFieldInvokeTypeSize; |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4363 | static constexpr size_t kFlagAlwaysThrows = kFlagCanThrow + 1; |
| 4364 | static constexpr size_t kNumberOfInvokePackedBits = kFlagAlwaysThrows + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4365 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4366 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4367 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4368 | HInvoke(InstructionKind kind, |
| 4369 | ArenaAllocator* allocator, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4370 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4371 | uint32_t number_of_other_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4372 | DataType::Type return_type, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4373 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4374 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4375 | ArtMethod* resolved_method, |
| 4376 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4377 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4378 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4379 | return_type, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4380 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4381 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4382 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4383 | number_of_arguments + number_of_other_inputs, |
| 4384 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4385 | number_of_arguments_(number_of_arguments), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4386 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4387 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4388 | intrinsic_optimizations_(0) { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4389 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4390 | SetPackedFlag<kFlagCanThrow>(true); |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 4391 | // Check mutator lock, constructors lack annotalysis support. |
| 4392 | Locks::mutator_lock_->AssertNotExclusiveHeld(Thread::Current()); |
| 4393 | SetResolvedMethod(resolved_method); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4394 | } |
| 4395 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4396 | DEFAULT_COPY_CONSTRUCTOR(Invoke); |
| 4397 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4398 | uint32_t number_of_arguments_; |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4399 | ArtMethod* resolved_method_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4400 | const uint32_t dex_method_index_; |
| 4401 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4402 | |
| 4403 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4404 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4405 | }; |
| 4406 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4407 | class HInvokeUnresolved final : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4408 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4409 | HInvokeUnresolved(ArenaAllocator* allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4410 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4411 | DataType::Type return_type, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4412 | uint32_t dex_pc, |
| 4413 | uint32_t dex_method_index, |
| 4414 | InvokeType invoke_type) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4415 | : HInvoke(kInvokeUnresolved, |
| 4416 | allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4417 | number_of_arguments, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4418 | /* number_of_other_inputs= */ 0u, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4419 | return_type, |
| 4420 | dex_pc, |
| 4421 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4422 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4423 | invoke_type) { |
| 4424 | } |
| 4425 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4426 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4427 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4428 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4429 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4430 | protected: |
| 4431 | DEFAULT_COPY_CONSTRUCTOR(InvokeUnresolved); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4432 | }; |
| 4433 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4434 | class HInvokePolymorphic final : public HInvoke { |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4435 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4436 | HInvokePolymorphic(ArenaAllocator* allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4437 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4438 | DataType::Type return_type, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4439 | uint32_t dex_pc, |
| 4440 | uint32_t dex_method_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4441 | : HInvoke(kInvokePolymorphic, |
| 4442 | allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4443 | number_of_arguments, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4444 | /* number_of_other_inputs= */ 0u, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4445 | return_type, |
| 4446 | dex_pc, |
| 4447 | dex_method_index, |
| 4448 | nullptr, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4449 | kVirtual) { |
| 4450 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4451 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4452 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4453 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4454 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4455 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4456 | protected: |
| 4457 | DEFAULT_COPY_CONSTRUCTOR(InvokePolymorphic); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4458 | }; |
| 4459 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4460 | class HInvokeCustom final : public HInvoke { |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4461 | public: |
| 4462 | HInvokeCustom(ArenaAllocator* allocator, |
| 4463 | uint32_t number_of_arguments, |
| 4464 | uint32_t call_site_index, |
| 4465 | DataType::Type return_type, |
| 4466 | uint32_t dex_pc) |
| 4467 | : HInvoke(kInvokeCustom, |
| 4468 | allocator, |
| 4469 | number_of_arguments, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4470 | /* number_of_other_inputs= */ 0u, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4471 | return_type, |
| 4472 | dex_pc, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4473 | /* dex_method_index= */ dex::kDexNoIndex, |
| 4474 | /* resolved_method= */ nullptr, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4475 | kStatic), |
| 4476 | call_site_index_(call_site_index) { |
| 4477 | } |
| 4478 | |
| 4479 | uint32_t GetCallSiteIndex() const { return call_site_index_; } |
| 4480 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4481 | bool IsClonable() const override { return true; } |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4482 | |
| 4483 | DECLARE_INSTRUCTION(InvokeCustom); |
| 4484 | |
| 4485 | protected: |
| 4486 | DEFAULT_COPY_CONSTRUCTOR(InvokeCustom); |
| 4487 | |
| 4488 | private: |
| 4489 | uint32_t call_site_index_; |
| 4490 | }; |
| 4491 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4492 | class HInvokeStaticOrDirect final : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4493 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4494 | // Requirements of this method call regarding the class |
| 4495 | // initialization (clinit) check of its declaring class. |
| 4496 | enum class ClinitCheckRequirement { |
| 4497 | kNone, // Class already initialized. |
| 4498 | kExplicit, // Static call having explicit clinit check as last input. |
| 4499 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4500 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4501 | }; |
| 4502 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4503 | // Determines how to load the target ArtMethod*. |
| 4504 | enum class MethodLoadKind { |
| 4505 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4506 | kStringInit, |
| 4507 | |
| 4508 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4509 | kRecursive, |
| 4510 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4511 | // Use PC-relative boot image ArtMethod* address that will be known at link time. |
| 4512 | // Used for boot image methods referenced by boot image code. |
| 4513 | kBootImageLinkTimePcRelative, |
| 4514 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4515 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| 4516 | // Used for app->boot calls with relocatable image. |
| 4517 | kBootImageRelRo, |
| 4518 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4519 | // Load from an entry in the .bss section using a PC-relative load. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4520 | // Used for methods outside boot image referenced by AOT-compiled app and boot image code. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4521 | kBssEntry, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4522 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4523 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4524 | // Used for for JIT-compiled calls. |
| 4525 | kJitDirectAddress, |
| 4526 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4527 | // Make a runtime call to resolve and call the method. This is the last-resort-kind |
| 4528 | // used when other kinds are unimplemented on a particular architecture. |
| 4529 | kRuntimeCall, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4530 | }; |
| 4531 | |
| 4532 | // Determines the location of the code pointer. |
| 4533 | enum class CodePtrLocation { |
| 4534 | // Recursive call, use local PC-relative call instruction. |
| 4535 | kCallSelf, |
| 4536 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4537 | // Use code pointer from the ArtMethod*. |
| 4538 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4539 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4540 | kCallArtMethod, |
| 4541 | }; |
| 4542 | |
| 4543 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4544 | MethodLoadKind method_load_kind; |
| 4545 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4546 | // The method load data holds |
| 4547 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4548 | // Note that there are multiple string init methods, each having its own offset. |
| 4549 | // - the method address for kDirectAddress |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4550 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4551 | }; |
| 4552 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4553 | HInvokeStaticOrDirect(ArenaAllocator* allocator, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4554 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4555 | DataType::Type return_type, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4556 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4557 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4558 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4559 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4560 | InvokeType invoke_type, |
| 4561 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4562 | ClinitCheckRequirement clinit_check_requirement) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4563 | : HInvoke(kInvokeStaticOrDirect, |
| 4564 | allocator, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4565 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4566 | // There is potentially one extra argument for the HCurrentMethod node, and |
Nicolas Geoffray | 0846a8f | 2018-09-12 15:21:07 +0100 | [diff] [blame] | 4567 | // potentially one other if the clinit check is explicit. |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4568 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4569 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4570 | return_type, |
| 4571 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4572 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4573 | resolved_method, |
| 4574 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4575 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4576 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4577 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4578 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4579 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4580 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4581 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4582 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4583 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4584 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4585 | |
| 4586 | // Using the current method is the default and once we find a better |
| 4587 | // method load kind, we should not go back to using the current method. |
| 4588 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4589 | |
| 4590 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4591 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4592 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4593 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4594 | dispatch_info_ = dispatch_info; |
| 4595 | } |
| 4596 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 4597 | DispatchInfo GetDispatchInfo() const { |
| 4598 | return dispatch_info_; |
| 4599 | } |
| 4600 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4601 | void AddSpecialInput(HInstruction* input) { |
| 4602 | // We allow only one special input. |
| 4603 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4604 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4605 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4606 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4607 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4608 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4609 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4610 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4611 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4612 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4613 | DCHECK(!input_records.empty()); |
| 4614 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4615 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4616 | // Note: `last_input` may be null during arguments setup. |
| 4617 | if (last_input != nullptr) { |
| 4618 | // `last_input` is the last input of a static invoke marked as having |
| 4619 | // an explicit clinit check. It must either be: |
| 4620 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4621 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4622 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4623 | } |
| 4624 | } |
| 4625 | return input_records; |
| 4626 | } |
| 4627 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4628 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4629 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4630 | // TODO: for intrinsics we can generate implicit null checks. |
| 4631 | return false; |
| 4632 | } |
| 4633 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4634 | bool CanBeNull() const override { |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4635 | return GetType() == DataType::Type::kReference && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4636 | } |
| 4637 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4638 | // Get the index of the special input, if any. |
| 4639 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4640 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4641 | // method pointer; otherwise there may be one platform-specific special input, |
| 4642 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4643 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4644 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4645 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4646 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4647 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4648 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4649 | bool NeedsDexCacheOfDeclaringClass() const override; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4650 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4651 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kJitDirectAddress; } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4652 | bool HasPcRelativeMethodLoadKind() const { |
| 4653 | return GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4654 | GetMethodLoadKind() == MethodLoadKind::kBootImageRelRo || |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4655 | GetMethodLoadKind() == MethodLoadKind::kBssEntry; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4656 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4657 | bool HasCurrentMethodInput() const { |
| 4658 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4659 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4660 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4661 | return true; |
| 4662 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4663 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4664 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4665 | return false; |
| 4666 | } |
| 4667 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4668 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4669 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4670 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4671 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | uint64_t GetMethodAddress() const { |
| 4675 | DCHECK(HasMethodAddress()); |
| 4676 | return dispatch_info_.method_load_data; |
| 4677 | } |
| 4678 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4679 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4680 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4681 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4682 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4683 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4684 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4685 | // Is this instruction a call to a static method? |
| 4686 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4687 | return GetInvokeType() == kStatic; |
| 4688 | } |
| 4689 | |
| 4690 | MethodReference GetTargetMethod() const { |
| 4691 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4692 | } |
| 4693 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4694 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4695 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4696 | // instruction; only relevant for static calls with explicit clinit check. |
| 4697 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4698 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4699 | size_t last_input_index = inputs_.size() - 1u; |
| 4700 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4701 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4702 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4703 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4704 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4705 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4706 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | // 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] | 4710 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4711 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4712 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4713 | } |
| 4714 | |
| 4715 | // Is this a call to a static method whose declaring class has an |
| 4716 | // implicit intialization check requirement? |
| 4717 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4718 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4719 | } |
| 4720 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4721 | // Does this method load kind need the current method as an input? |
| 4722 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4723 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kRuntimeCall; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4726 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4727 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4728 | protected: |
| 4729 | DEFAULT_COPY_CONSTRUCTOR(InvokeStaticOrDirect); |
| 4730 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4731 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4732 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4733 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4734 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4735 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4736 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4737 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4738 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4739 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4740 | kFieldClinitCheckRequirement, |
| 4741 | kFieldClinitCheckRequirementSize>; |
| 4742 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4743 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | ea179f4 | 2018-02-08 22:30:18 +0000 | [diff] [blame] | 4744 | const MethodReference target_method_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4745 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4746 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4747 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4748 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4749 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4750 | class HInvokeVirtual final : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4751 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4752 | HInvokeVirtual(ArenaAllocator* allocator, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4753 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4754 | DataType::Type return_type, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4755 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4756 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4757 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4758 | uint32_t vtable_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4759 | : HInvoke(kInvokeVirtual, |
| 4760 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4761 | number_of_arguments, |
| 4762 | 0u, |
| 4763 | return_type, |
| 4764 | dex_pc, |
| 4765 | dex_method_index, |
| 4766 | resolved_method, |
| 4767 | kVirtual), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4768 | vtable_index_(vtable_index) { |
| 4769 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4770 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4771 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4772 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4773 | bool CanBeNull() const override { |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4774 | switch (GetIntrinsic()) { |
| 4775 | case Intrinsics::kThreadCurrentThread: |
| 4776 | case Intrinsics::kStringBufferAppend: |
| 4777 | case Intrinsics::kStringBufferToString: |
| 4778 | case Intrinsics::kStringBuilderAppend: |
| 4779 | case Intrinsics::kStringBuilderToString: |
| 4780 | return false; |
| 4781 | default: |
| 4782 | return HInvoke::CanBeNull(); |
| 4783 | } |
| 4784 | } |
| 4785 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4786 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4787 | // TODO: Add implicit null checks in intrinsics. |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 4788 | return (obj == InputAt(0)) && !IsIntrinsic(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4789 | } |
| 4790 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4791 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4792 | |
| 4793 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4794 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4795 | protected: |
| 4796 | DEFAULT_COPY_CONSTRUCTOR(InvokeVirtual); |
| 4797 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4798 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4799 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4800 | const uint32_t vtable_index_; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4801 | }; |
| 4802 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4803 | class HInvokeInterface final : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4804 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4805 | HInvokeInterface(ArenaAllocator* allocator, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4806 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4807 | DataType::Type return_type, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4808 | uint32_t dex_pc, |
| 4809 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4810 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4811 | uint32_t imt_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4812 | : HInvoke(kInvokeInterface, |
| 4813 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4814 | number_of_arguments, |
| 4815 | 0u, |
| 4816 | return_type, |
| 4817 | dex_pc, |
| 4818 | dex_method_index, |
| 4819 | resolved_method, |
| 4820 | kInterface), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4821 | imt_index_(imt_index) { |
| 4822 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4823 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4824 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4825 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4826 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4827 | // TODO: Add implicit null checks in intrinsics. |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 4828 | return (obj == InputAt(0)) && !IsIntrinsic(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4829 | } |
| 4830 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4831 | bool NeedsDexCacheOfDeclaringClass() const override { |
Nicolas Geoffray | fbdfa6d | 2017-02-03 10:43:13 +0000 | [diff] [blame] | 4832 | // The assembly stub currently needs it. |
| 4833 | return true; |
| 4834 | } |
| 4835 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4836 | uint32_t GetImtIndex() const { return imt_index_; } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4837 | |
| 4838 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4839 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4840 | protected: |
| 4841 | DEFAULT_COPY_CONSTRUCTOR(InvokeInterface); |
| 4842 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4843 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4844 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4845 | const uint32_t imt_index_; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4846 | }; |
| 4847 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4848 | class HNeg final : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4849 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4850 | 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] | 4851 | : HUnaryOperation(kNeg, result_type, input, dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4852 | DCHECK_EQ(result_type, DataType::Kind(input->GetType())); |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4853 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4854 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4855 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4856 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4857 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4858 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4859 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4860 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4861 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4862 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4863 | HConstant* Evaluate(HFloatConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4864 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4865 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4866 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4867 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4868 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4869 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4870 | DECLARE_INSTRUCTION(Neg); |
| 4871 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4872 | protected: |
| 4873 | DEFAULT_COPY_CONSTRUCTOR(Neg); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4874 | }; |
| 4875 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4876 | class HNewArray final : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4877 | public: |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4878 | HNewArray(HInstruction* cls, HInstruction* length, uint32_t dex_pc, size_t component_size_shift) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4879 | : HExpression(kNewArray, DataType::Type::kReference, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4880 | SetRawInputAt(0, cls); |
| 4881 | SetRawInputAt(1, length); |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4882 | SetPackedField<ComponentSizeShiftField>(component_size_shift); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4883 | } |
| 4884 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4885 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4886 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4887 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4888 | bool NeedsEnvironment() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4889 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4890 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4891 | bool CanThrow() const override { return true; } |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4892 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4893 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4894 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4895 | HLoadClass* GetLoadClass() const { |
| 4896 | DCHECK(InputAt(0)->IsLoadClass()); |
| 4897 | return InputAt(0)->AsLoadClass(); |
| 4898 | } |
| 4899 | |
| 4900 | HInstruction* GetLength() const { |
| 4901 | return InputAt(1); |
| 4902 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4903 | |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4904 | size_t GetComponentSizeShift() { |
| 4905 | return GetPackedField<ComponentSizeShiftField>(); |
| 4906 | } |
| 4907 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4908 | DECLARE_INSTRUCTION(NewArray); |
| 4909 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4910 | protected: |
| 4911 | DEFAULT_COPY_CONSTRUCTOR(NewArray); |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4912 | |
| 4913 | private: |
| 4914 | static constexpr size_t kFieldComponentSizeShift = kNumberOfGenericPackedBits; |
| 4915 | static constexpr size_t kFieldComponentSizeShiftSize = MinimumBitsToStore(3u); |
| 4916 | static constexpr size_t kNumberOfNewArrayPackedBits = |
| 4917 | kFieldComponentSizeShift + kFieldComponentSizeShiftSize; |
| 4918 | static_assert(kNumberOfNewArrayPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4919 | using ComponentSizeShiftField = |
| 4920 | BitField<size_t, kFieldComponentSizeShift, kFieldComponentSizeShift>; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4921 | }; |
| 4922 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4923 | class HAdd final : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4924 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4925 | HAdd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4926 | HInstruction* left, |
| 4927 | HInstruction* right, |
| 4928 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4929 | : HBinaryOperation(kAdd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4930 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4931 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4932 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4933 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4934 | 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] | 4935 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4936 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4937 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4938 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4939 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4940 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4941 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4942 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4943 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4944 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4945 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4946 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4947 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4948 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4949 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4950 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4951 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4952 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4953 | DECLARE_INSTRUCTION(Add); |
| 4954 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4955 | protected: |
| 4956 | DEFAULT_COPY_CONSTRUCTOR(Add); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4957 | }; |
| 4958 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4959 | class HSub final : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4960 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4961 | HSub(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4962 | HInstruction* left, |
| 4963 | HInstruction* right, |
| 4964 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4965 | : HBinaryOperation(kSub, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4966 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4967 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4968 | 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] | 4969 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4970 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4971 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4972 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4973 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4974 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4975 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4976 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4977 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4978 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4979 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4980 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4981 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4982 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4983 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4984 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4985 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4986 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4987 | DECLARE_INSTRUCTION(Sub); |
| 4988 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4989 | protected: |
| 4990 | DEFAULT_COPY_CONSTRUCTOR(Sub); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4991 | }; |
| 4992 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4993 | class HMul final : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4994 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4995 | HMul(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4996 | HInstruction* left, |
| 4997 | HInstruction* right, |
| 4998 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4999 | : HBinaryOperation(kMul, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5000 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5001 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5002 | bool IsCommutative() const override { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5003 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5004 | 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] | 5005 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5006 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5007 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5008 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5009 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5010 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5011 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5012 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5013 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5014 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5015 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5016 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5017 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5018 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5019 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5020 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5021 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5022 | |
| 5023 | DECLARE_INSTRUCTION(Mul); |
| 5024 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5025 | protected: |
| 5026 | DEFAULT_COPY_CONSTRUCTOR(Mul); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5027 | }; |
| 5028 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5029 | class HDiv final : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5030 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5031 | HDiv(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5032 | HInstruction* left, |
| 5033 | HInstruction* right, |
| 5034 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5035 | : HBinaryOperation(kDiv, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5036 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5037 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5038 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5039 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5040 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5041 | // Our graph structure ensures we never have 0 for `y` during |
| 5042 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5043 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5044 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5045 | return (y == -1) ? -x : x / y; |
| 5046 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5047 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5048 | template <typename T> |
| 5049 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5050 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5051 | return x / y; |
| 5052 | } |
| 5053 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5054 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5055 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5056 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5057 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5058 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5059 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5060 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5061 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5062 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5063 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5064 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5065 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5066 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5067 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5068 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5069 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5070 | |
| 5071 | DECLARE_INSTRUCTION(Div); |
| 5072 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5073 | protected: |
| 5074 | DEFAULT_COPY_CONSTRUCTOR(Div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5075 | }; |
| 5076 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5077 | class HRem final : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5078 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5079 | HRem(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5080 | HInstruction* left, |
| 5081 | HInstruction* right, |
| 5082 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5083 | : HBinaryOperation(kRem, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5084 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5085 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5086 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5087 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5088 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5089 | // Our graph structure ensures we never have 0 for `y` during |
| 5090 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5091 | DCHECK_NE(y, 0); |
| 5092 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 5093 | return (y == -1) ? 0 : x % y; |
| 5094 | } |
| 5095 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5096 | template <typename T> |
| 5097 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5098 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5099 | return std::fmod(x, y); |
| 5100 | } |
| 5101 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5102 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5103 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5104 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5105 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5106 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5107 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5108 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5109 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5110 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5111 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5112 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5113 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5114 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5115 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5116 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5117 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5118 | |
| 5119 | DECLARE_INSTRUCTION(Rem); |
| 5120 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5121 | protected: |
| 5122 | DEFAULT_COPY_CONSTRUCTOR(Rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5123 | }; |
| 5124 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5125 | class HMin final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5126 | public: |
| 5127 | HMin(DataType::Type result_type, |
| 5128 | HInstruction* left, |
| 5129 | HInstruction* right, |
| 5130 | uint32_t dex_pc) |
| 5131 | : HBinaryOperation(kMin, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5132 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5133 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5134 | |
| 5135 | // Evaluation for integral values. |
| 5136 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5137 | return (x <= y) ? x : y; |
| 5138 | } |
| 5139 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5140 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5141 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5142 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5143 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5144 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5145 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5146 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5147 | } |
| 5148 | // TODO: Evaluation for floating-point values. |
| 5149 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5150 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5151 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5152 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5153 | |
| 5154 | DECLARE_INSTRUCTION(Min); |
| 5155 | |
| 5156 | protected: |
| 5157 | DEFAULT_COPY_CONSTRUCTOR(Min); |
| 5158 | }; |
| 5159 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5160 | class HMax final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5161 | public: |
| 5162 | HMax(DataType::Type result_type, |
| 5163 | HInstruction* left, |
| 5164 | HInstruction* right, |
| 5165 | uint32_t dex_pc) |
| 5166 | : HBinaryOperation(kMax, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5167 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5168 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5169 | |
| 5170 | // Evaluation for integral values. |
| 5171 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5172 | return (x >= y) ? x : y; |
| 5173 | } |
| 5174 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5175 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5176 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5177 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5178 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5179 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5180 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5181 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5182 | } |
| 5183 | // TODO: Evaluation for floating-point values. |
| 5184 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5185 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5186 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5187 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5188 | |
| 5189 | DECLARE_INSTRUCTION(Max); |
| 5190 | |
| 5191 | protected: |
| 5192 | DEFAULT_COPY_CONSTRUCTOR(Max); |
| 5193 | }; |
| 5194 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5195 | class HAbs final : public HUnaryOperation { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5196 | public: |
| 5197 | HAbs(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5198 | : HUnaryOperation(kAbs, result_type, input, dex_pc) {} |
| 5199 | |
| 5200 | // Evaluation for integral values. |
| 5201 | template <typename T> static T ComputeIntegral(T x) { |
| 5202 | return x < 0 ? -x : x; |
| 5203 | } |
| 5204 | |
| 5205 | // Evaluation for floating-point values. |
| 5206 | // Note, as a "quality of implementation", rather than pure "spec compliance", |
| 5207 | // we require that Math.abs() clears the sign bit (but changes nothing else) |
| 5208 | // for all floating-point numbers, including NaN (signaling NaN may become quiet though). |
| 5209 | // http://b/30758343 |
| 5210 | template <typename T, typename S> static T ComputeFP(T x) { |
| 5211 | S bits = bit_cast<S, T>(x); |
| 5212 | return bit_cast<T, S>(bits & std::numeric_limits<S>::max()); |
| 5213 | } |
| 5214 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5215 | HConstant* Evaluate(HIntConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5216 | return GetBlock()->GetGraph()->GetIntConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5217 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5218 | HConstant* Evaluate(HLongConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5219 | return GetBlock()->GetGraph()->GetLongConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5220 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5221 | HConstant* Evaluate(HFloatConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5222 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5223 | ComputeFP<float, int32_t>(x->GetValue()), GetDexPc()); |
| 5224 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5225 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5226 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5227 | ComputeFP<double, int64_t>(x->GetValue()), GetDexPc()); |
| 5228 | } |
| 5229 | |
| 5230 | DECLARE_INSTRUCTION(Abs); |
| 5231 | |
| 5232 | protected: |
| 5233 | DEFAULT_COPY_CONSTRUCTOR(Abs); |
| 5234 | }; |
| 5235 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5236 | class HDivZeroCheck final : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5237 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 5238 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5239 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5240 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5241 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5242 | : HExpression(kDivZeroCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5243 | SetRawInputAt(0, value); |
| 5244 | } |
| 5245 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5246 | bool IsClonable() const override { return true; } |
| 5247 | bool CanBeMoved() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5248 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5249 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5250 | return true; |
| 5251 | } |
| 5252 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5253 | bool NeedsEnvironment() const override { return true; } |
| 5254 | bool CanThrow() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5255 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5256 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 5257 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5258 | protected: |
| 5259 | DEFAULT_COPY_CONSTRUCTOR(DivZeroCheck); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5260 | }; |
| 5261 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5262 | class HShl final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5263 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5264 | HShl(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5265 | HInstruction* value, |
| 5266 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5267 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5268 | : HBinaryOperation(kShl, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5269 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5270 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5271 | } |
| 5272 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5273 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5274 | 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] | 5275 | return value << (distance & max_shift_distance); |
| 5276 | } |
| 5277 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5278 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5279 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5280 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5281 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5282 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5283 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5284 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5285 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5286 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5287 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5288 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5289 | UNREACHABLE(); |
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(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5292 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5293 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5294 | UNREACHABLE(); |
| 5295 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5296 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5297 | HDoubleConstant* 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 double values"; |
| 5299 | UNREACHABLE(); |
| 5300 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5301 | |
| 5302 | DECLARE_INSTRUCTION(Shl); |
| 5303 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5304 | protected: |
| 5305 | DEFAULT_COPY_CONSTRUCTOR(Shl); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5306 | }; |
| 5307 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5308 | class HShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5309 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5310 | HShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5311 | HInstruction* value, |
| 5312 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5313 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5314 | : HBinaryOperation(kShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5315 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5316 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5317 | } |
| 5318 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5319 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5320 | 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] | 5321 | return value >> (distance & max_shift_distance); |
| 5322 | } |
| 5323 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5324 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5325 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5326 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5327 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5328 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5329 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5330 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5331 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5332 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5333 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5334 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5335 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5336 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5337 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5338 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5339 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5340 | UNREACHABLE(); |
| 5341 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5342 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5343 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5344 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5345 | UNREACHABLE(); |
| 5346 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5347 | |
| 5348 | DECLARE_INSTRUCTION(Shr); |
| 5349 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5350 | protected: |
| 5351 | DEFAULT_COPY_CONSTRUCTOR(Shr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5352 | }; |
| 5353 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5354 | class HUShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5355 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5356 | HUShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5357 | HInstruction* value, |
| 5358 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5359 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5360 | : HBinaryOperation(kUShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5361 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5362 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5363 | } |
| 5364 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5365 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5366 | 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] | 5367 | typedef typename std::make_unsigned<T>::type V; |
| 5368 | V ux = static_cast<V>(value); |
| 5369 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 5370 | } |
| 5371 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5372 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5373 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5374 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5375 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5376 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5377 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5378 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5379 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5380 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5381 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5382 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5383 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5384 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5385 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5386 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5387 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5388 | UNREACHABLE(); |
| 5389 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5390 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5391 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5392 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5393 | UNREACHABLE(); |
| 5394 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5395 | |
| 5396 | DECLARE_INSTRUCTION(UShr); |
| 5397 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5398 | protected: |
| 5399 | DEFAULT_COPY_CONSTRUCTOR(UShr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5400 | }; |
| 5401 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5402 | class HAnd final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5403 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5404 | HAnd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5405 | HInstruction* left, |
| 5406 | HInstruction* right, |
| 5407 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5408 | : HBinaryOperation(kAnd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5409 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5410 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5411 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5412 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5413 | 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] | 5414 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5415 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5416 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5417 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5418 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5419 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5420 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5421 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5422 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5423 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5424 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5425 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5426 | UNREACHABLE(); |
| 5427 | } |
| 5428 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5429 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5430 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5431 | UNREACHABLE(); |
| 5432 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5433 | |
| 5434 | DECLARE_INSTRUCTION(And); |
| 5435 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5436 | protected: |
| 5437 | DEFAULT_COPY_CONSTRUCTOR(And); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5438 | }; |
| 5439 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5440 | class HOr final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5441 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5442 | HOr(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5443 | HInstruction* left, |
| 5444 | HInstruction* right, |
| 5445 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5446 | : HBinaryOperation(kOr, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5447 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5448 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5449 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5450 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5451 | 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] | 5452 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5453 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5454 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5455 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5456 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5457 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5458 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5459 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5460 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5461 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5462 | HFloatConstant* y 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 | } |
| 5466 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5467 | HDoubleConstant* y 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 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5471 | |
| 5472 | DECLARE_INSTRUCTION(Or); |
| 5473 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5474 | protected: |
| 5475 | DEFAULT_COPY_CONSTRUCTOR(Or); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5476 | }; |
| 5477 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5478 | class HXor final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5479 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5480 | HXor(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5481 | HInstruction* left, |
| 5482 | HInstruction* right, |
| 5483 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5484 | : HBinaryOperation(kXor, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5485 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5486 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5487 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5488 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5489 | 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] | 5490 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5491 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5492 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5493 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5494 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5495 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5496 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5497 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5498 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5499 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5500 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5501 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5502 | UNREACHABLE(); |
| 5503 | } |
| 5504 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5505 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5506 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5507 | UNREACHABLE(); |
| 5508 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5509 | |
| 5510 | DECLARE_INSTRUCTION(Xor); |
| 5511 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5512 | protected: |
| 5513 | DEFAULT_COPY_CONSTRUCTOR(Xor); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5514 | }; |
| 5515 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5516 | class HRor final : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5517 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5518 | HRor(DataType::Type result_type, HInstruction* value, HInstruction* distance) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5519 | : HBinaryOperation(kRor, result_type, value, distance) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5520 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5521 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5522 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5523 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5524 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5525 | 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] | 5526 | typedef typename std::make_unsigned<T>::type V; |
| 5527 | V ux = static_cast<V>(value); |
| 5528 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5529 | return static_cast<T>(ux); |
| 5530 | } else { |
| 5531 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5532 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 5533 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5534 | } |
| 5535 | } |
| 5536 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5537 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5538 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5539 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5540 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5541 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5542 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5543 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5544 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5545 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5546 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5547 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5548 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5549 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5550 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5551 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5552 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5553 | UNREACHABLE(); |
| 5554 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5555 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5556 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5557 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5558 | UNREACHABLE(); |
| 5559 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5560 | |
| 5561 | DECLARE_INSTRUCTION(Ror); |
| 5562 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5563 | protected: |
| 5564 | DEFAULT_COPY_CONSTRUCTOR(Ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5565 | }; |
| 5566 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5567 | // The value of a parameter in this method. Its location depends on |
| 5568 | // the calling convention. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5569 | class HParameterValue final : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5570 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5571 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5572 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5573 | uint8_t index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5574 | DataType::Type parameter_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5575 | bool is_this = false) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5576 | : HExpression(kParameterValue, parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5577 | dex_file_(dex_file), |
| 5578 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5579 | index_(index) { |
| 5580 | SetPackedFlag<kFlagIsThis>(is_this); |
| 5581 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 5582 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5583 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5584 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5585 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5586 | uint8_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5587 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5588 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5589 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5590 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5591 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5592 | DECLARE_INSTRUCTION(ParameterValue); |
| 5593 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5594 | protected: |
| 5595 | DEFAULT_COPY_CONSTRUCTOR(ParameterValue); |
| 5596 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5597 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5598 | // Whether or not the parameter value corresponds to 'this' argument. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5599 | static constexpr size_t kFlagIsThis = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5600 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 5601 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 5602 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 5603 | "Too many packed fields."); |
| 5604 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5605 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5606 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5607 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5608 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5609 | const uint8_t index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5610 | }; |
| 5611 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5612 | class HNot final : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5613 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5614 | 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] | 5615 | : HUnaryOperation(kNot, result_type, input, dex_pc) { |
| 5616 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5617 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5618 | bool CanBeMoved() const override { return true; } |
| 5619 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5620 | return true; |
| 5621 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5622 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5623 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5624 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5625 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5626 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5627 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5628 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5629 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5630 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5631 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5632 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5633 | UNREACHABLE(); |
| 5634 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5635 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5636 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5637 | UNREACHABLE(); |
| 5638 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5639 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5640 | DECLARE_INSTRUCTION(Not); |
| 5641 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5642 | protected: |
| 5643 | DEFAULT_COPY_CONSTRUCTOR(Not); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5644 | }; |
| 5645 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5646 | class HBooleanNot final : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5647 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5648 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5649 | : HUnaryOperation(kBooleanNot, DataType::Type::kBool, input, dex_pc) { |
| 5650 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5651 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5652 | bool CanBeMoved() const override { return true; } |
| 5653 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5654 | return true; |
| 5655 | } |
| 5656 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5657 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5658 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5659 | return !x; |
| 5660 | } |
| 5661 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5662 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5663 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5664 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5665 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5666 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5667 | UNREACHABLE(); |
| 5668 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5669 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5670 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5671 | UNREACHABLE(); |
| 5672 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5673 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5674 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5675 | UNREACHABLE(); |
| 5676 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5677 | |
| 5678 | DECLARE_INSTRUCTION(BooleanNot); |
| 5679 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5680 | protected: |
| 5681 | DEFAULT_COPY_CONSTRUCTOR(BooleanNot); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5682 | }; |
| 5683 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5684 | class HTypeConversion final : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5685 | public: |
| 5686 | // Instantiate a type conversion of `input` to `result_type`. |
Vladimir Marko | c8fb211 | 2017-10-03 11:37:52 +0100 | [diff] [blame] | 5687 | 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] | 5688 | : HExpression(kTypeConversion, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5689 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5690 | // Invariant: We should never generate a conversion to a Boolean value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5691 | DCHECK_NE(DataType::Type::kBool, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5692 | } |
| 5693 | |
| 5694 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5695 | DataType::Type GetInputType() const { return GetInput()->GetType(); } |
| 5696 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5697 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5698 | bool IsClonable() const override { return true; } |
| 5699 | bool CanBeMoved() const override { return true; } |
| 5700 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5701 | return true; |
| 5702 | } |
Nicolas Geoffray | acc56ac | 2018-10-09 08:45:24 +0100 | [diff] [blame] | 5703 | // Return whether the conversion is implicit. This includes conversion to the same type. |
| 5704 | bool IsImplicitConversion() const { |
| 5705 | return DataType::IsTypeConversionImplicit(GetInputType(), GetResultType()); |
| 5706 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5707 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5708 | // Try to statically evaluate the conversion and return a HConstant |
| 5709 | // containing the result. If the input cannot be converted, return nullptr. |
| 5710 | HConstant* TryStaticEvaluation() const; |
| 5711 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5712 | DECLARE_INSTRUCTION(TypeConversion); |
| 5713 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5714 | protected: |
| 5715 | DEFAULT_COPY_CONSTRUCTOR(TypeConversion); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5716 | }; |
| 5717 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5718 | static constexpr uint32_t kNoRegNumber = -1; |
| 5719 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5720 | class HNullCheck final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5721 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5722 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5723 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5724 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5725 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5726 | : HExpression(kNullCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5727 | SetRawInputAt(0, value); |
| 5728 | } |
| 5729 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5730 | bool IsClonable() const override { return true; } |
| 5731 | bool CanBeMoved() const override { return true; } |
| 5732 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5733 | return true; |
| 5734 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5735 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5736 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5737 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5738 | bool CanThrow() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5739 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5740 | bool CanBeNull() const override { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5741 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5742 | DECLARE_INSTRUCTION(NullCheck); |
| 5743 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5744 | protected: |
| 5745 | DEFAULT_COPY_CONSTRUCTOR(NullCheck); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5746 | }; |
| 5747 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5748 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5749 | // 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] | 5750 | class FieldInfo : public ValueObject { |
| 5751 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5752 | FieldInfo(ArtField* field, |
| 5753 | MemberOffset field_offset, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5754 | DataType::Type field_type, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5755 | bool is_volatile, |
| 5756 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5757 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5758 | const DexFile& dex_file) |
| 5759 | : field_(field), |
| 5760 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5761 | field_type_(field_type), |
| 5762 | is_volatile_(is_volatile), |
| 5763 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5764 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5765 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5766 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5767 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5768 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5769 | DataType::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5770 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5771 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5772 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5773 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5774 | |
| 5775 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5776 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5777 | const MemberOffset field_offset_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5778 | const DataType::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5779 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5780 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5781 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5782 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5783 | }; |
| 5784 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5785 | class HInstanceFieldGet final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5786 | public: |
| 5787 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5788 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5789 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5790 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5791 | bool is_volatile, |
| 5792 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5793 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5794 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5795 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5796 | : HExpression(kInstanceFieldGet, |
| 5797 | field_type, |
| 5798 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5799 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5800 | field_info_(field, |
| 5801 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5802 | field_type, |
| 5803 | is_volatile, |
| 5804 | field_idx, |
| 5805 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5806 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5807 | SetRawInputAt(0, value); |
| 5808 | } |
| 5809 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5810 | bool IsClonable() const override { return true; } |
| 5811 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5812 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5813 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5814 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5815 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5816 | } |
| 5817 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5818 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5819 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5820 | } |
| 5821 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5822 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5823 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5824 | } |
| 5825 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5826 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5827 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5828 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5829 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5830 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5831 | void SetType(DataType::Type new_type) { |
| 5832 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5833 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5834 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5835 | SetPackedField<TypeField>(new_type); |
| 5836 | } |
| 5837 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5838 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5839 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5840 | protected: |
| 5841 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldGet); |
| 5842 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5843 | private: |
| 5844 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5845 | }; |
| 5846 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5847 | class HInstanceFieldSet final : public HExpression<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5848 | public: |
| 5849 | HInstanceFieldSet(HInstruction* object, |
| 5850 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5851 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5852 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5853 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5854 | bool is_volatile, |
| 5855 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5856 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5857 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5858 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5859 | : HExpression(kInstanceFieldSet, |
| 5860 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5861 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5862 | field_info_(field, |
| 5863 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5864 | field_type, |
| 5865 | is_volatile, |
| 5866 | field_idx, |
| 5867 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5868 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5869 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5870 | SetRawInputAt(0, object); |
| 5871 | SetRawInputAt(1, value); |
| 5872 | } |
| 5873 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5874 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5875 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5876 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5877 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5878 | } |
| 5879 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5880 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5881 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5882 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5883 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5884 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5885 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5886 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5887 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5888 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5889 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5890 | protected: |
| 5891 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldSet); |
| 5892 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5893 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5894 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5895 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5896 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5897 | "Too many packed fields."); |
| 5898 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5899 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5900 | }; |
| 5901 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5902 | class HArrayGet final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5903 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5904 | HArrayGet(HInstruction* array, |
| 5905 | HInstruction* index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5906 | DataType::Type type, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5907 | uint32_t dex_pc) |
| 5908 | : HArrayGet(array, |
| 5909 | index, |
| 5910 | type, |
| 5911 | SideEffects::ArrayReadOfType(type), |
| 5912 | dex_pc, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5913 | /* is_string_char_at= */ false) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5914 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5915 | |
| 5916 | HArrayGet(HInstruction* array, |
| 5917 | HInstruction* index, |
| 5918 | DataType::Type type, |
| 5919 | SideEffects side_effects, |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5920 | uint32_t dex_pc, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5921 | bool is_string_char_at) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5922 | : HExpression(kArrayGet, type, side_effects, dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5923 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5924 | SetRawInputAt(0, array); |
| 5925 | SetRawInputAt(1, index); |
| 5926 | } |
| 5927 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5928 | bool IsClonable() const override { return true; } |
| 5929 | bool CanBeMoved() const override { return true; } |
| 5930 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5931 | return true; |
| 5932 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5933 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5934 | // TODO: We can be smarter here. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5935 | // Currently, unless the array is the result of NewArray, the array access is always |
| 5936 | // preceded by some form of null NullCheck necessary for the bounds check, usually |
| 5937 | // implicit null check on the ArrayLength input to BoundsCheck or Deoptimize for |
| 5938 | // dynamic BCE. There are cases when these could be removed to produce better code. |
| 5939 | // If we ever add optimizations to do so we should allow an implicit check here |
| 5940 | // (as long as the address falls in the first page). |
| 5941 | // |
| 5942 | // As an example of such fancy optimization, we could eliminate BoundsCheck for |
| 5943 | // a = cond ? new int[1] : null; |
| 5944 | // a[0]; // The Phi does not need bounds check for either input. |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5945 | return false; |
| 5946 | } |
| 5947 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5948 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5949 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5950 | if (kIsDebugBuild && result) { |
| 5951 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5952 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5953 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5954 | if (DataType::IsIntOrLongType(GetType())) { |
| 5955 | DCHECK(DataType::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5956 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5957 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| 5958 | DCHECK(DataType::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5959 | } |
| 5960 | } |
| 5961 | return result; |
| 5962 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5963 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5964 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5965 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5966 | HInstruction* GetArray() const { return InputAt(0); } |
| 5967 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5968 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5969 | void SetType(DataType::Type new_type) { |
| 5970 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5971 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5972 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5973 | SetPackedField<TypeField>(new_type); |
| 5974 | } |
| 5975 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5976 | DECLARE_INSTRUCTION(ArrayGet); |
| 5977 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5978 | protected: |
| 5979 | DEFAULT_COPY_CONSTRUCTOR(ArrayGet); |
| 5980 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5981 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5982 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5983 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5984 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5985 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5986 | // 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] | 5987 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5988 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5989 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5990 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5991 | }; |
| 5992 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5993 | class HArraySet final : public HExpression<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5994 | public: |
| 5995 | HArraySet(HInstruction* array, |
| 5996 | HInstruction* index, |
| 5997 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5998 | DataType::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5999 | uint32_t dex_pc) |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6000 | : HArraySet(array, |
| 6001 | index, |
| 6002 | value, |
| 6003 | expected_component_type, |
| 6004 | // Make a best guess for side effects now, may be refined during SSA building. |
| 6005 | ComputeSideEffects(GetComponentType(value->GetType(), expected_component_type)), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6006 | dex_pc) { |
| 6007 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6008 | |
| 6009 | HArraySet(HInstruction* array, |
| 6010 | HInstruction* index, |
| 6011 | HInstruction* value, |
| 6012 | DataType::Type expected_component_type, |
| 6013 | SideEffects side_effects, |
| 6014 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6015 | : HExpression(kArraySet, side_effects, dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6016 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6017 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6018 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 6019 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6020 | SetRawInputAt(0, array); |
| 6021 | SetRawInputAt(1, index); |
| 6022 | SetRawInputAt(2, value); |
| 6023 | } |
| 6024 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6025 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6026 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6027 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6028 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6029 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6030 | } |
| 6031 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 6032 | // Can throw ArrayStoreException. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6033 | bool CanThrow() const override { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 6034 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6035 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6036 | // TODO: Same as for ArrayGet. |
| 6037 | return false; |
| 6038 | } |
| 6039 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6040 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6041 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6042 | } |
| 6043 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6044 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6045 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6046 | } |
| 6047 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6048 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6049 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6050 | } |
| 6051 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6052 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6053 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 6054 | bool StaticTypeOfArrayIsObjectArray() const { |
| 6055 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 6056 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6057 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6058 | HInstruction* GetArray() const { return InputAt(0); } |
| 6059 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6060 | HInstruction* GetValue() const { return InputAt(2); } |
| 6061 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6062 | DataType::Type GetComponentType() const { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6063 | return GetComponentType(GetValue()->GetType(), GetRawExpectedComponentType()); |
| 6064 | } |
| 6065 | |
| 6066 | static DataType::Type GetComponentType(DataType::Type value_type, |
| 6067 | DataType::Type expected_component_type) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6068 | // The Dex format does not type floating point index operations. Since the |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6069 | // `expected_component_type` comes from SSA building and can therefore not |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6070 | // be correct, we also check what is the value type. If it is a floating |
| 6071 | // point type, we must use that type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6072 | return ((value_type == DataType::Type::kFloat32) || (value_type == DataType::Type::kFloat64)) |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6073 | ? value_type |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6074 | : expected_component_type; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6075 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6076 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6077 | DataType::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6078 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6079 | } |
| 6080 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6081 | static SideEffects ComputeSideEffects(DataType::Type type) { |
| 6082 | return SideEffects::ArrayWriteOfType(type).Union(SideEffectsForArchRuntimeCalls(type)); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 6083 | } |
| 6084 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6085 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type value_type) { |
| 6086 | return (value_type == DataType::Type::kReference) ? SideEffects::CanTriggerGC() |
| 6087 | : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6088 | } |
| 6089 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6090 | DECLARE_INSTRUCTION(ArraySet); |
| 6091 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6092 | protected: |
| 6093 | DEFAULT_COPY_CONSTRUCTOR(ArraySet); |
| 6094 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6095 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6096 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 6097 | static constexpr size_t kFieldExpectedComponentTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6098 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6099 | static constexpr size_t kFlagNeedsTypeCheck = |
| 6100 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 6101 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6102 | // Cached information for the reference_type_info_ so that codegen |
| 6103 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6104 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 6105 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 6106 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 6107 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6108 | using ExpectedComponentTypeField = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6109 | BitField<DataType::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6110 | }; |
| 6111 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6112 | class HArrayLength final : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6113 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6114 | 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] | 6115 | : HExpression(kArrayLength, DataType::Type::kInt32, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6116 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6117 | // Note that arrays do not change length, so the instruction does not |
| 6118 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6119 | SetRawInputAt(0, array); |
| 6120 | } |
| 6121 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6122 | bool IsClonable() const override { return true; } |
| 6123 | bool CanBeMoved() const override { return true; } |
| 6124 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6125 | return true; |
| 6126 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6127 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 6128 | return obj == InputAt(0); |
| 6129 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6130 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6131 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 6132 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6133 | DECLARE_INSTRUCTION(ArrayLength); |
| 6134 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6135 | protected: |
| 6136 | DEFAULT_COPY_CONSTRUCTOR(ArrayLength); |
| 6137 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6138 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6139 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 6140 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 6141 | // determine whether a particular HArrayLength is actually a String.length() by |
| 6142 | // looking at the type of the input but that requires holding the mutator lock, so |
| 6143 | // 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] | 6144 | static constexpr size_t kFlagIsStringLength = kNumberOfGenericPackedBits; |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6145 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 6146 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6147 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6148 | }; |
| 6149 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6150 | class HBoundsCheck final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6151 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 6152 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6153 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 6154 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6155 | HBoundsCheck(HInstruction* index, |
| 6156 | HInstruction* length, |
| 6157 | uint32_t dex_pc, |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6158 | bool is_string_char_at = false) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6159 | : HExpression(kBoundsCheck, index->GetType(), SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6160 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(index->GetType())); |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6161 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6162 | SetRawInputAt(0, index); |
| 6163 | SetRawInputAt(1, length); |
| 6164 | } |
| 6165 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6166 | bool IsClonable() const override { return true; } |
| 6167 | bool CanBeMoved() const override { return true; } |
| 6168 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6169 | return true; |
| 6170 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6171 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6172 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6173 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6174 | bool CanThrow() const override { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 6175 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 6176 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6177 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6178 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6179 | |
| 6180 | DECLARE_INSTRUCTION(BoundsCheck); |
| 6181 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6182 | protected: |
| 6183 | DEFAULT_COPY_CONSTRUCTOR(BoundsCheck); |
| 6184 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6185 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6186 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | f02046e | 2018-10-02 15:31:32 +0100 | [diff] [blame] | 6187 | static constexpr size_t kNumberOfBoundsCheckPackedBits = kFlagIsStringCharAt + 1; |
| 6188 | static_assert(kNumberOfBoundsCheckPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6189 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6190 | }; |
| 6191 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6192 | class HSuspendCheck final : public HExpression<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6193 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 6194 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6195 | : HExpression(kSuspendCheck, SideEffects::CanTriggerGC(), dex_pc), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6196 | slow_path_(nullptr) { |
| 6197 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6198 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6199 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6200 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6201 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6202 | return true; |
| 6203 | } |
| 6204 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6205 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 6206 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6207 | |
| 6208 | DECLARE_INSTRUCTION(SuspendCheck); |
| 6209 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6210 | protected: |
| 6211 | DEFAULT_COPY_CONSTRUCTOR(SuspendCheck); |
| 6212 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6213 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6214 | // Only used for code generation, in order to share the same slow path between back edges |
| 6215 | // of a same loop. |
| 6216 | SlowPathCode* slow_path_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6217 | }; |
| 6218 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6219 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 6220 | // 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] | 6221 | class HNativeDebugInfo : public HExpression<0> { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6222 | public: |
| 6223 | explicit HNativeDebugInfo(uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6224 | : HExpression<0>(kNativeDebugInfo, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6225 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6226 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6227 | bool NeedsEnvironment() const override { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6228 | return true; |
| 6229 | } |
| 6230 | |
| 6231 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 6232 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6233 | protected: |
| 6234 | DEFAULT_COPY_CONSTRUCTOR(NativeDebugInfo); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6235 | }; |
| 6236 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6237 | /** |
| 6238 | * Instruction to load a Class object. |
| 6239 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6240 | class HLoadClass final : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6241 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6242 | // Determines how to load the Class. |
| 6243 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6244 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 6245 | kInvalid = -1, |
| 6246 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6247 | // Use the Class* from the method's own ArtMethod*. |
| 6248 | kReferrersClass, |
| 6249 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6250 | // 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] | 6251 | // Used for boot image classes referenced by boot image code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6252 | kBootImageLinkTimePcRelative, |
| 6253 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6254 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6255 | // Used for boot image classes referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6256 | kBootImageRelRo, |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6257 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6258 | // Load from an entry in the .bss section using a PC-relative load. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6259 | // Used for classes outside boot image referenced by AOT-compiled app and boot image code. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6260 | kBssEntry, |
| 6261 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6262 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 6263 | // Used for boot image classes referenced by apps in JIT-compiled code. |
| 6264 | kJitBootImageAddress, |
| 6265 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6266 | // Load from the root table associated with the JIT compiled method. |
| 6267 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6268 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6269 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6270 | // the codegen is unable to use another appropriate kind. |
| 6271 | kRuntimeCall, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6272 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6273 | kLast = kRuntimeCall |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6274 | }; |
| 6275 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6276 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6277 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6278 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6279 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6280 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6281 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6282 | bool needs_access_check) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6283 | : HInstruction(kLoadClass, |
| 6284 | DataType::Type::kReference, |
| 6285 | SideEffectsForArchRuntimeCalls(), |
| 6286 | dex_pc), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6287 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6288 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6289 | dex_file_(dex_file), |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6290 | klass_(klass) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 6291 | // Referrers class should not need access check. We never inline unverified |
| 6292 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6293 | DCHECK(!is_referrers_class || !needs_access_check); |
| 6294 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6295 | SetPackedField<LoadKindField>( |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6296 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kRuntimeCall); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6297 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6298 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6299 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6300 | SetPackedFlag<kFlagValidLoadedClassRTI>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6301 | } |
| 6302 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6303 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6304 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6305 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6306 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6307 | LoadKind GetLoadKind() const { |
| 6308 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6309 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6310 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6311 | bool HasPcRelativeLoadKind() const { |
| 6312 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6313 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 6314 | GetLoadKind() == LoadKind::kBssEntry; |
| 6315 | } |
| 6316 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6317 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6318 | |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame^] | 6319 | bool InstructionDataEquals(const HInstruction* other) const override; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6320 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6321 | size_t ComputeHashCode() const override { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6322 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6323 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6324 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6325 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6326 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6327 | } |
| 6328 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 6329 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 6330 | // The entrypoint the code generator is going to call does not do |
| 6331 | // clinit of the class. |
| 6332 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6333 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6334 | } |
| 6335 | |
| 6336 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6337 | return NeedsAccessCheck() || |
| 6338 | MustGenerateClinitCheck() || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6339 | GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6340 | GetLoadKind() == LoadKind::kBssEntry; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6341 | } |
| 6342 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6343 | bool CanThrow() const override { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6344 | return NeedsAccessCheck() || |
| 6345 | MustGenerateClinitCheck() || |
| 6346 | // If the class is in the boot image, the lookup in the runtime call cannot throw. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6347 | ((GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6348 | GetLoadKind() == LoadKind::kBssEntry) && |
| 6349 | !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6350 | } |
| 6351 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6352 | ReferenceTypeInfo GetLoadedClassRTI() { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6353 | if (GetPackedFlag<kFlagValidLoadedClassRTI>()) { |
| 6354 | // Note: The is_exact flag from the return value should not be used. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6355 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact= */ true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6356 | } else { |
| 6357 | return ReferenceTypeInfo::CreateInvalid(); |
| 6358 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6359 | } |
| 6360 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6361 | // Loaded class RTI is marked as valid by RTP if the klass_ is admissible. |
| 6362 | void SetValidLoadedClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 6363 | DCHECK(klass_ != nullptr); |
| 6364 | SetPackedFlag<kFlagValidLoadedClassRTI>(true); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6365 | } |
| 6366 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6367 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6368 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6369 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6370 | bool NeedsDexCacheOfDeclaringClass() const override { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6371 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6372 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 6373 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6374 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6375 | return SideEffects::CanTriggerGC(); |
| 6376 | } |
| 6377 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6378 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6379 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6380 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6381 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6382 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6383 | bool MustResolveTypeOnSlowPath() const { |
| 6384 | // Check that this instruction has a slow path. |
| 6385 | DCHECK(GetLoadKind() != LoadKind::kRuntimeCall); // kRuntimeCall calls on main path. |
| 6386 | DCHECK(GetLoadKind() == LoadKind::kBssEntry || MustGenerateClinitCheck()); |
| 6387 | return GetLoadKind() == LoadKind::kBssEntry; |
| 6388 | } |
| 6389 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6390 | void MarkInBootImage() { |
| 6391 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 6392 | } |
| 6393 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6394 | void AddSpecialInput(HInstruction* special_input); |
| 6395 | |
| 6396 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6397 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6398 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6399 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6400 | } |
| 6401 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6402 | Handle<mirror::Class> GetClass() const { |
| 6403 | return klass_; |
| 6404 | } |
| 6405 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6406 | DECLARE_INSTRUCTION(LoadClass); |
| 6407 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6408 | protected: |
| 6409 | DEFAULT_COPY_CONSTRUCTOR(LoadClass); |
| 6410 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6411 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6412 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6413 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6414 | // Whether this instruction must generate the initialization check. |
| 6415 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6416 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6417 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 6418 | static constexpr size_t kFieldLoadKindSize = |
| 6419 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6420 | static constexpr size_t kFlagValidLoadedClassRTI = kFieldLoadKind + kFieldLoadKindSize; |
| 6421 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagValidLoadedClassRTI + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6422 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6423 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 6424 | |
| 6425 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6426 | return load_kind == LoadKind::kReferrersClass || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6427 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6428 | load_kind == LoadKind::kBssEntry || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6429 | load_kind == LoadKind::kRuntimeCall; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6430 | } |
| 6431 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6432 | void SetLoadKindInternal(LoadKind load_kind); |
| 6433 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6434 | // The special input is the HCurrentMethod for kRuntimeCall or kReferrersClass. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6435 | // 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] | 6436 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6437 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6438 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6439 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 6440 | // - The compiling method's dex file if the class is defined there too. |
| 6441 | // - The compiling method's dex file if the class is referenced there. |
| 6442 | // - 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] | 6443 | // kBssEntry or kRuntimeCall, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6444 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6445 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6446 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6447 | Handle<mirror::Class> klass_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6448 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6449 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 6450 | |
| 6451 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6452 | inline void HLoadClass::SetLoadKind(LoadKind load_kind) { |
| 6453 | // The load kind should be determined before inserting the instruction to the graph. |
| 6454 | DCHECK(GetBlock() == nullptr); |
| 6455 | DCHECK(GetEnvironment() == nullptr); |
| 6456 | SetPackedField<LoadKindField>(load_kind); |
| 6457 | if (load_kind != LoadKind::kRuntimeCall && load_kind != LoadKind::kReferrersClass) { |
| 6458 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6459 | } |
| 6460 | if (!NeedsEnvironment()) { |
| 6461 | SetSideEffects(SideEffects::None()); |
| 6462 | } |
| 6463 | } |
| 6464 | |
| 6465 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6466 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6467 | // The special input is used for PC-relative loads on some architectures, |
| 6468 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6469 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6470 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6471 | GetLoadKind() == LoadKind::kBssEntry || |
| 6472 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6473 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6474 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 6475 | special_input->AddUseAt(this, 0); |
| 6476 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6477 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6478 | class HLoadString final : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6479 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6480 | // Determines how to load the String. |
| 6481 | enum class LoadKind { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6482 | // 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] | 6483 | // Used for boot image strings referenced by boot image code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6484 | kBootImageLinkTimePcRelative, |
| 6485 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6486 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6487 | // Used for boot image strings referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6488 | kBootImageRelRo, |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6489 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6490 | // Load from an entry in the .bss section using a PC-relative load. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6491 | // Used for strings outside boot image referenced by AOT-compiled app and boot image code. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6492 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6493 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6494 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 6495 | // Used for boot image strings referenced by apps in JIT-compiled code. |
| 6496 | kJitBootImageAddress, |
| 6497 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6498 | // Load from the root table associated with the JIT compiled method. |
| 6499 | kJitTableAddress, |
| 6500 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6501 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6502 | // the codegen is unable to use another appropriate kind. |
| 6503 | kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6504 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6505 | kLast = kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6506 | }; |
| 6507 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6508 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6509 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6510 | const DexFile& dex_file, |
| 6511 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6512 | : HInstruction(kLoadString, |
| 6513 | DataType::Type::kReference, |
| 6514 | SideEffectsForArchRuntimeCalls(), |
| 6515 | dex_pc), |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6516 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6517 | string_index_(string_index), |
| 6518 | dex_file_(dex_file) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6519 | SetPackedField<LoadKindField>(LoadKind::kRuntimeCall); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6520 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6521 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6522 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6523 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6524 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6525 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6526 | LoadKind GetLoadKind() const { |
| 6527 | return GetPackedField<LoadKindField>(); |
| 6528 | } |
| 6529 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6530 | bool HasPcRelativeLoadKind() const { |
| 6531 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6532 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 6533 | GetLoadKind() == LoadKind::kBssEntry; |
| 6534 | } |
| 6535 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6536 | const DexFile& GetDexFile() const { |
| 6537 | return dex_file_; |
| 6538 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6539 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6540 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6541 | return string_index_; |
| 6542 | } |
| 6543 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6544 | Handle<mirror::String> GetString() const { |
| 6545 | return string_; |
| 6546 | } |
| 6547 | |
| 6548 | void SetString(Handle<mirror::String> str) { |
| 6549 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6550 | } |
| 6551 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6552 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6553 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6554 | bool InstructionDataEquals(const HInstruction* other) const override; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6555 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6556 | size_t ComputeHashCode() const override { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6557 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6558 | // Will call the runtime if we need to load the string through |
| 6559 | // the dex cache and the string is not guaranteed to be there yet. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6560 | bool NeedsEnvironment() const override { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6561 | LoadKind load_kind = GetLoadKind(); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6562 | if (load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6563 | load_kind == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6564 | load_kind == LoadKind::kJitBootImageAddress || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6565 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6566 | return false; |
| 6567 | } |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6568 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6569 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6570 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6571 | bool NeedsDexCacheOfDeclaringClass() const override { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6572 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6573 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6574 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6575 | bool CanBeNull() const override { return false; } |
| 6576 | bool CanThrow() const override { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6577 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6578 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6579 | return SideEffects::CanTriggerGC(); |
| 6580 | } |
| 6581 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6582 | void AddSpecialInput(HInstruction* special_input); |
| 6583 | |
| 6584 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6585 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6586 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6587 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6588 | } |
| 6589 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6590 | DECLARE_INSTRUCTION(LoadString); |
| 6591 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6592 | protected: |
| 6593 | DEFAULT_COPY_CONSTRUCTOR(LoadString); |
| 6594 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6595 | private: |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6596 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6597 | static constexpr size_t kFieldLoadKindSize = |
| 6598 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 6599 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6600 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6601 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6602 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6603 | void SetLoadKindInternal(LoadKind load_kind); |
| 6604 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6605 | // The special input is the HCurrentMethod for kRuntimeCall. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6606 | // 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] | 6607 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6608 | HUserRecord<HInstruction*> special_input_; |
| 6609 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6610 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6611 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6612 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6613 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6614 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6615 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 6616 | |
| 6617 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6618 | inline void HLoadString::SetLoadKind(LoadKind load_kind) { |
| 6619 | // The load kind should be determined before inserting the instruction to the graph. |
| 6620 | DCHECK(GetBlock() == nullptr); |
| 6621 | DCHECK(GetEnvironment() == nullptr); |
| 6622 | DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); |
| 6623 | SetPackedField<LoadKindField>(load_kind); |
| 6624 | if (load_kind != LoadKind::kRuntimeCall) { |
| 6625 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6626 | } |
| 6627 | if (!NeedsEnvironment()) { |
| 6628 | SetSideEffects(SideEffects::None()); |
| 6629 | } |
| 6630 | } |
| 6631 | |
| 6632 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6633 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6634 | // The special input is used for PC-relative loads on some architectures, |
| 6635 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6636 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6637 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6638 | GetLoadKind() == LoadKind::kBssEntry || |
| 6639 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6640 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 6641 | // so use the GetInputRecords() from the base class to set the input record. |
| 6642 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6643 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6644 | special_input->AddUseAt(this, 0); |
| 6645 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6646 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6647 | class HLoadMethodHandle final : public HInstruction { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6648 | public: |
| 6649 | HLoadMethodHandle(HCurrentMethod* current_method, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 6650 | uint16_t method_handle_idx, |
| 6651 | const DexFile& dex_file, |
| 6652 | uint32_t dex_pc) |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6653 | : HInstruction(kLoadMethodHandle, |
| 6654 | DataType::Type::kReference, |
| 6655 | SideEffectsForArchRuntimeCalls(), |
| 6656 | dex_pc), |
| 6657 | special_input_(HUserRecord<HInstruction*>(current_method)), |
| 6658 | method_handle_idx_(method_handle_idx), |
| 6659 | dex_file_(dex_file) { |
| 6660 | } |
| 6661 | |
| 6662 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6663 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6664 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6665 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6666 | } |
| 6667 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6668 | bool IsClonable() const override { return true; } |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6669 | |
| 6670 | uint16_t GetMethodHandleIndex() const { return method_handle_idx_; } |
| 6671 | |
| 6672 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6673 | |
| 6674 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6675 | return SideEffects::CanTriggerGC(); |
| 6676 | } |
| 6677 | |
| 6678 | DECLARE_INSTRUCTION(LoadMethodHandle); |
| 6679 | |
| 6680 | protected: |
| 6681 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodHandle); |
| 6682 | |
| 6683 | private: |
| 6684 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6685 | HUserRecord<HInstruction*> special_input_; |
| 6686 | |
| 6687 | const uint16_t method_handle_idx_; |
| 6688 | const DexFile& dex_file_; |
| 6689 | }; |
| 6690 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6691 | class HLoadMethodType final : public HInstruction { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6692 | public: |
| 6693 | HLoadMethodType(HCurrentMethod* current_method, |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6694 | dex::ProtoIndex proto_index, |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6695 | const DexFile& dex_file, |
| 6696 | uint32_t dex_pc) |
| 6697 | : HInstruction(kLoadMethodType, |
| 6698 | DataType::Type::kReference, |
| 6699 | SideEffectsForArchRuntimeCalls(), |
| 6700 | dex_pc), |
| 6701 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6702 | proto_index_(proto_index), |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6703 | dex_file_(dex_file) { |
| 6704 | } |
| 6705 | |
| 6706 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6707 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6708 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6709 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6710 | } |
| 6711 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6712 | bool IsClonable() const override { return true; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6713 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6714 | dex::ProtoIndex GetProtoIndex() const { return proto_index_; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6715 | |
| 6716 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6717 | |
| 6718 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6719 | return SideEffects::CanTriggerGC(); |
| 6720 | } |
| 6721 | |
| 6722 | DECLARE_INSTRUCTION(LoadMethodType); |
| 6723 | |
| 6724 | protected: |
| 6725 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodType); |
| 6726 | |
| 6727 | private: |
| 6728 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6729 | HUserRecord<HInstruction*> special_input_; |
| 6730 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6731 | const dex::ProtoIndex proto_index_; |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6732 | const DexFile& dex_file_; |
| 6733 | }; |
| 6734 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6735 | /** |
| 6736 | * Performs an initialization check on its Class object input. |
| 6737 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6738 | class HClinitCheck final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6739 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 6740 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 6741 | : HExpression( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6742 | kClinitCheck, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6743 | DataType::Type::kReference, |
Mingyao Yang | 217eb06 | 2017-12-11 15:20:07 -0800 | [diff] [blame] | 6744 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6745 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6746 | SetRawInputAt(0, constant); |
| 6747 | } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 6748 | // TODO: Make ClinitCheck clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6749 | bool CanBeMoved() const override { return true; } |
| 6750 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6751 | return true; |
| 6752 | } |
| 6753 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6754 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6755 | // May call runtime to initialize the class. |
| 6756 | return true; |
| 6757 | } |
| 6758 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6759 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6760 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6761 | HLoadClass* GetLoadClass() const { |
| 6762 | DCHECK(InputAt(0)->IsLoadClass()); |
| 6763 | return InputAt(0)->AsLoadClass(); |
| 6764 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6765 | |
| 6766 | DECLARE_INSTRUCTION(ClinitCheck); |
| 6767 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6768 | |
| 6769 | protected: |
| 6770 | DEFAULT_COPY_CONSTRUCTOR(ClinitCheck); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6771 | }; |
| 6772 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6773 | class HStaticFieldGet final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6774 | public: |
| 6775 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6776 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6777 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6778 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6779 | bool is_volatile, |
| 6780 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6781 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6782 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6783 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6784 | : HExpression(kStaticFieldGet, |
| 6785 | field_type, |
| 6786 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 6787 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6788 | field_info_(field, |
| 6789 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6790 | field_type, |
| 6791 | is_volatile, |
| 6792 | field_idx, |
| 6793 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6794 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6795 | SetRawInputAt(0, cls); |
| 6796 | } |
| 6797 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6798 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6799 | bool IsClonable() const override { return true; } |
| 6800 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6801 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6802 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6803 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6804 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6805 | } |
| 6806 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6807 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6808 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6809 | } |
| 6810 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6811 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6812 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6813 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6814 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6815 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6816 | void SetType(DataType::Type new_type) { |
| 6817 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6818 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6819 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6820 | SetPackedField<TypeField>(new_type); |
| 6821 | } |
| 6822 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6823 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 6824 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6825 | protected: |
| 6826 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldGet); |
| 6827 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6828 | private: |
| 6829 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6830 | }; |
| 6831 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6832 | class HStaticFieldSet final : public HExpression<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6833 | public: |
| 6834 | HStaticFieldSet(HInstruction* cls, |
| 6835 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6836 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6837 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6838 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6839 | bool is_volatile, |
| 6840 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6841 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6842 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6843 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6844 | : HExpression(kStaticFieldSet, |
| 6845 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 6846 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6847 | field_info_(field, |
| 6848 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6849 | field_type, |
| 6850 | is_volatile, |
| 6851 | field_idx, |
| 6852 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6853 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6854 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6855 | SetRawInputAt(0, cls); |
| 6856 | SetRawInputAt(1, value); |
| 6857 | } |
| 6858 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6859 | bool IsClonable() const override { return true; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6860 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6861 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6862 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6863 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6864 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6865 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6866 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6867 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6868 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6869 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6870 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6871 | protected: |
| 6872 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldSet); |
| 6873 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6874 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6875 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6876 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6877 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6878 | "Too many packed fields."); |
| 6879 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6880 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6881 | }; |
| 6882 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6883 | class HUnresolvedInstanceFieldGet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6884 | public: |
| 6885 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6886 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6887 | uint32_t field_index, |
| 6888 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6889 | : HExpression(kUnresolvedInstanceFieldGet, |
| 6890 | field_type, |
| 6891 | SideEffects::AllExceptGCDependency(), |
| 6892 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6893 | field_index_(field_index) { |
| 6894 | SetRawInputAt(0, obj); |
| 6895 | } |
| 6896 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6897 | bool IsClonable() const override { return true; } |
| 6898 | bool NeedsEnvironment() const override { return true; } |
| 6899 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6900 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6901 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6902 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6903 | |
| 6904 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6905 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6906 | protected: |
| 6907 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldGet); |
| 6908 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6909 | private: |
| 6910 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6911 | }; |
| 6912 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6913 | class HUnresolvedInstanceFieldSet final : public HExpression<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6914 | public: |
| 6915 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6916 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6917 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6918 | uint32_t field_index, |
| 6919 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6920 | : HExpression(kUnresolvedInstanceFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6921 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6922 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6923 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6924 | SetRawInputAt(0, obj); |
| 6925 | SetRawInputAt(1, value); |
| 6926 | } |
| 6927 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6928 | bool IsClonable() const override { return true; } |
| 6929 | bool NeedsEnvironment() const override { return true; } |
| 6930 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6931 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6932 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6933 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6934 | |
| 6935 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6936 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6937 | protected: |
| 6938 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldSet); |
| 6939 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6940 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6941 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6942 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6943 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6944 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6945 | kFieldFieldType + kFieldFieldTypeSize; |
| 6946 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6947 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6948 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6949 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6950 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6951 | }; |
| 6952 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6953 | class HUnresolvedStaticFieldGet final : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6954 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6955 | HUnresolvedStaticFieldGet(DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6956 | uint32_t field_index, |
| 6957 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6958 | : HExpression(kUnresolvedStaticFieldGet, |
| 6959 | field_type, |
| 6960 | SideEffects::AllExceptGCDependency(), |
| 6961 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6962 | field_index_(field_index) { |
| 6963 | } |
| 6964 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6965 | bool IsClonable() const override { return true; } |
| 6966 | bool NeedsEnvironment() const override { return true; } |
| 6967 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6968 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6969 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6970 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6971 | |
| 6972 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6973 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6974 | protected: |
| 6975 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldGet); |
| 6976 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6977 | private: |
| 6978 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6979 | }; |
| 6980 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6981 | class HUnresolvedStaticFieldSet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6982 | public: |
| 6983 | HUnresolvedStaticFieldSet(HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6984 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6985 | uint32_t field_index, |
| 6986 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6987 | : HExpression(kUnresolvedStaticFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6988 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6989 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6990 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6991 | SetRawInputAt(0, value); |
| 6992 | } |
| 6993 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6994 | bool IsClonable() const override { return true; } |
| 6995 | bool NeedsEnvironment() const override { return true; } |
| 6996 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6997 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6998 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6999 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7000 | |
| 7001 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 7002 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7003 | protected: |
| 7004 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldSet); |
| 7005 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7006 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7007 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 7008 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7009 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7010 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 7011 | kFieldFieldType + kFieldFieldTypeSize; |
| 7012 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7013 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7014 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7015 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7016 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7017 | }; |
| 7018 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7019 | // Implement the move-exception DEX instruction. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7020 | class HLoadException final : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7021 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7022 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7023 | : HExpression(kLoadException, DataType::Type::kReference, SideEffects::None(), dex_pc) { |
| 7024 | } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7025 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7026 | bool CanBeNull() const override { return false; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 7027 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7028 | DECLARE_INSTRUCTION(LoadException); |
| 7029 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7030 | protected: |
| 7031 | DEFAULT_COPY_CONSTRUCTOR(LoadException); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7032 | }; |
| 7033 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7034 | // Implicit part of move-exception which clears thread-local exception storage. |
| 7035 | // Must not be removed because the runtime expects the TLS to get cleared. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7036 | class HClearException final : public HExpression<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7037 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7038 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7039 | : HExpression(kClearException, SideEffects::AllWrites(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7040 | } |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7041 | |
| 7042 | DECLARE_INSTRUCTION(ClearException); |
| 7043 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7044 | protected: |
| 7045 | DEFAULT_COPY_CONSTRUCTOR(ClearException); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7046 | }; |
| 7047 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7048 | class HThrow final : public HExpression<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7049 | public: |
| 7050 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7051 | : HExpression(kThrow, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7052 | SetRawInputAt(0, exception); |
| 7053 | } |
| 7054 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7055 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7056 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7057 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7058 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7059 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7060 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7061 | bool AlwaysThrows() const override { return true; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 7062 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7063 | DECLARE_INSTRUCTION(Throw); |
| 7064 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7065 | protected: |
| 7066 | DEFAULT_COPY_CONSTRUCTOR(Throw); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7067 | }; |
| 7068 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7069 | /** |
| 7070 | * Implementation strategies for the code generator of a HInstanceOf |
| 7071 | * or `HCheckCast`. |
| 7072 | */ |
| 7073 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7074 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7075 | kExactCheck, // Can do a single class compare. |
| 7076 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 7077 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 7078 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 7079 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7080 | kArrayCheck, // No optimization yet when checking against a generic array. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7081 | kBitstringCheck, // Compare the type check bitstring. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7082 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7083 | }; |
| 7084 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 7085 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 7086 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7087 | // Note: HTypeCheckInstruction is just a helper class, not an abstract instruction with an |
| 7088 | // `IsTypeCheckInstruction()`. (New virtual methods in the HInstruction class have a high cost.) |
| 7089 | class HTypeCheckInstruction : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7090 | public: |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7091 | HTypeCheckInstruction(InstructionKind kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7092 | DataType::Type type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7093 | HInstruction* object, |
| 7094 | HInstruction* target_class_or_null, |
| 7095 | TypeCheckKind check_kind, |
| 7096 | Handle<mirror::Class> klass, |
| 7097 | uint32_t dex_pc, |
| 7098 | ArenaAllocator* allocator, |
| 7099 | HIntConstant* bitstring_path_to_root, |
| 7100 | HIntConstant* bitstring_mask, |
| 7101 | SideEffects side_effects) |
| 7102 | : HVariableInputSizeInstruction( |
| 7103 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7104 | type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7105 | side_effects, |
| 7106 | dex_pc, |
| 7107 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7108 | /* number_of_inputs= */ check_kind == TypeCheckKind::kBitstringCheck ? 4u : 2u, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7109 | kArenaAllocTypeCheckInputs), |
| 7110 | klass_(klass) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7111 | SetPackedField<TypeCheckKindField>(check_kind); |
| 7112 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7113 | SetPackedFlag<kFlagValidTargetClassRTI>(false); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7114 | SetRawInputAt(0, object); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7115 | SetRawInputAt(1, target_class_or_null); |
| 7116 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_path_to_root != nullptr); |
| 7117 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_mask != nullptr); |
| 7118 | if (check_kind == TypeCheckKind::kBitstringCheck) { |
| 7119 | DCHECK(target_class_or_null->IsNullConstant()); |
| 7120 | SetRawInputAt(2, bitstring_path_to_root); |
| 7121 | SetRawInputAt(3, bitstring_mask); |
| 7122 | } else { |
| 7123 | DCHECK(target_class_or_null->IsLoadClass()); |
| 7124 | } |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7125 | } |
| 7126 | |
| 7127 | HLoadClass* GetTargetClass() const { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7128 | DCHECK_NE(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7129 | HInstruction* load_class = InputAt(1); |
| 7130 | DCHECK(load_class->IsLoadClass()); |
| 7131 | return load_class->AsLoadClass(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7132 | } |
| 7133 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7134 | uint32_t GetBitstringPathToRoot() const { |
| 7135 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7136 | HInstruction* path_to_root = InputAt(2); |
| 7137 | DCHECK(path_to_root->IsIntConstant()); |
| 7138 | return static_cast<uint32_t>(path_to_root->AsIntConstant()->GetValue()); |
| 7139 | } |
| 7140 | |
| 7141 | uint32_t GetBitstringMask() const { |
| 7142 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7143 | HInstruction* mask = InputAt(3); |
| 7144 | DCHECK(mask->IsIntConstant()); |
| 7145 | return static_cast<uint32_t>(mask->AsIntConstant()->GetValue()); |
| 7146 | } |
| 7147 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7148 | bool IsClonable() const override { return true; } |
| 7149 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7150 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7151 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7152 | DCHECK(other->IsInstanceOf() || other->IsCheckCast()) << other->DebugName(); |
| 7153 | return GetPackedFields() == down_cast<const HTypeCheckInstruction*>(other)->GetPackedFields(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7154 | } |
| 7155 | |
Andreas Gampe | 3fbd3ad | 2018-03-26 21:14:46 +0000 | [diff] [blame] | 7156 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 7157 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 7158 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 7159 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
| 7160 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7161 | ReferenceTypeInfo GetTargetClassRTI() { |
| 7162 | if (GetPackedFlag<kFlagValidTargetClassRTI>()) { |
| 7163 | // Note: The is_exact flag from the return value should not be used. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7164 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact= */ true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7165 | } else { |
| 7166 | return ReferenceTypeInfo::CreateInvalid(); |
| 7167 | } |
| 7168 | } |
| 7169 | |
| 7170 | // Target class RTI is marked as valid by RTP if the klass_ is admissible. |
| 7171 | void SetValidTargetClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 7172 | DCHECK(klass_ != nullptr); |
| 7173 | SetPackedFlag<kFlagValidTargetClassRTI>(true); |
| 7174 | } |
| 7175 | |
| 7176 | Handle<mirror::Class> GetClass() const { |
| 7177 | return klass_; |
| 7178 | } |
| 7179 | |
| 7180 | protected: |
| 7181 | DEFAULT_COPY_CONSTRUCTOR(TypeCheckInstruction); |
| 7182 | |
| 7183 | private: |
| 7184 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 7185 | static constexpr size_t kFieldTypeCheckKindSize = |
| 7186 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 7187 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 7188 | static constexpr size_t kFlagValidTargetClassRTI = kFlagMustDoNullCheck + 1; |
| 7189 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagValidTargetClassRTI + 1; |
| 7190 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7191 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
| 7192 | |
| 7193 | Handle<mirror::Class> klass_; |
| 7194 | }; |
| 7195 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7196 | class HInstanceOf final : public HTypeCheckInstruction { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7197 | public: |
| 7198 | HInstanceOf(HInstruction* object, |
| 7199 | HInstruction* target_class_or_null, |
| 7200 | TypeCheckKind check_kind, |
| 7201 | Handle<mirror::Class> klass, |
| 7202 | uint32_t dex_pc, |
| 7203 | ArenaAllocator* allocator, |
| 7204 | HIntConstant* bitstring_path_to_root, |
| 7205 | HIntConstant* bitstring_mask) |
| 7206 | : HTypeCheckInstruction(kInstanceOf, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7207 | DataType::Type::kBool, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7208 | object, |
| 7209 | target_class_or_null, |
| 7210 | check_kind, |
| 7211 | klass, |
| 7212 | dex_pc, |
| 7213 | allocator, |
| 7214 | bitstring_path_to_root, |
| 7215 | bitstring_mask, |
| 7216 | SideEffectsForArchRuntimeCalls(check_kind)) {} |
| 7217 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7218 | bool IsClonable() const override { return true; } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 7219 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7220 | bool NeedsEnvironment() const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7221 | return CanCallRuntime(GetTypeCheckKind()); |
| 7222 | } |
| 7223 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7224 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 7225 | // Mips currently does runtime calls for any other checks. |
| 7226 | return check_kind != TypeCheckKind::kExactCheck; |
| 7227 | } |
| 7228 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7229 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7230 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7231 | } |
| 7232 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7233 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7234 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7235 | protected: |
| 7236 | DEFAULT_COPY_CONSTRUCTOR(InstanceOf); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7237 | }; |
| 7238 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7239 | class HBoundType final : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7240 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 7241 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7242 | : HExpression(kBoundType, DataType::Type::kReference, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7243 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 7244 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 7245 | SetPackedFlag<kFlagCanBeNull>(true); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7246 | DCHECK_EQ(input->GetType(), DataType::Type::kReference); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7247 | SetRawInputAt(0, input); |
| 7248 | } |
| 7249 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7250 | bool InstructionDataEquals(const HInstruction* other) const override; |
| 7251 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7252 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7253 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7254 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7255 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7256 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7257 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7258 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7259 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 7260 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7261 | } |
| 7262 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7263 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7264 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7265 | DECLARE_INSTRUCTION(BoundType); |
| 7266 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7267 | protected: |
| 7268 | DEFAULT_COPY_CONSTRUCTOR(BoundType); |
| 7269 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7270 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7271 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 7272 | // is false then CanBeNull() cannot be true). |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7273 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7274 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 7275 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 7276 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7277 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7278 | // 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] | 7279 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 7280 | // It is used to bound the type in cases like: |
| 7281 | // if (x instanceof ClassX) { |
| 7282 | // // uper_bound_ will be ClassX |
| 7283 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7284 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7285 | }; |
| 7286 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7287 | class HCheckCast final : public HTypeCheckInstruction { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7288 | public: |
| 7289 | HCheckCast(HInstruction* object, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7290 | HInstruction* target_class_or_null, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7291 | TypeCheckKind check_kind, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7292 | Handle<mirror::Class> klass, |
| 7293 | uint32_t dex_pc, |
| 7294 | ArenaAllocator* allocator, |
| 7295 | HIntConstant* bitstring_path_to_root, |
| 7296 | HIntConstant* bitstring_mask) |
| 7297 | : HTypeCheckInstruction(kCheckCast, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7298 | DataType::Type::kVoid, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7299 | object, |
| 7300 | target_class_or_null, |
| 7301 | check_kind, |
| 7302 | klass, |
| 7303 | dex_pc, |
| 7304 | allocator, |
| 7305 | bitstring_path_to_root, |
| 7306 | bitstring_mask, |
| 7307 | SideEffects::CanTriggerGC()) {} |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7308 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7309 | bool IsClonable() const override { return true; } |
| 7310 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7311 | // Instruction may throw a CheckCastError. |
| 7312 | return true; |
| 7313 | } |
| 7314 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7315 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7316 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7317 | DECLARE_INSTRUCTION(CheckCast); |
| 7318 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7319 | protected: |
| 7320 | DEFAULT_COPY_CONSTRUCTOR(CheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7321 | }; |
| 7322 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 7323 | /** |
| 7324 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 7325 | * @details We define the combined barrier types that are actually required |
| 7326 | * by the Java Memory Model, rather than using exactly the terminology from |
| 7327 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 7328 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 7329 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 7330 | * The current recipe is as follows: |
| 7331 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 7332 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 7333 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 7334 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 7335 | * class has final fields. |
| 7336 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 7337 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 7338 | */ |
| 7339 | enum MemBarrierKind { |
| 7340 | kAnyStore, |
| 7341 | kLoadAny, |
| 7342 | kStoreStore, |
| 7343 | kAnyAny, |
| 7344 | kNTStoreStore, |
| 7345 | kLastBarrierKind = kNTStoreStore |
| 7346 | }; |
| 7347 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 7348 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7349 | class HMemoryBarrier final : public HExpression<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7350 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7351 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7352 | : HExpression(kMemoryBarrier, |
| 7353 | SideEffects::AllWritesAndReads(), // Assume write/read on all fields/arrays. |
| 7354 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7355 | SetPackedField<BarrierKindField>(barrier_kind); |
| 7356 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7357 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7358 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7359 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7360 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7361 | |
| 7362 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 7363 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7364 | protected: |
| 7365 | DEFAULT_COPY_CONSTRUCTOR(MemoryBarrier); |
| 7366 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7367 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7368 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 7369 | static constexpr size_t kFieldBarrierKindSize = |
| 7370 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 7371 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 7372 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 7373 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 7374 | "Too many packed fields."); |
| 7375 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7376 | }; |
| 7377 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7378 | // A constructor fence orders all prior stores to fields that could be accessed via a final field of |
| 7379 | // the specified object(s), with respect to any subsequent store that might "publish" |
| 7380 | // (i.e. make visible) the specified object to another thread. |
| 7381 | // |
| 7382 | // JLS 17.5.1 "Semantics of final fields" states that a freeze action happens |
| 7383 | // for all final fields (that were set) at the end of the invoked constructor. |
| 7384 | // |
| 7385 | // The constructor fence models the freeze actions for the final fields of an object |
| 7386 | // being constructed (semantically at the end of the constructor). Constructor fences |
| 7387 | // have a per-object affinity; two separate objects being constructed get two separate |
| 7388 | // constructor fences. |
| 7389 | // |
| 7390 | // (Note: that if calling a super-constructor or forwarding to another constructor, |
| 7391 | // the freezes would happen at the end of *that* constructor being invoked). |
| 7392 | // |
| 7393 | // The memory model guarantees that when the object being constructed is "published" after |
| 7394 | // constructor completion (i.e. escapes the current thread via a store), then any final field |
| 7395 | // writes must be observable on other threads (once they observe that publication). |
| 7396 | // |
| 7397 | // Further, anything written before the freeze, and read by dereferencing through the final field, |
| 7398 | // must also be visible (so final object field could itself have an object with non-final fields; |
| 7399 | // yet the freeze must also extend to them). |
| 7400 | // |
| 7401 | // Constructor example: |
| 7402 | // |
| 7403 | // class HasFinal { |
| 7404 | // final int field; Optimizing IR for <init>()V: |
| 7405 | // HasFinal() { |
| 7406 | // field = 123; HInstanceFieldSet(this, HasFinal.field, 123) |
| 7407 | // // freeze(this.field); HConstructorFence(this) |
| 7408 | // } HReturn |
| 7409 | // } |
| 7410 | // |
| 7411 | // HConstructorFence can serve double duty as a fence for new-instance/new-array allocations of |
| 7412 | // already-initialized classes; in that case the allocation must act as a "default-initializer" |
| 7413 | // of the object which effectively writes the class pointer "final field". |
| 7414 | // |
| 7415 | // For example, we can model default-initialiation as roughly the equivalent of the following: |
| 7416 | // |
| 7417 | // class Object { |
| 7418 | // private final Class header; |
| 7419 | // } |
| 7420 | // |
| 7421 | // Java code: Optimizing IR: |
| 7422 | // |
| 7423 | // T new_instance<T>() { |
| 7424 | // Object obj = allocate_memory(T.class.size); obj = HInvoke(art_quick_alloc_object, T) |
| 7425 | // obj.header = T.class; // header write is done by above call. |
| 7426 | // // freeze(obj.header) HConstructorFence(obj) |
| 7427 | // return (T)obj; |
| 7428 | // } |
| 7429 | // |
| 7430 | // See also: |
Vladimir Marko | c1c3452 | 2018-10-31 13:56:49 +0000 | [diff] [blame] | 7431 | // * DexCompilationUnit::RequiresConstructorBarrier |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7432 | // * QuasiAtomic::ThreadFenceForConstructor |
| 7433 | // |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7434 | class HConstructorFence final : public HVariableInputSizeInstruction { |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7435 | // A fence has variable inputs because the inputs can be removed |
| 7436 | // after prepare_for_register_allocation phase. |
| 7437 | // (TODO: In the future a fence could freeze multiple objects |
| 7438 | // after merging two fences together.) |
| 7439 | public: |
| 7440 | // `fence_object` is the reference that needs to be protected for correct publication. |
| 7441 | // |
| 7442 | // It makes sense in the following situations: |
| 7443 | // * <init> constructors, it's the "this" parameter (i.e. HParameterValue, s.t. IsThis() == true). |
| 7444 | // * new-instance-like instructions, it's the return value (i.e. HNewInstance). |
| 7445 | // |
| 7446 | // After construction the `fence_object` becomes the 0th input. |
| 7447 | // This is not an input in a real sense, but just a convenient place to stash the information |
| 7448 | // about the associated object. |
| 7449 | HConstructorFence(HInstruction* fence_object, |
| 7450 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7451 | ArenaAllocator* allocator) |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7452 | // We strongly suspect there is not a more accurate way to describe the fine-grained reordering |
| 7453 | // constraints described in the class header. We claim that these SideEffects constraints |
| 7454 | // enforce a superset of the real constraints. |
| 7455 | // |
| 7456 | // The ordering described above is conservatively modeled with SideEffects as follows: |
| 7457 | // |
| 7458 | // * To prevent reordering of the publication stores: |
| 7459 | // ----> "Reads of objects" is the initial SideEffect. |
| 7460 | // * For every primitive final field store in the constructor: |
| 7461 | // ----> Union that field's type as a read (e.g. "Read of T") into the SideEffect. |
| 7462 | // * If there are any stores to reference final fields in the constructor: |
| 7463 | // ----> Use a more conservative "AllReads" SideEffect because any stores to any references |
| 7464 | // that are reachable from `fence_object` also need to be prevented for reordering |
| 7465 | // (and we do not want to do alias analysis to figure out what those stores are). |
| 7466 | // |
| 7467 | // In the implementation, this initially starts out as an "all reads" side effect; this is an |
| 7468 | // even more conservative approach than the one described above, and prevents all of the |
| 7469 | // above reordering without analyzing any of the instructions in the constructor. |
| 7470 | // |
| 7471 | // If in a later phase we discover that there are no writes to reference final fields, |
| 7472 | // 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] | 7473 | : HVariableInputSizeInstruction(kConstructorFence, |
| 7474 | SideEffects::AllReads(), |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7475 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7476 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7477 | /* number_of_inputs= */ 1, |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7478 | kArenaAllocConstructorFenceInputs) { |
| 7479 | DCHECK(fence_object != nullptr); |
| 7480 | SetRawInputAt(0, fence_object); |
| 7481 | } |
| 7482 | |
| 7483 | // The object associated with this constructor fence. |
| 7484 | // |
| 7485 | // (Note: This will be null after the prepare_for_register_allocation phase, |
| 7486 | // as all constructor fence inputs are removed there). |
| 7487 | HInstruction* GetFenceObject() const { |
| 7488 | return InputAt(0); |
| 7489 | } |
| 7490 | |
| 7491 | // Find all the HConstructorFence uses (`fence_use`) for `this` and: |
| 7492 | // - Delete `fence_use` from `this`'s use list. |
| 7493 | // - Delete `this` from `fence_use`'s inputs list. |
| 7494 | // - If the `fence_use` is dead, remove it from the graph. |
| 7495 | // |
| 7496 | // A fence is considered dead once it no longer has any uses |
| 7497 | // and all of the inputs are dead. |
| 7498 | // |
| 7499 | // This must *not* be called during/after prepare_for_register_allocation, |
| 7500 | // because that removes all the inputs to the fences but the fence is actually |
| 7501 | // still considered live. |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7502 | // |
| 7503 | // Returns how many HConstructorFence instructions were removed from graph. |
| 7504 | static size_t RemoveConstructorFences(HInstruction* instruction); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7505 | |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7506 | // Combine all inputs of `this` and `other` instruction and remove |
| 7507 | // `other` from the graph. |
| 7508 | // |
| 7509 | // Inputs are unique after the merge. |
| 7510 | // |
| 7511 | // Requirement: `this` must not be the same as `other. |
| 7512 | void Merge(HConstructorFence* other); |
| 7513 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7514 | // Check if this constructor fence is protecting |
| 7515 | // an HNewInstance or HNewArray that is also the immediate |
| 7516 | // predecessor of `this`. |
| 7517 | // |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7518 | // If `ignore_inputs` is true, then the immediate predecessor doesn't need |
| 7519 | // to be one of the inputs of `this`. |
| 7520 | // |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7521 | // Returns the associated HNewArray or HNewInstance, |
| 7522 | // or null otherwise. |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7523 | HInstruction* GetAssociatedAllocation(bool ignore_inputs = false); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7524 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7525 | DECLARE_INSTRUCTION(ConstructorFence); |
| 7526 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7527 | protected: |
| 7528 | DEFAULT_COPY_CONSTRUCTOR(ConstructorFence); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7529 | }; |
| 7530 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7531 | class HMonitorOperation final : public HExpression<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7532 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7533 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7534 | kEnter, |
| 7535 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7536 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7537 | }; |
| 7538 | |
| 7539 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7540 | : HExpression(kMonitorOperation, |
| 7541 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 7542 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7543 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7544 | SetRawInputAt(0, object); |
| 7545 | } |
| 7546 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7547 | // Instruction may go into runtime, so we need an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7548 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 7549 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7550 | bool CanThrow() const override { |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 7551 | // Verifier guarantees that monitor-exit cannot throw. |
| 7552 | // This is important because it allows the HGraphBuilder to remove |
| 7553 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 7554 | return IsEnter(); |
| 7555 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7556 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7557 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 7558 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7559 | |
| 7560 | DECLARE_INSTRUCTION(MonitorOperation); |
| 7561 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7562 | protected: |
| 7563 | DEFAULT_COPY_CONSTRUCTOR(MonitorOperation); |
| 7564 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7565 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7566 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 7567 | static constexpr size_t kFieldOperationKindSize = |
| 7568 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 7569 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 7570 | kFieldOperationKind + kFieldOperationKindSize; |
| 7571 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7572 | "Too many packed fields."); |
| 7573 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7574 | }; |
| 7575 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7576 | class HSelect final : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7577 | public: |
| 7578 | HSelect(HInstruction* condition, |
| 7579 | HInstruction* true_value, |
| 7580 | HInstruction* false_value, |
| 7581 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7582 | : HExpression(kSelect, HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7583 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 7584 | |
| 7585 | // First input must be `true_value` or `false_value` to allow codegens to |
| 7586 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 7587 | // that architectures which implement HSelect as a conditional move also |
| 7588 | // will not need to invert the condition. |
| 7589 | SetRawInputAt(0, false_value); |
| 7590 | SetRawInputAt(1, true_value); |
| 7591 | SetRawInputAt(2, condition); |
| 7592 | } |
| 7593 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7594 | bool IsClonable() const override { return true; } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7595 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 7596 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 7597 | HInstruction* GetCondition() const { return InputAt(2); } |
| 7598 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7599 | bool CanBeMoved() const override { return true; } |
| 7600 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7601 | return true; |
| 7602 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7603 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7604 | bool CanBeNull() const override { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7605 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 7606 | } |
| 7607 | |
| 7608 | DECLARE_INSTRUCTION(Select); |
| 7609 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7610 | protected: |
| 7611 | DEFAULT_COPY_CONSTRUCTOR(Select); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7612 | }; |
| 7613 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 7614 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7615 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7616 | MoveOperands(Location source, |
| 7617 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7618 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7619 | HInstruction* instruction) |
| 7620 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7621 | |
| 7622 | Location GetSource() const { return source_; } |
| 7623 | Location GetDestination() const { return destination_; } |
| 7624 | |
| 7625 | void SetSource(Location value) { source_ = value; } |
| 7626 | void SetDestination(Location value) { destination_ = value; } |
| 7627 | |
| 7628 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 7629 | // destination (but not the source). |
| 7630 | Location MarkPending() { |
| 7631 | DCHECK(!IsPending()); |
| 7632 | Location dest = destination_; |
| 7633 | destination_ = Location::NoLocation(); |
| 7634 | return dest; |
| 7635 | } |
| 7636 | |
| 7637 | void ClearPending(Location dest) { |
| 7638 | DCHECK(IsPending()); |
| 7639 | destination_ = dest; |
| 7640 | } |
| 7641 | |
| 7642 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7643 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 7644 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7645 | } |
| 7646 | |
| 7647 | // True if this blocks a move from the given location. |
| 7648 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 7649 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7650 | } |
| 7651 | |
| 7652 | // A move is redundant if it's been eliminated, if its source and |
| 7653 | // destination are the same, or if its destination is unneeded. |
| 7654 | bool IsRedundant() const { |
| 7655 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 7656 | } |
| 7657 | |
| 7658 | // We clear both operands to indicate move that's been eliminated. |
| 7659 | void Eliminate() { |
| 7660 | source_ = destination_ = Location::NoLocation(); |
| 7661 | } |
| 7662 | |
| 7663 | bool IsEliminated() const { |
| 7664 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 7665 | return source_.IsInvalid(); |
| 7666 | } |
| 7667 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7668 | DataType::Type GetType() const { return type_; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7669 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7670 | bool Is64BitMove() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7671 | return DataType::Is64BitType(type_); |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7672 | } |
| 7673 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7674 | HInstruction* GetInstruction() const { return instruction_; } |
| 7675 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7676 | private: |
| 7677 | Location source_; |
| 7678 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7679 | // The type this move is for. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7680 | DataType::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7681 | // The instruction this move is assocatied with. Null when this move is |
| 7682 | // for moving an input in the expected locations of user (including a phi user). |
| 7683 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 7684 | // in the same parallel move. |
| 7685 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7686 | }; |
| 7687 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7688 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 7689 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7690 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 7691 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7692 | class HParallelMove final : public HExpression<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7693 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7694 | explicit HParallelMove(ArenaAllocator* allocator, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7695 | : HExpression(kParallelMove, SideEffects::None(), dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7696 | moves_(allocator->Adapter(kArenaAllocMoveOperands)) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7697 | moves_.reserve(kDefaultNumberOfMoves); |
| 7698 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7699 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7700 | void AddMove(Location source, |
| 7701 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7702 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7703 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 7704 | DCHECK(source.IsValid()); |
| 7705 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7706 | if (kIsDebugBuild) { |
| 7707 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7708 | for (const MoveOperands& move : moves_) { |
| 7709 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7710 | // Special case the situation where the move is for the spill slot |
| 7711 | // of the instruction. |
| 7712 | if ((GetPrevious() == instruction) |
| 7713 | || ((GetPrevious() == nullptr) |
| 7714 | && instruction->IsPhi() |
| 7715 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7716 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7717 | << "Doing parallel moves for the same instruction."; |
| 7718 | } else { |
| 7719 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 7720 | } |
| 7721 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 7722 | } |
| 7723 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7724 | for (const MoveOperands& move : moves_) { |
| 7725 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7726 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7727 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7728 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7729 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7730 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7731 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7732 | } |
| 7733 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7734 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7735 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7736 | } |
| 7737 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7738 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7739 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 7740 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7741 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7742 | protected: |
| 7743 | DEFAULT_COPY_CONSTRUCTOR(ParallelMove); |
| 7744 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7745 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7746 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7747 | }; |
| 7748 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7749 | // This instruction computes an intermediate address pointing in the 'middle' of an object. The |
| 7750 | // result pointer cannot be handled by GC, so extra care is taken to make sure that this value is |
| 7751 | // never used across anything that can trigger GC. |
| 7752 | // The result of this instruction is not a pointer in the sense of `DataType::Type::kreference`. |
| 7753 | // So we represent it by the type `DataType::Type::kInt`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7754 | class HIntermediateAddress final : public HExpression<2> { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7755 | public: |
| 7756 | HIntermediateAddress(HInstruction* base_address, HInstruction* offset, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7757 | : HExpression(kIntermediateAddress, |
| 7758 | DataType::Type::kInt32, |
| 7759 | SideEffects::DependsOnGC(), |
| 7760 | dex_pc) { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7761 | DCHECK_EQ(DataType::Size(DataType::Type::kInt32), |
| 7762 | DataType::Size(DataType::Type::kReference)) |
| 7763 | << "kPrimInt and kPrimNot have different sizes."; |
| 7764 | SetRawInputAt(0, base_address); |
| 7765 | SetRawInputAt(1, offset); |
| 7766 | } |
| 7767 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7768 | bool IsClonable() const override { return true; } |
| 7769 | bool CanBeMoved() const override { return true; } |
| 7770 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7771 | return true; |
| 7772 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7773 | bool IsActualObject() const override { return false; } |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7774 | |
| 7775 | HInstruction* GetBaseAddress() const { return InputAt(0); } |
| 7776 | HInstruction* GetOffset() const { return InputAt(1); } |
| 7777 | |
| 7778 | DECLARE_INSTRUCTION(IntermediateAddress); |
| 7779 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7780 | protected: |
| 7781 | DEFAULT_COPY_CONSTRUCTOR(IntermediateAddress); |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7782 | }; |
| 7783 | |
| 7784 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7785 | } // namespace art |
| 7786 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 7787 | #include "nodes_vector.h" |
| 7788 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7789 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 7790 | #include "nodes_shared.h" |
| 7791 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7792 | #ifdef ART_ENABLE_CODEGEN_mips |
| 7793 | #include "nodes_mips.h" |
| 7794 | #endif |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 7795 | #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64) |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7796 | #include "nodes_x86.h" |
| 7797 | #endif |
| 7798 | |
| 7799 | namespace art { |
| 7800 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7801 | class OptimizingCompilerStats; |
| 7802 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7803 | class HGraphVisitor : public ValueObject { |
| 7804 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7805 | explicit HGraphVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7806 | : stats_(stats), |
| 7807 | graph_(graph) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 7808 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7809 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7810 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7811 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 7812 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7813 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7814 | void VisitInsertionOrder(); |
| 7815 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7816 | // Visit the graph following dominator tree reverse post-order. |
| 7817 | void VisitReversePostOrder(); |
| 7818 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 7819 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7820 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7821 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7822 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7823 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 7824 | |
| 7825 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7826 | |
| 7827 | #undef DECLARE_VISIT_INSTRUCTION |
| 7828 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7829 | protected: |
| 7830 | OptimizingCompilerStats* stats_; |
| 7831 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7832 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 7833 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7834 | |
| 7835 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 7836 | }; |
| 7837 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7838 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 7839 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7840 | explicit HGraphDelegateVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7841 | : HGraphVisitor(graph, stats) {} |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7842 | virtual ~HGraphDelegateVisitor() {} |
| 7843 | |
| 7844 | // Visit functions that delegate to to super class. |
| 7845 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7846 | void Visit##name(H##name* instr) override { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7847 | |
| 7848 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7849 | |
| 7850 | #undef DECLARE_VISIT_INSTRUCTION |
| 7851 | |
| 7852 | private: |
| 7853 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 7854 | }; |
| 7855 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7856 | // Create a clone of the instruction, insert it into the graph; replace the old one with a new |
| 7857 | // and remove the old instruction. |
| 7858 | HInstruction* ReplaceInstrOrPhiByClone(HInstruction* instr); |
| 7859 | |
| 7860 | // Create a clone for each clonable instructions/phis and replace the original with the clone. |
| 7861 | // |
| 7862 | // Used for testing individual instruction cloner. |
| 7863 | class CloneAndReplaceInstructionVisitor : public HGraphDelegateVisitor { |
| 7864 | public: |
| 7865 | explicit CloneAndReplaceInstructionVisitor(HGraph* graph) |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7866 | : HGraphDelegateVisitor(graph), instr_replaced_by_clones_count_(0) {} |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7867 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7868 | void VisitInstruction(HInstruction* instruction) override { |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7869 | if (instruction->IsClonable()) { |
| 7870 | ReplaceInstrOrPhiByClone(instruction); |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7871 | instr_replaced_by_clones_count_++; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7872 | } |
| 7873 | } |
| 7874 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7875 | size_t GetInstrReplacedByClonesCount() const { return instr_replaced_by_clones_count_; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7876 | |
| 7877 | private: |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7878 | size_t instr_replaced_by_clones_count_; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7879 | |
| 7880 | DISALLOW_COPY_AND_ASSIGN(CloneAndReplaceInstructionVisitor); |
| 7881 | }; |
| 7882 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7883 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7884 | // of an inner loop. The order in which the blocks are iterated is on their |
| 7885 | // block id. |
| 7886 | class HBlocksInLoopIterator : public ValueObject { |
| 7887 | public: |
| 7888 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 7889 | : blocks_in_loop_(info.GetBlocks()), |
| 7890 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 7891 | index_(0) { |
| 7892 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 7893 | Advance(); |
| 7894 | } |
| 7895 | } |
| 7896 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7897 | bool Done() const { return index_ == blocks_.size(); } |
| 7898 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7899 | void Advance() { |
| 7900 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7901 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7902 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 7903 | break; |
| 7904 | } |
| 7905 | } |
| 7906 | } |
| 7907 | |
| 7908 | private: |
| 7909 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7910 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7911 | size_t index_; |
| 7912 | |
| 7913 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 7914 | }; |
| 7915 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7916 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7917 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 7918 | // post order. |
| 7919 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 7920 | public: |
| 7921 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 7922 | : blocks_in_loop_(info.GetBlocks()), |
| 7923 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 7924 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7925 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7926 | Advance(); |
| 7927 | } |
| 7928 | } |
| 7929 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7930 | bool Done() const { return index_ == blocks_.size(); } |
| 7931 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7932 | void Advance() { |
| 7933 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7934 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 7935 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7936 | break; |
| 7937 | } |
| 7938 | } |
| 7939 | } |
| 7940 | |
| 7941 | private: |
| 7942 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7943 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7944 | size_t index_; |
| 7945 | |
| 7946 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 7947 | }; |
| 7948 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7949 | // Returns int64_t value of a properly typed constant. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7950 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7951 | if (constant->IsIntConstant()) { |
| 7952 | return constant->AsIntConstant()->GetValue(); |
| 7953 | } else if (constant->IsLongConstant()) { |
| 7954 | return constant->AsLongConstant()->GetValue(); |
| 7955 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 7956 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7957 | return 0; |
| 7958 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7959 | } |
| 7960 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7961 | // Returns true iff instruction is an integral constant (and sets value on success). |
| 7962 | inline bool IsInt64AndGet(HInstruction* instruction, /*out*/ int64_t* value) { |
| 7963 | if (instruction->IsIntConstant()) { |
| 7964 | *value = instruction->AsIntConstant()->GetValue(); |
| 7965 | return true; |
| 7966 | } else if (instruction->IsLongConstant()) { |
| 7967 | *value = instruction->AsLongConstant()->GetValue(); |
| 7968 | return true; |
| 7969 | } else if (instruction->IsNullConstant()) { |
| 7970 | *value = 0; |
| 7971 | return true; |
| 7972 | } |
| 7973 | return false; |
| 7974 | } |
| 7975 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 7976 | // Returns true iff instruction is the given integral constant. |
| 7977 | inline bool IsInt64Value(HInstruction* instruction, int64_t value) { |
| 7978 | int64_t val = 0; |
| 7979 | return IsInt64AndGet(instruction, &val) && val == value; |
| 7980 | } |
| 7981 | |
| 7982 | // Returns true iff instruction is a zero bit pattern. |
| 7983 | inline bool IsZeroBitPattern(HInstruction* instruction) { |
| 7984 | return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern(); |
| 7985 | } |
| 7986 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7987 | // Implement HInstruction::Is##type() for concrete instructions. |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7988 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7989 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } |
| 7990 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7991 | #undef INSTRUCTION_TYPE_CHECK |
| 7992 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7993 | // Implement HInstruction::Is##type() for abstract instructions. |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7994 | #define INSTRUCTION_TYPE_CHECK_RESULT(type, super) \ |
| 7995 | std::is_base_of<BaseType, H##type>::value, |
| 7996 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 7997 | inline bool HInstruction::Is##type() const { \ |
| 7998 | DCHECK_LT(GetKind(), kLastInstructionKind); \ |
| 7999 | using BaseType = H##type; \ |
| 8000 | static constexpr bool results[] = { \ |
| 8001 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK_RESULT) \ |
| 8002 | }; \ |
| 8003 | return results[static_cast<size_t>(GetKind())]; \ |
| 8004 | } |
| 8005 | |
| 8006 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 8007 | #undef INSTRUCTION_TYPE_CHECK |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 8008 | #undef INSTRUCTION_TYPE_CHECK_RESULT |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8009 | |
| 8010 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8011 | inline const H##type* HInstruction::As##type() const { \ |
| 8012 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 8013 | } \ |
| 8014 | inline H##type* HInstruction::As##type() { \ |
| 8015 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 8016 | } |
| 8017 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8018 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 8019 | #undef INSTRUCTION_TYPE_CAST |
| 8020 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8021 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 8022 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 8023 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 8024 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 8025 | size_t number_of_new_blocks, |
| 8026 | size_t after) { |
| 8027 | DCHECK_LT(after, blocks->size()); |
| 8028 | size_t old_size = blocks->size(); |
| 8029 | size_t new_size = old_size + number_of_new_blocks; |
| 8030 | blocks->resize(new_size); |
| 8031 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 8032 | } |
| 8033 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8034 | /* |
| 8035 | * Hunt "under the hood" of array lengths (leading to array references), |
| 8036 | * null checks (also leading to array references), and new arrays |
| 8037 | * (leading to the actual length). This makes it more likely related |
| 8038 | * instructions become actually comparable. |
| 8039 | */ |
| 8040 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 8041 | while (instruction->IsArrayLength() || |
| 8042 | instruction->IsNullCheck() || |
| 8043 | instruction->IsNewArray()) { |
| 8044 | instruction = instruction->IsNewArray() |
| 8045 | ? instruction->AsNewArray()->GetLength() |
| 8046 | : instruction->InputAt(0); |
| 8047 | } |
| 8048 | return instruction; |
| 8049 | } |
| 8050 | |
Artem Serov | 21c7e6f | 2017-07-27 16:04:42 +0100 | [diff] [blame] | 8051 | void RemoveEnvironmentUses(HInstruction* instruction); |
| 8052 | bool HasEnvironmentUsedByOthers(HInstruction* instruction); |
| 8053 | void ResetEnvironmentInputRecords(HInstruction* instruction); |
| 8054 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8055 | } // namespace art |
| 8056 | |
| 8057 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |