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" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 29 | #include "base/stl_util.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 30 | #include "base/transform_array_ref.h" |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 31 | #include "data_type.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 32 | #include "deoptimization_kind.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 33 | #include "dex/dex_file.h" |
| 34 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 35 | #include "dex/invoke_type.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 36 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 37 | #include "handle.h" |
| 38 | #include "handle_scope.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 39 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 40 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 41 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 42 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 43 | #include "offsets.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 44 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 45 | |
| 46 | namespace art { |
| 47 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 48 | class ArenaStack; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 49 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 50 | class HBasicBlock; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 51 | class HConstructorFence; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 52 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 53 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 54 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 55 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 56 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 57 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 58 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 59 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 60 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 61 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 62 | class HNullConstant; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 63 | class HParameterValue; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 64 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 65 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 66 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 67 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 68 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 69 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 70 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 71 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 72 | namespace mirror { |
| 73 | class DexCache; |
| 74 | } // namespace mirror |
| 75 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 76 | static const int kDefaultNumberOfBlocks = 8; |
| 77 | static const int kDefaultNumberOfSuccessors = 2; |
| 78 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 79 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 80 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 81 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 82 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 83 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 84 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 85 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 86 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 87 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 88 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 89 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 90 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 91 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 92 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 93 | static constexpr uint32_t kNoDexPc = -1; |
| 94 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 95 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 96 | // For the purposes of the compiler, the dex files must actually be the same object |
| 97 | // if we want to safely treat them as the same. This is especially important for JIT |
| 98 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 99 | // times and provide different class resolution but no two class loaders should ever |
| 100 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 101 | // all sorts of weird failures. |
| 102 | return &lhs == &rhs; |
| 103 | } |
| 104 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 105 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 106 | // All types. |
| 107 | kCondEQ, // == |
| 108 | kCondNE, // != |
| 109 | // Signed integers and floating-point numbers. |
| 110 | kCondLT, // < |
| 111 | kCondLE, // <= |
| 112 | kCondGT, // > |
| 113 | kCondGE, // >= |
| 114 | // Unsigned integers. |
| 115 | kCondB, // < |
| 116 | kCondBE, // <= |
| 117 | kCondA, // > |
| 118 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 119 | // First and last aliases. |
| 120 | kCondFirst = kCondEQ, |
| 121 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 124 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 125 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 126 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 127 | kAnalysisFailThrowCatchLoop, |
| 128 | kAnalysisFailAmbiguousArrayOp, |
| 129 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 132 | template <typename T> |
| 133 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 134 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 135 | } |
| 136 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 137 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 138 | public: |
| 139 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 140 | |
| 141 | void AddInstruction(HInstruction* instruction); |
| 142 | void RemoveInstruction(HInstruction* instruction); |
| 143 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 144 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 145 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 146 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 147 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 148 | // Return true if this list contains `instruction`. |
| 149 | bool Contains(HInstruction* instruction) const; |
| 150 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 151 | // Return true if `instruction1` is found before `instruction2` in |
| 152 | // this instruction list and false otherwise. Abort if none |
| 153 | // of these instructions is found. |
| 154 | bool FoundBefore(const HInstruction* instruction1, |
| 155 | const HInstruction* instruction2) const; |
| 156 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 157 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 158 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 159 | |
| 160 | // Update the block of all instructions to be `block`. |
| 161 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 162 | |
| 163 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 164 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 165 | void Add(const HInstructionList& instruction_list); |
| 166 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 167 | // Return the number of instructions in the list. This is an expensive operation. |
| 168 | size_t CountSize() const; |
| 169 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 170 | private: |
| 171 | HInstruction* first_instruction_; |
| 172 | HInstruction* last_instruction_; |
| 173 | |
| 174 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 175 | friend class HGraph; |
| 176 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 177 | friend class HInstructionIterator; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 178 | friend class HInstructionIteratorHandleChanges; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 179 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 180 | |
| 181 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 182 | }; |
| 183 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 184 | class ReferenceTypeInfo : ValueObject { |
| 185 | public: |
| 186 | typedef Handle<mirror::Class> TypeHandle; |
| 187 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 188 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 189 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 190 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 191 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 192 | } |
| 193 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 194 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 195 | return ReferenceTypeInfo(type_handle, is_exact); |
| 196 | } |
| 197 | |
| 198 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 199 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 200 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 201 | return handle.GetReference() != nullptr; |
| 202 | } |
| 203 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 204 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 205 | return IsValidHandle(type_handle_); |
| 206 | } |
| 207 | |
| 208 | bool IsExact() const { return is_exact_; } |
| 209 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 210 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 211 | DCHECK(IsValid()); |
| 212 | return GetTypeHandle()->IsObjectClass(); |
| 213 | } |
| 214 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 215 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 216 | DCHECK(IsValid()); |
| 217 | return GetTypeHandle()->IsStringClass(); |
| 218 | } |
| 219 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 220 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 221 | DCHECK(IsValid()); |
| 222 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 223 | } |
| 224 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 225 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 226 | DCHECK(IsValid()); |
| 227 | return GetTypeHandle()->IsInterface(); |
| 228 | } |
| 229 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 230 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 231 | DCHECK(IsValid()); |
| 232 | return GetTypeHandle()->IsArrayClass(); |
| 233 | } |
| 234 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 235 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 236 | DCHECK(IsValid()); |
| 237 | return GetTypeHandle()->IsPrimitiveArray(); |
| 238 | } |
| 239 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 240 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 241 | DCHECK(IsValid()); |
| 242 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 243 | } |
| 244 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 245 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 246 | DCHECK(IsValid()); |
| 247 | if (!IsExact()) return false; |
| 248 | if (!IsArrayClass()) return false; |
| 249 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 250 | } |
| 251 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 252 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 253 | DCHECK(IsValid()); |
| 254 | if (!IsExact()) return false; |
| 255 | if (!IsArrayClass()) return false; |
| 256 | if (!rti.IsArrayClass()) return false; |
| 257 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 258 | rti.GetTypeHandle()->GetComponentType()); |
| 259 | } |
| 260 | |
| 261 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 262 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 263 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 264 | DCHECK(IsValid()); |
| 265 | DCHECK(rti.IsValid()); |
| 266 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 267 | } |
| 268 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 269 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 270 | DCHECK(IsValid()); |
| 271 | DCHECK(rti.IsValid()); |
| 272 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 273 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 274 | } |
| 275 | |
| 276 | // Returns true if the type information provide the same amount of details. |
| 277 | // Note that it does not mean that the instructions have the same actual type |
| 278 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 279 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 280 | if (!IsValid() && !rti.IsValid()) { |
| 281 | // Invalid types are equal. |
| 282 | return true; |
| 283 | } |
| 284 | if (!IsValid() || !rti.IsValid()) { |
| 285 | // One is valid, the other not. |
| 286 | return false; |
| 287 | } |
| 288 | return IsExact() == rti.IsExact() |
| 289 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 290 | } |
| 291 | |
| 292 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 293 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 294 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 295 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 296 | |
| 297 | // The class of the object. |
| 298 | TypeHandle type_handle_; |
| 299 | // Whether or not the type is exact or a superclass of the actual type. |
| 300 | // Whether or not we have any information about this type. |
| 301 | bool is_exact_; |
| 302 | }; |
| 303 | |
| 304 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 305 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 306 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 307 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 308 | public: |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 309 | HGraph(ArenaAllocator* allocator, |
| 310 | ArenaStack* arena_stack, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 311 | const DexFile& dex_file, |
| 312 | uint32_t method_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 313 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 314 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 315 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 316 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 317 | int start_instruction_id = 0) |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 318 | : allocator_(allocator), |
| 319 | arena_stack_(arena_stack), |
| 320 | blocks_(allocator->Adapter(kArenaAllocBlockList)), |
| 321 | reverse_post_order_(allocator->Adapter(kArenaAllocReversePostOrder)), |
| 322 | linear_order_(allocator->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 323 | entry_block_(nullptr), |
| 324 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 325 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 326 | number_of_vregs_(0), |
| 327 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 328 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 329 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 330 | has_try_catch_(false), |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 331 | has_simd_(false), |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 332 | has_loops_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 333 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 334 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 335 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 336 | dex_file_(dex_file), |
| 337 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 338 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 339 | in_ssa_form_(false), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 340 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 341 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 342 | cached_null_constant_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 343 | cached_int_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 344 | cached_float_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 345 | cached_long_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 346 | cached_double_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 347 | cached_current_method_(nullptr), |
Nicolas Geoffray | 53fec08 | 2017-03-27 12:56:16 +0100 | [diff] [blame] | 348 | art_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 349 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 350 | osr_(osr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 351 | cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 352 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 353 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 354 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 355 | // 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] | 356 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 357 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 358 | ArenaAllocator* GetAllocator() const { return allocator_; } |
| 359 | ArenaStack* GetArenaStack() const { return arena_stack_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 360 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 361 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 362 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 363 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 364 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 365 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 366 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 367 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 368 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 369 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 370 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 371 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 372 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 373 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 374 | void ComputeDominanceInformation(); |
| 375 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 376 | void ClearLoopInformation(); |
| 377 | void FindBackEdges(ArenaBitVector* visited); |
| 378 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 379 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 380 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 381 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 382 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 383 | // 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] | 384 | // 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] | 385 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 386 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 387 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 388 | // order and loop information. |
| 389 | void ComputeTryBlockInformation(); |
| 390 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 391 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 392 | // Returns the instruction to replace the invoke expression or null if the |
| 393 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 394 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 395 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 396 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 397 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 398 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 399 | // should be the new back edge. |
| 400 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 401 | HBasicBlock* reference, |
| 402 | bool replace_if_back_edge); |
| 403 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 404 | // Need to add a couple of blocks to test if the loop body is entered and |
| 405 | // put deoptimization instructions, etc. |
| 406 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 407 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 408 | // Adds a new loop directly after the loop with the given header and exit. |
| 409 | // Returns the new preheader. |
| 410 | HBasicBlock* TransformLoopForVectorization(HBasicBlock* header, |
| 411 | HBasicBlock* body, |
| 412 | HBasicBlock* exit); |
| 413 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 414 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 415 | // other blocks and has no instructions or phis. |
| 416 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 417 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 418 | // Splits the edge between `block` and `successor` while preserving the |
| 419 | // indices in the predecessor/successor lists. If there are multiple edges |
| 420 | // between the blocks, the lowest indices are used. |
| 421 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 422 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 423 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 424 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
Artem Serov | c73ee37 | 2017-07-31 15:08:40 +0100 | [diff] [blame] | 425 | void OrderLoopHeaderPredecessors(HBasicBlock* header); |
Artem Serov | 09faaea | 2017-12-07 14:36:01 +0000 | [diff] [blame] | 426 | |
| 427 | // Transform a loop into a format with a single preheader. |
| 428 | // |
| 429 | // Each phi in the header should be split: original one in the header should only hold |
| 430 | // inputs reachable from the back edges and a single input from the preheader. The newly created |
| 431 | // phi in the preheader should collate the inputs from the original multiple incoming blocks. |
| 432 | // |
| 433 | // Loops in the graph typically have a single preheader, so this method is used to "repair" loops |
| 434 | // that no longer have this property. |
| 435 | void TransformLoopToSinglePreheaderFormat(HBasicBlock* header); |
| 436 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 437 | void SimplifyLoop(HBasicBlock* header); |
| 438 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 439 | int32_t GetNextInstructionId() { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 440 | CHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 441 | return current_instruction_id_++; |
| 442 | } |
| 443 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 444 | int32_t GetCurrentInstructionId() const { |
| 445 | return current_instruction_id_; |
| 446 | } |
| 447 | |
| 448 | void SetCurrentInstructionId(int32_t id) { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 449 | CHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 450 | current_instruction_id_ = id; |
| 451 | } |
| 452 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 453 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 454 | return maximum_number_of_out_vregs_; |
| 455 | } |
| 456 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 457 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 458 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 459 | } |
| 460 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 461 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 462 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 463 | } |
| 464 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 465 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 466 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 467 | } |
| 468 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 469 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 470 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 471 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 472 | } |
| 473 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 474 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 475 | number_of_vregs_ = number_of_vregs; |
| 476 | } |
| 477 | |
| 478 | uint16_t GetNumberOfVRegs() const { |
| 479 | return number_of_vregs_; |
| 480 | } |
| 481 | |
| 482 | void SetNumberOfInVRegs(uint16_t value) { |
| 483 | number_of_in_vregs_ = value; |
| 484 | } |
| 485 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 486 | uint16_t GetNumberOfInVRegs() const { |
| 487 | return number_of_in_vregs_; |
| 488 | } |
| 489 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 490 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 491 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 492 | return number_of_vregs_ - number_of_in_vregs_; |
| 493 | } |
| 494 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 495 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 496 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 497 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 498 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 499 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 500 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 501 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 502 | } |
| 503 | |
| 504 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 505 | return ReverseRange(GetReversePostOrder()); |
| 506 | } |
| 507 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 508 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 509 | return linear_order_; |
| 510 | } |
| 511 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 512 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 513 | return ReverseRange(GetLinearOrder()); |
| 514 | } |
| 515 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 516 | bool HasBoundsChecks() const { |
| 517 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 518 | } |
| 519 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 520 | void SetHasBoundsChecks(bool value) { |
| 521 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 522 | } |
| 523 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 524 | bool IsDebuggable() const { return debuggable_; } |
| 525 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 526 | // 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] | 527 | // already, it is created and inserted into the graph. This method is only for |
| 528 | // integral types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 529 | 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] | 530 | |
| 531 | // TODO: This is problematic for the consistency of reference type propagation |
| 532 | // because it can be created anytime after the pass and thus it will be left |
| 533 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 534 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 535 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 536 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 537 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 538 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 539 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 540 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 541 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 542 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 543 | 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] | 544 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 545 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 546 | 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] | 547 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 548 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 549 | HCurrentMethod* GetCurrentMethod(); |
| 550 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 551 | const DexFile& GetDexFile() const { |
| 552 | return dex_file_; |
| 553 | } |
| 554 | |
| 555 | uint32_t GetMethodIdx() const { |
| 556 | return method_idx_; |
| 557 | } |
| 558 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 559 | // Get the method name (without the signature), e.g. "<init>" |
| 560 | const char* GetMethodName() const; |
| 561 | |
| 562 | // Get the pretty method name (class + name + optionally signature). |
| 563 | std::string PrettyMethod(bool with_signature = true) const; |
| 564 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 565 | InvokeType GetInvokeType() const { |
| 566 | return invoke_type_; |
| 567 | } |
| 568 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 569 | InstructionSet GetInstructionSet() const { |
| 570 | return instruction_set_; |
| 571 | } |
| 572 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 573 | bool IsCompilingOsr() const { return osr_; } |
| 574 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 575 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 576 | return cha_single_implementation_list_; |
| 577 | } |
| 578 | |
| 579 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 580 | cha_single_implementation_list_.insert(method); |
| 581 | } |
| 582 | |
| 583 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 584 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 585 | } |
| 586 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 587 | bool HasTryCatch() const { return has_try_catch_; } |
| 588 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 589 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 590 | bool HasSIMD() const { return has_simd_; } |
| 591 | void SetHasSIMD(bool value) { has_simd_ = value; } |
| 592 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 593 | bool HasLoops() const { return has_loops_; } |
| 594 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 595 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 596 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 597 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 598 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 599 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 600 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 601 | |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 602 | // Returns an instruction with the opposite Boolean value from 'cond'. |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 603 | // The instruction has been inserted into the graph, either as a constant, or |
| 604 | // before cursor. |
| 605 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 606 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 607 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 608 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 609 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 610 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 611 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 612 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 613 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 614 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 615 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 616 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 617 | template <class InstructionType, typename ValueType> |
| 618 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 619 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 620 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 621 | // Try to find an existing constant of the given value. |
| 622 | InstructionType* constant = nullptr; |
| 623 | auto cached_constant = cache->find(value); |
| 624 | if (cached_constant != cache->end()) { |
| 625 | constant = cached_constant->second; |
| 626 | } |
| 627 | |
| 628 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 629 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 630 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 631 | constant = new (allocator_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 632 | cache->Overwrite(value, constant); |
| 633 | InsertConstant(constant); |
| 634 | } |
| 635 | return constant; |
| 636 | } |
| 637 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 638 | void InsertConstant(HConstant* instruction); |
| 639 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 640 | // Cache a float constant into the graph. This method should only be |
| 641 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 642 | void CacheFloatConstant(HFloatConstant* constant); |
| 643 | |
| 644 | // See CacheFloatConstant comment. |
| 645 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 646 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 647 | ArenaAllocator* const allocator_; |
| 648 | ArenaStack* const arena_stack_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 649 | |
| 650 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 651 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 652 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 653 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 654 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 655 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 656 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 657 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 658 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 659 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 660 | HBasicBlock* entry_block_; |
| 661 | HBasicBlock* exit_block_; |
| 662 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 663 | // 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] | 664 | uint16_t maximum_number_of_out_vregs_; |
| 665 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 666 | // The number of virtual registers in this method. Contains the parameters. |
| 667 | uint16_t number_of_vregs_; |
| 668 | |
| 669 | // The number of virtual registers used by parameters of this method. |
| 670 | uint16_t number_of_in_vregs_; |
| 671 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 672 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 673 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 674 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 675 | // Flag whether there are bounds checks in the graph. We can skip |
| 676 | // BCE if it's false. It's only best effort to keep it up to date in |
| 677 | // the presence of code elimination so there might be false positives. |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 678 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 679 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 680 | // Flag whether there are try/catch blocks in the graph. We will skip |
| 681 | // try/catch-related passes if it's false. It's only best effort to keep |
| 682 | // it up to date in the presence of code elimination so there might be |
| 683 | // false positives. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 684 | bool has_try_catch_; |
| 685 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 686 | // Flag whether SIMD instructions appear in the graph. If true, the |
| 687 | // code generators may have to be more careful spilling the wider |
| 688 | // contents of SIMD registers. |
| 689 | bool has_simd_; |
| 690 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 691 | // Flag whether there are any loops in the graph. We can skip loop |
| 692 | // optimization if it's false. It's only best effort to keep it up |
| 693 | // to date in the presence of code elimination so there might be false |
| 694 | // positives. |
| 695 | bool has_loops_; |
| 696 | |
| 697 | // Flag whether there are any irreducible loops in the graph. It's only |
| 698 | // best effort to keep it up to date in the presence of code elimination |
| 699 | // so there might be false positives. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 700 | bool has_irreducible_loops_; |
| 701 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 702 | // Indicates whether the graph should be compiled in a way that |
| 703 | // ensures full debuggability. If false, we can apply more |
| 704 | // aggressive optimizations that may limit the level of debugging. |
| 705 | const bool debuggable_; |
| 706 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 707 | // 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] | 708 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 709 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 710 | // The dex file from which the method is from. |
| 711 | const DexFile& dex_file_; |
| 712 | |
| 713 | // The method index in the dex file. |
| 714 | const uint32_t method_idx_; |
| 715 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 716 | // If inlined, this encodes how the callee is being invoked. |
| 717 | const InvokeType invoke_type_; |
| 718 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 719 | // Whether the graph has been transformed to SSA form. Only used |
| 720 | // in debug mode to ensure we are not using properties only valid |
| 721 | // for non-SSA form (like the number of temporaries). |
| 722 | bool in_ssa_form_; |
| 723 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 724 | // Number of CHA guards in the graph. Used to short-circuit the |
| 725 | // CHA guard optimization pass when there is no CHA guard left. |
| 726 | uint32_t number_of_cha_guards_; |
| 727 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 728 | const InstructionSet instruction_set_; |
| 729 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 730 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 731 | HNullConstant* cached_null_constant_; |
| 732 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 733 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 734 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 735 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 736 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 737 | HCurrentMethod* cached_current_method_; |
| 738 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 739 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 740 | // for example for methods whose declaring class could not be resolved |
| 741 | // (such as when the superclass could not be found). |
| 742 | ArtMethod* art_method_; |
| 743 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 744 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 745 | // collection pointer to passes which may create NullConstant. |
| 746 | ReferenceTypeInfo inexact_object_rti_; |
| 747 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 748 | // Whether we are compiling this graph for on stack replacement: this will |
| 749 | // make all loops seen as irreducible and emit special stack maps to mark |
| 750 | // compiled code entries which the interpreter can directly jump to. |
| 751 | const bool osr_; |
| 752 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 753 | // List of methods that are assumed to have single implementation. |
| 754 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 755 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 756 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 757 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 758 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 759 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 760 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 761 | }; |
| 762 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 763 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 764 | public: |
| 765 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 766 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 767 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 768 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 769 | contains_irreducible_loop_(false), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 770 | back_edges_(graph->GetAllocator()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 771 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 772 | blocks_(graph->GetAllocator(), |
| 773 | graph->GetBlocks().size(), |
| 774 | true, |
| 775 | kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 776 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 777 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 778 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 779 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 780 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 781 | |
| 782 | void Dump(std::ostream& os); |
| 783 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 784 | HBasicBlock* GetHeader() const { |
| 785 | return header_; |
| 786 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 787 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 788 | void SetHeader(HBasicBlock* block) { |
| 789 | header_ = block; |
| 790 | } |
| 791 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 792 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 793 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 794 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 795 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 796 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 797 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 800 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 801 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 802 | } |
| 803 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 804 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 805 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 806 | } |
| 807 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 808 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 809 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 812 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 813 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 814 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 815 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 816 | } |
| 817 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 818 | // Returns the lifetime position of the back edge that has the |
| 819 | // greatest lifetime position. |
| 820 | size_t GetLifetimeEnd() const; |
| 821 | |
| 822 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 823 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 824 | } |
| 825 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 826 | // Finds blocks that are part of this loop. |
| 827 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 828 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 829 | // Updates blocks population of the loop and all of its outer' ones recursively after the |
| 830 | // population of the inner loop is updated. |
| 831 | void PopulateInnerLoopUpwards(HLoopInformation* inner_loop); |
| 832 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 833 | // Returns whether this loop information contains `block`. |
| 834 | // Note that this loop information *must* be populated before entering this function. |
| 835 | bool Contains(const HBasicBlock& block) const; |
| 836 | |
| 837 | // Returns whether this loop information is an inner loop of `other`. |
| 838 | // Note that `other` *must* be populated before entering this function. |
| 839 | bool IsIn(const HLoopInformation& other) const; |
| 840 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 841 | // Returns true if instruction is not defined within this loop. |
| 842 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 843 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 844 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 845 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 846 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 847 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 848 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 849 | void ClearAllBlocks() { |
| 850 | blocks_.ClearAllBits(); |
| 851 | } |
| 852 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 853 | bool HasBackEdgeNotDominatedByHeader() const; |
| 854 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 855 | bool IsPopulated() const { |
| 856 | return blocks_.GetHighestBitSet() != -1; |
| 857 | } |
| 858 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 859 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 860 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 861 | bool HasExitEdge() const; |
| 862 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 863 | // Resets back edge and blocks-in-loop data. |
| 864 | void ResetBasicBlockData() { |
| 865 | back_edges_.clear(); |
| 866 | ClearAllBlocks(); |
| 867 | } |
| 868 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 869 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 870 | // Internal recursive implementation of `Populate`. |
| 871 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 872 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 873 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 874 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 875 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 876 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 877 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 878 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 879 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 880 | |
| 881 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 882 | }; |
| 883 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 884 | // Stores try/catch information for basic blocks. |
| 885 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 886 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 887 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 888 | public: |
| 889 | // Try block information constructor. |
| 890 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 891 | : try_entry_(&try_entry), |
| 892 | catch_dex_file_(nullptr), |
| 893 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 894 | DCHECK(try_entry_ != nullptr); |
| 895 | } |
| 896 | |
| 897 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 898 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 899 | : try_entry_(nullptr), |
| 900 | catch_dex_file_(&dex_file), |
| 901 | catch_type_index_(catch_type_index) {} |
| 902 | |
| 903 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 904 | |
| 905 | const HTryBoundary& GetTryEntry() const { |
| 906 | DCHECK(IsTryBlock()); |
| 907 | return *try_entry_; |
| 908 | } |
| 909 | |
| 910 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 911 | |
| 912 | bool IsCatchAllTypeIndex() const { |
| 913 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 914 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 915 | } |
| 916 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 917 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 918 | DCHECK(IsCatchBlock()); |
| 919 | return catch_type_index_; |
| 920 | } |
| 921 | |
| 922 | const DexFile& GetCatchDexFile() const { |
| 923 | DCHECK(IsCatchBlock()); |
| 924 | return *catch_dex_file_; |
| 925 | } |
| 926 | |
| 927 | private: |
| 928 | // One of possibly several TryBoundary instructions entering the block's try. |
| 929 | // Only set for try blocks. |
| 930 | const HTryBoundary* try_entry_; |
| 931 | |
| 932 | // Exception type information. Only set for catch blocks. |
| 933 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 934 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 935 | }; |
| 936 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 937 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 938 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 939 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 940 | // A block in a method. Contains the list of instructions represented |
| 941 | // as a double linked list. Each block knows its predecessors and |
| 942 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 943 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 944 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 945 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 946 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 947 | : graph_(graph), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 948 | predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), |
| 949 | successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 950 | loop_information_(nullptr), |
| 951 | dominator_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 952 | dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 953 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 954 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 955 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 956 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 957 | try_catch_information_(nullptr) { |
| 958 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 959 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 960 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 961 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 962 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 963 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 964 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 967 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 968 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 969 | } |
| 970 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 971 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 972 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 973 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 974 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 975 | return ContainsElement(successors_, block, start_from); |
| 976 | } |
| 977 | |
| 978 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 979 | return dominated_blocks_; |
| 980 | } |
| 981 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 982 | bool IsEntryBlock() const { |
| 983 | return graph_->GetEntryBlock() == this; |
| 984 | } |
| 985 | |
| 986 | bool IsExitBlock() const { |
| 987 | return graph_->GetExitBlock() == this; |
| 988 | } |
| 989 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 990 | bool IsSingleGoto() const; |
Mads Ager | 16e5289 | 2017-07-14 13:11:37 +0200 | [diff] [blame] | 991 | bool IsSingleReturn() const; |
Mingyao Yang | 46721ef | 2017-10-05 14:45:17 -0700 | [diff] [blame] | 992 | bool IsSingleReturnOrReturnVoidAllowingPhis() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 993 | bool IsSingleTryBoundary() const; |
| 994 | |
| 995 | // Returns true if this block emits nothing but a jump. |
| 996 | bool IsSingleJump() const { |
| 997 | HLoopInformation* loop_info = GetLoopInformation(); |
| 998 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 999 | // Back edges generate a suspend check. |
| 1000 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 1001 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1002 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1003 | void AddBackEdge(HBasicBlock* back_edge) { |
| 1004 | if (loop_information_ == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1005 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1006 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1007 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1008 | loop_information_->AddBackEdge(back_edge); |
| 1009 | } |
| 1010 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 1011 | // Registers a back edge; if the block was not a loop header before the call associates a newly |
| 1012 | // created loop info with it. |
| 1013 | // |
| 1014 | // Used in SuperblockCloner to preserve LoopInformation object instead of reseting loop |
| 1015 | // info for all blocks during back edges recalculation. |
| 1016 | void AddBackEdgeWhileUpdating(HBasicBlock* back_edge) { |
| 1017 | if (loop_information_ == nullptr || loop_information_->GetHeader() != this) { |
| 1018 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
| 1019 | } |
| 1020 | loop_information_->AddBackEdge(back_edge); |
| 1021 | } |
| 1022 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1023 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1024 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1025 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1026 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1027 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1028 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1029 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1030 | HBasicBlock* GetDominator() const { return dominator_; } |
| 1031 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1032 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 1033 | |
| 1034 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 1035 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 1036 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1037 | |
| 1038 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1039 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 1040 | } |
| 1041 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1042 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1043 | |
| 1044 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1045 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1048 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1049 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1050 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1051 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1052 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1053 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1054 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1055 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1056 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1057 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1058 | successors_.push_back(block); |
| 1059 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1062 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1063 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1064 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1065 | new_block->predecessors_.push_back(this); |
| 1066 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1069 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1070 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1071 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1072 | new_block->successors_.push_back(this); |
| 1073 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1076 | // Insert `this` between `predecessor` and `successor. This method |
| 1077 | // preserves the indicies, and will update the first edge found between |
| 1078 | // `predecessor` and `successor`. |
| 1079 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1080 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1081 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1082 | successor->predecessors_[predecessor_index] = this; |
| 1083 | predecessor->successors_[successor_index] = this; |
| 1084 | successors_.push_back(successor); |
| 1085 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1088 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1089 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1090 | } |
| 1091 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1092 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1093 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1096 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1097 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1101 | predecessors_.push_back(block); |
| 1102 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1103 | } |
| 1104 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1105 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1106 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1107 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1108 | } |
| 1109 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1110 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1111 | DCHECK_EQ(successors_.size(), 2u); |
| 1112 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1115 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1116 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1117 | } |
| 1118 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1119 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1120 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1123 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1124 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1125 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1129 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1130 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1134 | // predecessors is at index `idx`. |
| 1135 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1136 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1137 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1138 | } |
| 1139 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1140 | // Create a new block between this block and its predecessors. The new block |
| 1141 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1142 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1143 | // loop and try/catch information are not updated. |
| 1144 | HBasicBlock* CreateImmediateDominator(); |
| 1145 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1146 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1147 | // created, latter block. Note that this method will add the block to the |
| 1148 | // graph, create a Goto at the end of the former block and will create an edge |
| 1149 | // 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] | 1150 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1151 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1152 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1153 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1154 | // created block. Note that this method just updates raw block information, |
| 1155 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1156 | // update the graph, reverse post order, loop information, nor make sure the |
| 1157 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1158 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1159 | |
| 1160 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1161 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1162 | |
| 1163 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1164 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1165 | // that this method does not update the graph, reverse post order, loop |
| 1166 | // information, nor make sure the blocks are consistent (for example ending |
| 1167 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1168 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1169 | |
| 1170 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1171 | // of `this` are moved to `other`. |
| 1172 | // Note that this method does not update the graph, reverse post order, loop |
| 1173 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1174 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1175 | void ReplaceWith(HBasicBlock* other); |
| 1176 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1177 | // Merges the instructions of `other` at the end of `this`. |
| 1178 | void MergeInstructionsWith(HBasicBlock* other); |
| 1179 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1180 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1181 | // order, links to predecessors, successors, dominators and deletes the block |
| 1182 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1183 | // predecessor of `other` and vice versa. |
| 1184 | void MergeWith(HBasicBlock* other); |
| 1185 | |
| 1186 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1187 | // removes it from all loops it is included in and eventually from the graph. |
| 1188 | // The block must not dominate any other block. Predecessors and successors |
| 1189 | // are safely updated. |
| 1190 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1191 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1192 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1193 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1194 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1195 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1196 | // Replace phi `initial` with `replacement` within this block. |
| 1197 | void ReplaceAndRemovePhiWith(HPhi* initial, HPhi* replacement); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1198 | // Replace instruction `initial` with `replacement` within this block. |
| 1199 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1200 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1201 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1202 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1203 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1204 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1205 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1206 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1207 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1208 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1209 | |
| 1210 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1211 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1212 | } |
| 1213 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1214 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1215 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1216 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1217 | } |
| 1218 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1219 | bool IsFirstPredecessorBackEdge() const { |
| 1220 | DCHECK(IsLoopHeader()); |
| 1221 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1222 | } |
| 1223 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1224 | HLoopInformation* GetLoopInformation() const { |
| 1225 | return loop_information_; |
| 1226 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1227 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1228 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1229 | // 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] | 1230 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1231 | void SetInLoop(HLoopInformation* info) { |
| 1232 | if (IsLoopHeader()) { |
| 1233 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1234 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1235 | loop_information_ = info; |
| 1236 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1237 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1238 | // Note that a non loop header having a loop information means this loop information |
| 1239 | // has already been populated |
| 1240 | loop_information_ = info; |
| 1241 | } else { |
| 1242 | // Block is part of an inner loop. Do not update the loop information. |
| 1243 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1244 | // at this point, because this method is being called while populating `info`. |
| 1245 | } |
| 1246 | } |
| 1247 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1248 | // Raw update of the loop information. |
| 1249 | void SetLoopInformation(HLoopInformation* info) { |
| 1250 | loop_information_ = info; |
| 1251 | } |
| 1252 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1253 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1254 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1255 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1256 | |
| 1257 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1258 | try_catch_information_ = try_catch_information; |
| 1259 | } |
| 1260 | |
| 1261 | bool IsTryBlock() const { |
| 1262 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1263 | } |
| 1264 | |
| 1265 | bool IsCatchBlock() const { |
| 1266 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1267 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1268 | |
| 1269 | // Returns the try entry that this block's successors should have. They will |
| 1270 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1271 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1272 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1273 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1274 | bool HasThrowingInstructions() const; |
| 1275 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1276 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1277 | bool Dominates(HBasicBlock* block) const; |
| 1278 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1279 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1280 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1281 | |
| 1282 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1283 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1284 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1285 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1286 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1287 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1288 | bool HasSinglePhi() const; |
| 1289 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1290 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1291 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1292 | ArenaVector<HBasicBlock*> predecessors_; |
| 1293 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1294 | HInstructionList instructions_; |
| 1295 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1296 | HLoopInformation* loop_information_; |
| 1297 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1298 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1299 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1300 | // The dex program counter of the first instruction of this block. |
| 1301 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1302 | size_t lifetime_start_; |
| 1303 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1304 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1305 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1306 | friend class HGraph; |
| 1307 | friend class HInstruction; |
| 1308 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1309 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1310 | }; |
| 1311 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1312 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1313 | // from the innermost to the outermost. |
| 1314 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1315 | public: |
| 1316 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1317 | : current_(block.GetLoopInformation()) {} |
| 1318 | |
| 1319 | bool Done() const { return current_ == nullptr; } |
| 1320 | |
| 1321 | void Advance() { |
| 1322 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1323 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | HLoopInformation* Current() const { |
| 1327 | DCHECK(!Done()); |
| 1328 | return current_; |
| 1329 | } |
| 1330 | |
| 1331 | private: |
| 1332 | HLoopInformation* current_; |
| 1333 | |
| 1334 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1335 | }; |
| 1336 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1337 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1338 | M(Above, Condition) \ |
| 1339 | M(AboveOrEqual, Condition) \ |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame^] | 1340 | M(Abs, UnaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1341 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1342 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1343 | M(ArrayGet, Instruction) \ |
| 1344 | M(ArrayLength, Instruction) \ |
| 1345 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1346 | M(Below, Condition) \ |
| 1347 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1348 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1349 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1350 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1351 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1352 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1353 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1354 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1355 | M(Compare, BinaryOperation) \ |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1356 | M(ConstructorFence, Instruction) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1357 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1358 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1359 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1360 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1361 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1362 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1363 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1364 | M(Exit, Instruction) \ |
| 1365 | M(FloatConstant, Constant) \ |
| 1366 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1367 | M(GreaterThan, Condition) \ |
| 1368 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1369 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1370 | M(InstanceFieldGet, Instruction) \ |
| 1371 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1372 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1373 | M(IntConstant, Constant) \ |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 1374 | M(IntermediateAddress, Instruction) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1375 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1376 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1377 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1378 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1379 | M(InvokePolymorphic, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1380 | M(LessThan, Condition) \ |
| 1381 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1382 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1383 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1384 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1385 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1386 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1387 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1388 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1389 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1390 | M(Neg, UnaryOperation) \ |
| 1391 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1392 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1393 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1394 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1395 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1396 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1397 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1398 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1399 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1400 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1401 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1402 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1403 | M(Return, Instruction) \ |
| 1404 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1405 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1406 | M(Shl, BinaryOperation) \ |
| 1407 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1408 | M(StaticFieldGet, Instruction) \ |
| 1409 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1410 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1411 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1412 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1413 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1414 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1415 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1416 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1417 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1418 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1419 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1420 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1421 | M(Xor, BinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1422 | M(VecReplicateScalar, VecUnaryOperation) \ |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1423 | M(VecExtractScalar, VecUnaryOperation) \ |
| 1424 | M(VecReduce, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1425 | M(VecCnv, VecUnaryOperation) \ |
| 1426 | M(VecNeg, VecUnaryOperation) \ |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1427 | M(VecAbs, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1428 | M(VecNot, VecUnaryOperation) \ |
| 1429 | M(VecAdd, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1430 | M(VecHalvingAdd, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1431 | M(VecSub, VecBinaryOperation) \ |
| 1432 | M(VecMul, VecBinaryOperation) \ |
| 1433 | M(VecDiv, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1434 | M(VecMin, VecBinaryOperation) \ |
| 1435 | M(VecMax, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1436 | M(VecAnd, VecBinaryOperation) \ |
| 1437 | M(VecAndNot, VecBinaryOperation) \ |
| 1438 | M(VecOr, VecBinaryOperation) \ |
| 1439 | M(VecXor, VecBinaryOperation) \ |
| 1440 | M(VecShl, VecBinaryOperation) \ |
| 1441 | M(VecShr, VecBinaryOperation) \ |
| 1442 | M(VecUShr, VecBinaryOperation) \ |
Aart Bik | 8de5916 | 2017-04-21 09:42:01 -0700 | [diff] [blame] | 1443 | M(VecSetScalars, VecOperation) \ |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1444 | M(VecMultiplyAccumulate, VecOperation) \ |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1445 | M(VecSADAccumulate, VecOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1446 | M(VecLoad, VecMemoryOperation) \ |
| 1447 | M(VecStore, VecMemoryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1448 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1449 | /* |
| 1450 | * Instructions, shared across several (not all) architectures. |
| 1451 | */ |
| 1452 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1453 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1454 | #else |
| 1455 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1456 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1457 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1458 | M(MultiplyAccumulate, Instruction) \ |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 1459 | M(IntermediateAddressIndex, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1460 | #endif |
| 1461 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1462 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1463 | |
| 1464 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1465 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1466 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1467 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1468 | #else |
| 1469 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1470 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 1471 | M(MipsPackedSwitch, Instruction) \ |
| 1472 | M(IntermediateArrayAddressIndex, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1473 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1474 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1475 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1476 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1477 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1478 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1479 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1480 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1481 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1482 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1483 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1484 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1485 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1486 | |
| 1487 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1488 | |
| 1489 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1490 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1491 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1492 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1493 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1494 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1495 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1496 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1497 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1498 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1499 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1500 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1501 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1502 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1503 | M(BinaryOperation, Instruction) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1504 | M(Invoke, Instruction) \ |
| 1505 | M(VecOperation, Instruction) \ |
| 1506 | M(VecUnaryOperation, VecOperation) \ |
| 1507 | M(VecBinaryOperation, VecOperation) \ |
| 1508 | M(VecMemoryOperation, VecOperation) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1509 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1510 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1511 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1512 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1513 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1514 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1515 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1516 | #undef FORWARD_DECLARATION |
| 1517 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1518 | #define DECLARE_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1519 | private: \ |
| 1520 | H##type& operator=(const H##type&) = delete; \ |
| 1521 | public: \ |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1522 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1523 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1524 | return other->Is##type(); \ |
| 1525 | } \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1526 | HInstruction* Clone(ArenaAllocator* arena) const OVERRIDE { \ |
| 1527 | DCHECK(IsClonable()); \ |
| 1528 | return new (arena) H##type(*this->As##type()); \ |
| 1529 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1530 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1531 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1532 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1533 | private: \ |
| 1534 | H##type& operator=(const H##type&) = delete; \ |
| 1535 | public: \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1536 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1537 | const H##type* As##type() const { return this; } \ |
| 1538 | H##type* As##type() { return this; } |
| 1539 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1540 | #define DEFAULT_COPY_CONSTRUCTOR(type) \ |
| 1541 | explicit H##type(const H##type& other) = default; |
| 1542 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1543 | template <typename T> |
Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 1544 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode>, |
| 1545 | public IntrusiveForwardListNode<HUseListNode<T>> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1546 | public: |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1547 | // Get the instruction which has this use as one of the inputs. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1548 | T GetUser() const { return user_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1549 | // Get the position of the input record that this use corresponds to. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1550 | size_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1551 | // Set the position of the input record that this use corresponds to. |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1552 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1553 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1554 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1555 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1556 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1557 | |
| 1558 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1559 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1560 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1561 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1562 | |
| 1563 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1564 | }; |
| 1565 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1566 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1567 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1568 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1569 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1570 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1571 | // by the used instructions. |
| 1572 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1573 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1574 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1575 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1576 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1577 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1578 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1579 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1580 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1581 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1582 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1586 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1587 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1588 | |
| 1589 | private: |
| 1590 | // Instruction used by the user. |
| 1591 | HInstruction* instruction_; |
| 1592 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1593 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1594 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1595 | }; |
| 1596 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1597 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1598 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1599 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1600 | struct HInputExtractor { |
| 1601 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1602 | return record.GetInstruction(); |
| 1603 | } |
| 1604 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1605 | return record.GetInstruction(); |
| 1606 | } |
| 1607 | }; |
| 1608 | |
| 1609 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1610 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1611 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1612 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1613 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1614 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1615 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1616 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1617 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1618 | * modify the value of a reference field read [although it may modify the |
| 1619 | * reference fetch prior to reading the field, which is represented by its own |
| 1620 | * write/read dependence]). The analysis makes conservative points-to |
| 1621 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1622 | * the same, and any reference read depends on any reference read without |
| 1623 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1624 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1625 | * The internal representation uses 38-bit and is described in the table below. |
| 1626 | * The first line indicates the side effect, and for field/array accesses the |
| 1627 | * 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] | 1628 | * DataType::Type enum). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1629 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1630 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1631 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1632 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1633 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1634 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1635 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1636 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1637 | * |
| 1638 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1639 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1640 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1641 | class SideEffects : public ValueObject { |
| 1642 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1643 | SideEffects() : flags_(0) {} |
| 1644 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1645 | static SideEffects None() { |
| 1646 | return SideEffects(0); |
| 1647 | } |
| 1648 | |
| 1649 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1650 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1651 | } |
| 1652 | |
| 1653 | static SideEffects AllChanges() { |
| 1654 | return SideEffects(kAllChangeBits); |
| 1655 | } |
| 1656 | |
| 1657 | static SideEffects AllDependencies() { |
| 1658 | return SideEffects(kAllDependOnBits); |
| 1659 | } |
| 1660 | |
| 1661 | static SideEffects AllExceptGCDependency() { |
| 1662 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1663 | } |
| 1664 | |
| 1665 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1666 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1667 | } |
| 1668 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1669 | static SideEffects AllWrites() { |
| 1670 | return SideEffects(kAllWrites); |
| 1671 | } |
| 1672 | |
| 1673 | static SideEffects AllReads() { |
| 1674 | return SideEffects(kAllReads); |
| 1675 | } |
| 1676 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1677 | static SideEffects FieldWriteOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1678 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1679 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1680 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1681 | } |
| 1682 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1683 | static SideEffects ArrayWriteOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1684 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1685 | } |
| 1686 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1687 | static SideEffects FieldReadOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1688 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1689 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1690 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1693 | static SideEffects ArrayReadOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1694 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1697 | static SideEffects CanTriggerGC() { |
| 1698 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1699 | } |
| 1700 | |
| 1701 | static SideEffects DependsOnGC() { |
| 1702 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1703 | } |
| 1704 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1705 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1706 | SideEffects Union(SideEffects other) const { |
| 1707 | return SideEffects(flags_ | other.flags_); |
| 1708 | } |
| 1709 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1710 | SideEffects Exclusion(SideEffects other) const { |
| 1711 | return SideEffects(flags_ & ~other.flags_); |
| 1712 | } |
| 1713 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1714 | void Add(SideEffects other) { |
| 1715 | flags_ |= other.flags_; |
| 1716 | } |
| 1717 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1718 | bool Includes(SideEffects other) const { |
| 1719 | return (other.flags_ & flags_) == other.flags_; |
| 1720 | } |
| 1721 | |
| 1722 | bool HasSideEffects() const { |
| 1723 | return (flags_ & kAllChangeBits); |
| 1724 | } |
| 1725 | |
| 1726 | bool HasDependencies() const { |
| 1727 | return (flags_ & kAllDependOnBits); |
| 1728 | } |
| 1729 | |
| 1730 | // Returns true if there are no side effects or dependencies. |
| 1731 | bool DoesNothing() const { |
| 1732 | return flags_ == 0; |
| 1733 | } |
| 1734 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1735 | // Returns true if something is written. |
| 1736 | bool DoesAnyWrite() const { |
| 1737 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1738 | } |
| 1739 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1740 | // Returns true if something is read. |
| 1741 | bool DoesAnyRead() const { |
| 1742 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1743 | } |
| 1744 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1745 | // Returns true if potentially everything is written and read |
| 1746 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1747 | bool DoesAllReadWrite() const { |
| 1748 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1749 | } |
| 1750 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1751 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1752 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1755 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1756 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1757 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1758 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1762 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1763 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1764 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1765 | for (int s = kLastBit; s >= 0; s--) { |
| 1766 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1767 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1768 | // This is a bit for the GC side effect. |
| 1769 | if (current_bit_is_set) { |
| 1770 | flags += "GC"; |
| 1771 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1772 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1773 | } else { |
| 1774 | // This is a bit for the array/field analysis. |
| 1775 | // The underscore character stands for the 'can trigger GC' bit. |
| 1776 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1777 | if (current_bit_is_set) { |
| 1778 | flags += kDebug[s]; |
| 1779 | } |
| 1780 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1781 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1782 | flags += "|"; |
| 1783 | } |
| 1784 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1785 | } |
| 1786 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1787 | } |
| 1788 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1789 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1790 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1791 | private: |
| 1792 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1793 | |
| 1794 | static constexpr int kFieldWriteOffset = 0; |
| 1795 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1796 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1797 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1798 | |
| 1799 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1800 | |
| 1801 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1802 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1803 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1804 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1805 | |
| 1806 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1807 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1808 | |
| 1809 | // Aliases. |
| 1810 | |
| 1811 | static_assert(kChangeBits == kDependOnBits, |
| 1812 | "the 'change' bits should match the 'depend on' bits."); |
| 1813 | |
| 1814 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1815 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1816 | static constexpr uint64_t kAllWrites = |
| 1817 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1818 | static constexpr uint64_t kAllReads = |
| 1819 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1820 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1821 | // 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] | 1822 | static uint64_t TypeFlag(DataType::Type type, int offset) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1823 | int shift; |
| 1824 | switch (type) { |
| 1825 | case DataType::Type::kReference: shift = 0; break; |
| 1826 | case DataType::Type::kBool: shift = 1; break; |
| 1827 | case DataType::Type::kInt8: shift = 2; break; |
| 1828 | case DataType::Type::kUint16: shift = 3; break; |
| 1829 | case DataType::Type::kInt16: shift = 4; break; |
| 1830 | case DataType::Type::kInt32: shift = 5; break; |
| 1831 | case DataType::Type::kInt64: shift = 6; break; |
| 1832 | case DataType::Type::kFloat32: shift = 7; break; |
| 1833 | case DataType::Type::kFloat64: shift = 8; break; |
| 1834 | default: |
| 1835 | LOG(FATAL) << "Unexpected data type " << type; |
| 1836 | UNREACHABLE(); |
| 1837 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1838 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1839 | DCHECK_LT(shift, kArrayWriteOffset); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1840 | return UINT64_C(1) << (shift + offset); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | // Private constructor on direct flags value. |
| 1844 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1845 | |
| 1846 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1847 | }; |
| 1848 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1849 | // 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] | 1850 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1851 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1852 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1853 | size_t number_of_vregs, |
| 1854 | ArtMethod* method, |
| 1855 | uint32_t dex_pc, |
| 1856 | HInstruction* holder) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1857 | : vregs_(number_of_vregs, allocator->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1858 | locations_(allocator->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1859 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1860 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1861 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1862 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1863 | } |
| 1864 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1865 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
| 1866 | const HEnvironment& to_copy, |
| 1867 | HInstruction* holder) |
| 1868 | : HEnvironment(allocator, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1869 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1870 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1871 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1872 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1873 | |
Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 1874 | void AllocateLocations() { |
| 1875 | DCHECK(locations_.empty()); |
| 1876 | locations_.resize(vregs_.size()); |
| 1877 | } |
| 1878 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1879 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1880 | if (parent_ != nullptr) { |
| 1881 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1882 | } else { |
| 1883 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1884 | parent_->CopyFrom(parent); |
| 1885 | if (parent->GetParent() != nullptr) { |
| 1886 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1887 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1888 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 1891 | void CopyFrom(ArrayRef<HInstruction* const> locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1892 | void CopyFrom(HEnvironment* environment); |
| 1893 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1894 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1895 | // input to the loop phi instead. This is for inserting instructions that |
| 1896 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1897 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1898 | |
| 1899 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1900 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1904 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1907 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1908 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1909 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1910 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1911 | HEnvironment* GetParent() const { return parent_; } |
| 1912 | |
| 1913 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1914 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1918 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | uint32_t GetDexPc() const { |
| 1922 | return dex_pc_; |
| 1923 | } |
| 1924 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1925 | ArtMethod* GetMethod() const { |
| 1926 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1927 | } |
| 1928 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1929 | HInstruction* GetHolder() const { |
| 1930 | return holder_; |
| 1931 | } |
| 1932 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1933 | |
| 1934 | bool IsFromInlinedInvoke() const { |
| 1935 | return GetParent() != nullptr; |
| 1936 | } |
| 1937 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1938 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1939 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1940 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1941 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1942 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1943 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1944 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1945 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1946 | HInstruction* const holder_; |
| 1947 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1948 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1949 | |
| 1950 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1951 | }; |
| 1952 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1953 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1954 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 1955 | #define DECLARE_KIND(type, super) k##type, |
| 1956 | enum InstructionKind { |
| 1957 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1958 | kLastInstructionKind |
| 1959 | }; |
| 1960 | #undef DECLARE_KIND |
| 1961 | |
| 1962 | HInstruction(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1963 | : previous_(nullptr), |
| 1964 | next_(nullptr), |
| 1965 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1966 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1967 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1968 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1969 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1970 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1971 | locations_(nullptr), |
| 1972 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1973 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1974 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1975 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 1976 | SetPackedField<InstructionKindField>(kind); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1977 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1978 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1979 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1980 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1981 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1982 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1983 | HInstruction* GetNext() const { return next_; } |
| 1984 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1985 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1986 | HInstruction* GetNextDisregardingMoves() const; |
| 1987 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1988 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1989 | HBasicBlock* GetBlock() const { return block_; } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1990 | ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1991 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1992 | bool IsInBlock() const { return block_ != nullptr; } |
| 1993 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1994 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1995 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1996 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1997 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1998 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1999 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 2000 | |
| 2001 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 2002 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 2003 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 2004 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 2005 | } |
| 2006 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2007 | HInputsRef GetInputs() { |
| 2008 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2009 | } |
| 2010 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2011 | HConstInputsRef GetInputs() const { |
| 2012 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2016 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2017 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 2018 | bool HasInput(HInstruction* input) const { |
| 2019 | for (const HInstruction* i : GetInputs()) { |
| 2020 | if (i == input) { |
| 2021 | return true; |
| 2022 | } |
| 2023 | } |
| 2024 | return false; |
| 2025 | } |
| 2026 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2027 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 2028 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 2029 | } |
| 2030 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2031 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 2032 | virtual const char* DebugName() const = 0; |
| 2033 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2034 | virtual DataType::Type GetType() const { return DataType::Type::kVoid; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2035 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2036 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2037 | |
| 2038 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2039 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2040 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2041 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2042 | // Can the instruction throw? |
| 2043 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 2044 | // 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] | 2045 | virtual bool CanThrow() const { return false; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2046 | |
| 2047 | // Does the instruction always throw an exception unconditionally? |
| 2048 | virtual bool AlwaysThrows() const { return false; } |
| 2049 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2050 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2051 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2052 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2053 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2054 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2055 | // Does not apply for all instructions, but having this at top level greatly |
| 2056 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 2057 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2058 | virtual bool CanBeNull() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2059 | DCHECK_EQ(GetType(), DataType::Type::kReference) << "CanBeNull only applies to reference types"; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2060 | return true; |
| 2061 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2062 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2063 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 2064 | return false; |
| 2065 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2066 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2067 | virtual bool IsActualObject() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2068 | return GetType() == DataType::Type::kReference; |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 2071 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2072 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2073 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2074 | DCHECK_EQ(GetType(), DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2075 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 2076 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2077 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2078 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2079 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2080 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2081 | // Note: fixup_end remains valid across push_front(). |
| 2082 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 2083 | HUseListNode<HInstruction*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2084 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HInstruction*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2085 | uses_.push_front(*new_node); |
| 2086 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2089 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2090 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2091 | // Note: env_fixup_end remains valid across push_front(). |
| 2092 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2093 | HUseListNode<HEnvironment*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2094 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HEnvironment*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2095 | env_uses_.push_front(*new_node); |
| 2096 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2097 | } |
| 2098 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2099 | void RemoveAsUserOfInput(size_t input) { |
| 2100 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2101 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2102 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2103 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2104 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2105 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2106 | void RemoveAsUserOfAllInputs() { |
| 2107 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2108 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2109 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2110 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2111 | } |
| 2112 | } |
| 2113 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2114 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2115 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2116 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2117 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2118 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2119 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2120 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2121 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2122 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2123 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2124 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2125 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2126 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2127 | !CanThrow() && |
| 2128 | !IsSuspendCheck() && |
| 2129 | !IsControlFlow() && |
| 2130 | !IsNativeDebugInfo() && |
| 2131 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2132 | // If we added an explicit barrier then we should keep it. |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2133 | !IsMemoryBarrier() && |
| 2134 | !IsConstructorFence(); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2137 | bool IsDeadAndRemovable() const { |
| 2138 | return IsRemovable() && !HasUses(); |
| 2139 | } |
| 2140 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2141 | // Does this instruction strictly dominate `other_instruction`? |
| 2142 | // Returns false if this instruction and `other_instruction` are the same. |
| 2143 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2144 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2145 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2146 | int GetId() const { return id_; } |
| 2147 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2148 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2149 | int GetSsaIndex() const { return ssa_index_; } |
| 2150 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2151 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2152 | |
| 2153 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2154 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2155 | // Set the `environment_` field. Raw because this method does not |
| 2156 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2157 | void SetRawEnvironment(HEnvironment* environment) { |
| 2158 | DCHECK(environment_ == nullptr); |
| 2159 | DCHECK_EQ(environment->GetHolder(), this); |
| 2160 | environment_ = environment; |
| 2161 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2162 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2163 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2164 | DCHECK(environment_ != nullptr); |
| 2165 | DCHECK_EQ(environment->GetHolder(), this); |
| 2166 | DCHECK(environment->GetParent() == nullptr); |
| 2167 | environment->parent_ = environment_; |
| 2168 | environment_ = environment; |
| 2169 | } |
| 2170 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2171 | void RemoveEnvironment(); |
| 2172 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2173 | // Set the environment of this instruction, copying it from `environment`. While |
| 2174 | // copying, the uses lists are being updated. |
| 2175 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2176 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2177 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2178 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2179 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2180 | if (environment->GetParent() != nullptr) { |
| 2181 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2182 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2183 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2184 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2185 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2186 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2187 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2188 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2189 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2190 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2191 | if (environment->GetParent() != nullptr) { |
| 2192 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2193 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2196 | // Returns the number of entries in the environment. Typically, that is the |
| 2197 | // number of dex registers in a method. It could be more in case of inlining. |
| 2198 | size_t EnvironmentSize() const; |
| 2199 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2200 | LocationSummary* GetLocations() const { return locations_; } |
| 2201 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2202 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2203 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2204 | void ReplaceUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2205 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2206 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2207 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2208 | // uses of this instruction by `other` are *not* updated. |
| 2209 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2210 | ReplaceWith(other); |
| 2211 | other->ReplaceInput(this, use_index); |
| 2212 | } |
| 2213 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2214 | // Move `this` instruction before `cursor` |
| 2215 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2216 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2217 | // Move `this` before its first user and out of any loops. If there is no |
| 2218 | // out-of-loop user that dominates all other users, move the instruction |
| 2219 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2220 | // |
| 2221 | // This can be used only on non-throwing instructions with no side effects that |
| 2222 | // have at least one use but no environment uses. |
| 2223 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2224 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2225 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2226 | bool Is##type() const; \ |
| 2227 | const H##type* As##type() const; \ |
| 2228 | H##type* As##type(); |
| 2229 | |
| 2230 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2231 | #undef INSTRUCTION_TYPE_CHECK |
| 2232 | |
| 2233 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2234 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2235 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2236 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2237 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2238 | #undef INSTRUCTION_TYPE_CHECK |
| 2239 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2240 | // Return a clone of the instruction if it is clonable (shallow copy by default, custom copy |
| 2241 | // if a custom copy-constructor is provided for a particular type). If IsClonable() is false for |
| 2242 | // the instruction then the behaviour of this function is undefined. |
| 2243 | // |
| 2244 | // Note: It is semantically valid to create a clone of the instruction only until |
| 2245 | // prepare_for_register_allocator phase as lifetime, intervals and codegen info are not |
| 2246 | // copied. |
| 2247 | // |
| 2248 | // Note: HEnvironment and some other fields are not copied and are set to default values, see |
| 2249 | // 'explicit HInstruction(const HInstruction& other)' for details. |
| 2250 | virtual HInstruction* Clone(ArenaAllocator* arena ATTRIBUTE_UNUSED) const { |
| 2251 | LOG(FATAL) << "Cloning is not implemented for the instruction " << |
| 2252 | DebugName() << " " << GetId(); |
| 2253 | UNREACHABLE(); |
| 2254 | } |
| 2255 | |
| 2256 | // Return whether instruction can be cloned (copied). |
| 2257 | virtual bool IsClonable() const { return false; } |
| 2258 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2259 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2260 | // TODO: this method is used by LICM and GVN with possibly different |
| 2261 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2262 | virtual bool CanBeMoved() const { return false; } |
| 2263 | |
| 2264 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2265 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2266 | return false; |
| 2267 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2268 | |
| 2269 | // Returns whether any data encoded in the two instructions is equal. |
| 2270 | // This method does not look at the inputs. Both instructions must be |
| 2271 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2272 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2273 | return false; |
| 2274 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2275 | |
| 2276 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2277 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2278 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2279 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2280 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2281 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2282 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2283 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2284 | // apply the strong requirement for virtual functions, preventing optimizations. |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2285 | InstructionKind GetKind() const { return GetPackedField<InstructionKindField>(); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2286 | |
| 2287 | virtual size_t ComputeHashCode() const { |
| 2288 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2289 | for (const HInstruction* input : GetInputs()) { |
| 2290 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2291 | } |
| 2292 | return result; |
| 2293 | } |
| 2294 | |
| 2295 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2296 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2297 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2298 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2299 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2300 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2301 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2302 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2303 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2304 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2305 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2306 | |
| 2307 | // Returns whether the code generation of the instruction will require to have access |
| 2308 | // to the current method. Such instructions are: |
| 2309 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2310 | // 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] | 2311 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2312 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2313 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2314 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2315 | } |
| 2316 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2317 | // Returns whether the code generation of the instruction will require to have access |
| 2318 | // to the dex cache of the current method's declaring class via the current method. |
| 2319 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2320 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2321 | // Does this instruction have any use in an environment before |
| 2322 | // control flow hits 'other'? |
| 2323 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2324 | |
| 2325 | // Remove all references to environment uses of this instruction. |
| 2326 | // The caller must ensure that this is safe to do. |
| 2327 | void RemoveEnvironmentUsers(); |
| 2328 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2329 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2330 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2331 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2332 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2333 | // If set, the machine code for this instruction is assumed to be generated by |
| 2334 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2335 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2336 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2337 | static constexpr size_t kFieldInstructionKind = kFlagReferenceTypeIsExact + 1; |
| 2338 | static constexpr size_t kFieldInstructionKindSize = |
| 2339 | MinimumBitsToStore(static_cast<size_t>(InstructionKind::kLastInstructionKind - 1)); |
| 2340 | static constexpr size_t kNumberOfGenericPackedBits = |
| 2341 | kFieldInstructionKind + kFieldInstructionKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2342 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2343 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2344 | static_assert(kNumberOfGenericPackedBits <= kMaxNumberOfPackedBits, |
| 2345 | "Too many generic packed fields"); |
| 2346 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2347 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2348 | return GetInputRecords()[i]; |
| 2349 | } |
| 2350 | |
| 2351 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2352 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2353 | input_records[index] = input; |
| 2354 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2355 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2356 | uint32_t GetPackedFields() const { |
| 2357 | return packed_fields_; |
| 2358 | } |
| 2359 | |
| 2360 | template <size_t flag> |
| 2361 | bool GetPackedFlag() const { |
| 2362 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2363 | } |
| 2364 | |
| 2365 | template <size_t flag> |
| 2366 | void SetPackedFlag(bool value = true) { |
| 2367 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2368 | } |
| 2369 | |
| 2370 | template <typename BitFieldType> |
| 2371 | typename BitFieldType::value_type GetPackedField() const { |
| 2372 | return BitFieldType::Decode(packed_fields_); |
| 2373 | } |
| 2374 | |
| 2375 | template <typename BitFieldType> |
| 2376 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2377 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2378 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2379 | } |
| 2380 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2381 | // Copy construction for the instruction (used for Clone function). |
| 2382 | // |
| 2383 | // Fields (e.g. lifetime, intervals and codegen info) associated with phases starting from |
| 2384 | // prepare_for_register_allocator are not copied (set to default values). |
| 2385 | // |
| 2386 | // Copy constructors must be provided for every HInstruction type; default copy constructor is |
| 2387 | // fine for most of them. However for some of the instructions a custom copy constructor must be |
| 2388 | // specified (when instruction has non-trivially copyable fields and must have a special behaviour |
| 2389 | // for copying them). |
| 2390 | explicit HInstruction(const HInstruction& other) |
| 2391 | : previous_(nullptr), |
| 2392 | next_(nullptr), |
| 2393 | block_(nullptr), |
| 2394 | dex_pc_(other.dex_pc_), |
| 2395 | id_(-1), |
| 2396 | ssa_index_(-1), |
| 2397 | packed_fields_(other.packed_fields_), |
| 2398 | environment_(nullptr), |
| 2399 | locations_(nullptr), |
| 2400 | live_interval_(nullptr), |
| 2401 | lifetime_position_(kNoLifetime), |
| 2402 | side_effects_(other.side_effects_), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2403 | reference_type_handle_(other.reference_type_handle_) { |
| 2404 | } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2405 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2406 | private: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2407 | using InstructionKindField = |
| 2408 | BitField<InstructionKind, kFieldInstructionKind, kFieldInstructionKindSize>; |
| 2409 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2410 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2411 | auto before_use_node = uses_.before_begin(); |
| 2412 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2413 | HInstruction* user = use_node->GetUser(); |
| 2414 | size_t input_index = use_node->GetIndex(); |
| 2415 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2416 | before_use_node = use_node; |
| 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2421 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2422 | if (next != uses_.end()) { |
| 2423 | HInstruction* next_user = next->GetUser(); |
| 2424 | size_t next_index = next->GetIndex(); |
| 2425 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2426 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2431 | auto before_env_use_node = env_uses_.before_begin(); |
| 2432 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2433 | HEnvironment* user = env_use_node->GetUser(); |
| 2434 | size_t input_index = env_use_node->GetIndex(); |
| 2435 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2436 | before_env_use_node = env_use_node; |
| 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2441 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2442 | if (next != env_uses_.end()) { |
| 2443 | HEnvironment* next_user = next->GetUser(); |
| 2444 | size_t next_index = next->GetIndex(); |
| 2445 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2446 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2447 | } |
| 2448 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2449 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2450 | HInstruction* previous_; |
| 2451 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2452 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2453 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2454 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2455 | // An instruction gets an id when it is added to the graph. |
| 2456 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2457 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2458 | int id_; |
| 2459 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2460 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2461 | int ssa_index_; |
| 2462 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2463 | // Packed fields. |
| 2464 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2465 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2466 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2467 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2468 | |
| 2469 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2470 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2471 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2472 | // The environment associated with this instruction. Not null if the instruction |
| 2473 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2474 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2475 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2476 | // Set by the code generator. |
| 2477 | LocationSummary* locations_; |
| 2478 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2479 | // Set by the liveness analysis. |
| 2480 | LiveInterval* live_interval_; |
| 2481 | |
| 2482 | // Set by the liveness analysis, this is the position in a linear |
| 2483 | // order of blocks where this instruction's live interval start. |
| 2484 | size_t lifetime_position_; |
| 2485 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2486 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2487 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2488 | // The reference handle part of the reference type info. |
| 2489 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2490 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2491 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2492 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2493 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2494 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2495 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2496 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2497 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2498 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2499 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2500 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2501 | // Iterates over the instructions, while preserving the next instruction |
| 2502 | // in case the current instruction gets removed from the list by the user |
| 2503 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2504 | class HInstructionIterator : public ValueObject { |
| 2505 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2506 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2507 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2508 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2509 | } |
| 2510 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2511 | bool Done() const { return instruction_ == nullptr; } |
| 2512 | HInstruction* Current() const { return instruction_; } |
| 2513 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2514 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2515 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | private: |
| 2519 | HInstruction* instruction_; |
| 2520 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2521 | |
| 2522 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2523 | }; |
| 2524 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2525 | // Iterates over the instructions without saving the next instruction, |
| 2526 | // therefore handling changes in the graph potentially made by the user |
| 2527 | // of this iterator. |
| 2528 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2529 | public: |
| 2530 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2531 | : instruction_(instructions.first_instruction_) { |
| 2532 | } |
| 2533 | |
| 2534 | bool Done() const { return instruction_ == nullptr; } |
| 2535 | HInstruction* Current() const { return instruction_; } |
| 2536 | void Advance() { |
| 2537 | instruction_ = instruction_->GetNext(); |
| 2538 | } |
| 2539 | |
| 2540 | private: |
| 2541 | HInstruction* instruction_; |
| 2542 | |
| 2543 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2544 | }; |
| 2545 | |
| 2546 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2547 | class HBackwardInstructionIterator : public ValueObject { |
| 2548 | public: |
| 2549 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2550 | : instruction_(instructions.last_instruction_) { |
| 2551 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2552 | } |
| 2553 | |
| 2554 | bool Done() const { return instruction_ == nullptr; } |
| 2555 | HInstruction* Current() const { return instruction_; } |
| 2556 | void Advance() { |
| 2557 | instruction_ = next_; |
| 2558 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2559 | } |
| 2560 | |
| 2561 | private: |
| 2562 | HInstruction* instruction_; |
| 2563 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2564 | |
| 2565 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2566 | }; |
| 2567 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2568 | class HVariableInputSizeInstruction : public HInstruction { |
| 2569 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2570 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2571 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 2572 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2573 | } |
| 2574 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2575 | void AddInput(HInstruction* input); |
| 2576 | void InsertInputAt(size_t index, HInstruction* input); |
| 2577 | void RemoveInputAt(size_t index); |
| 2578 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2579 | // Removes all the inputs. |
| 2580 | // Also removes this instructions from each input's use list |
| 2581 | // (for non-environment uses only). |
| 2582 | void RemoveAllInputs(); |
| 2583 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2584 | protected: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2585 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2586 | SideEffects side_effects, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2587 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2588 | ArenaAllocator* allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2589 | size_t number_of_inputs, |
| 2590 | ArenaAllocKind kind) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2591 | : HInstruction(inst_kind, side_effects, dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2592 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2593 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2594 | DEFAULT_COPY_CONSTRUCTOR(VariableInputSizeInstruction); |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2595 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2596 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2597 | }; |
| 2598 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2599 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2600 | class HTemplateInstruction: public HInstruction { |
| 2601 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2602 | HTemplateInstruction<N>(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
| 2603 | : HInstruction(kind, side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2604 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2605 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2606 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2607 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2608 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2609 | } |
| 2610 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2611 | protected: |
| 2612 | DEFAULT_COPY_CONSTRUCTOR(TemplateInstruction<N>); |
| 2613 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2614 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2615 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2616 | |
| 2617 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2618 | }; |
| 2619 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2620 | // HTemplateInstruction specialization for N=0. |
| 2621 | template<> |
| 2622 | class HTemplateInstruction<0>: public HInstruction { |
| 2623 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2624 | explicit HTemplateInstruction<0>(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
| 2625 | : HInstruction(kind, side_effects, dex_pc) {} |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2626 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2627 | virtual ~HTemplateInstruction() {} |
| 2628 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2629 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2630 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2631 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2632 | } |
| 2633 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2634 | protected: |
| 2635 | DEFAULT_COPY_CONSTRUCTOR(TemplateInstruction<0>); |
| 2636 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2637 | private: |
| 2638 | friend class SsaBuilder; |
| 2639 | }; |
| 2640 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2641 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2642 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2643 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2644 | using HInstruction::InstructionKind; |
| 2645 | HExpression<N>(InstructionKind kind, |
| 2646 | DataType::Type type, |
| 2647 | SideEffects side_effects, |
| 2648 | uint32_t dex_pc) |
| 2649 | : HTemplateInstruction<N>(kind, side_effects, dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2650 | this->template SetPackedField<TypeField>(type); |
| 2651 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2652 | virtual ~HExpression() {} |
| 2653 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2654 | DataType::Type GetType() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2655 | return TypeField::Decode(this->GetPackedFields()); |
| 2656 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2657 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2658 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2659 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2660 | static constexpr size_t kFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2661 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2662 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2663 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2664 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2665 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2666 | DEFAULT_COPY_CONSTRUCTOR(Expression<N>); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2667 | }; |
| 2668 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2669 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2670 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2671 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2672 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2673 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2674 | : HTemplateInstruction(kReturnVoid, SideEffects::None(), dex_pc) { |
| 2675 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2676 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2677 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2678 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2679 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2680 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2681 | protected: |
| 2682 | DEFAULT_COPY_CONSTRUCTOR(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2683 | }; |
| 2684 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2685 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2686 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2687 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2688 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2689 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2690 | : HTemplateInstruction(kReturn, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2691 | SetRawInputAt(0, value); |
| 2692 | } |
| 2693 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2694 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2695 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2696 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2697 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2698 | protected: |
| 2699 | DEFAULT_COPY_CONSTRUCTOR(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2700 | }; |
| 2701 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2702 | class HPhi FINAL : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2703 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2704 | HPhi(ArenaAllocator* allocator, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2705 | uint32_t reg_number, |
| 2706 | size_t number_of_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2707 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2708 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2709 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2710 | kPhi, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2711 | SideEffects::None(), |
| 2712 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2713 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2714 | number_of_inputs, |
| 2715 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2716 | reg_number_(reg_number) { |
| 2717 | SetPackedField<TypeField>(ToPhiType(type)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2718 | DCHECK_NE(GetType(), DataType::Type::kVoid); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2719 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2720 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2721 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2722 | SetPackedFlag<kFlagIsLive>(true); |
| 2723 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2724 | } |
| 2725 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2726 | bool IsClonable() const OVERRIDE { return true; } |
| 2727 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2728 | // 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] | 2729 | static DataType::Type ToPhiType(DataType::Type type) { |
| 2730 | return DataType::Kind(type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2734 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2735 | DataType::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2736 | void SetType(DataType::Type new_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2737 | // Make sure that only valid type changes occur. The following are allowed: |
| 2738 | // (1) int -> float/ref (primitive type propagation), |
| 2739 | // (2) long -> double (primitive type propagation). |
| 2740 | DCHECK(GetType() == new_type || |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2741 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kFloat32) || |
| 2742 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kReference) || |
| 2743 | (GetType() == DataType::Type::kInt64 && new_type == DataType::Type::kFloat64)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2744 | SetPackedField<TypeField>(new_type); |
| 2745 | } |
| 2746 | |
| 2747 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2748 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2749 | |
| 2750 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2751 | |
| 2752 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2753 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2754 | bool IsDead() const { return !IsLive(); } |
| 2755 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2756 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2757 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2758 | return other != nullptr |
| 2759 | && other->IsPhi() |
| 2760 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2761 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2762 | } |
| 2763 | |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 2764 | bool HasEquivalentPhi() const { |
| 2765 | if (GetPrevious() != nullptr && GetPrevious()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2766 | return true; |
| 2767 | } |
| 2768 | if (GetNext() != nullptr && GetNext()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2769 | return true; |
| 2770 | } |
| 2771 | return false; |
| 2772 | } |
| 2773 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2774 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2775 | // An equivalent phi is a phi having the same dex register and type. |
| 2776 | // It assumes that phis with the same dex register are adjacent. |
| 2777 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2778 | HInstruction* next = GetNext(); |
| 2779 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2780 | if (next->GetType() == GetType()) { |
| 2781 | return next->AsPhi(); |
| 2782 | } |
| 2783 | next = next->GetNext(); |
| 2784 | } |
| 2785 | return nullptr; |
| 2786 | } |
| 2787 | |
| 2788 | DECLARE_INSTRUCTION(Phi); |
| 2789 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2790 | protected: |
| 2791 | DEFAULT_COPY_CONSTRUCTOR(Phi); |
| 2792 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2793 | private: |
| 2794 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2795 | static constexpr size_t kFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2796 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2797 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2798 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2799 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2800 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2801 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2802 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2803 | const uint32_t reg_number_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2804 | }; |
| 2805 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2806 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2807 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2808 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2809 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2810 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2811 | explicit HExit(uint32_t dex_pc = kNoDexPc) |
| 2812 | : HTemplateInstruction(kExit, SideEffects::None(), dex_pc) { |
| 2813 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2814 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2815 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2816 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2817 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2818 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2819 | protected: |
| 2820 | DEFAULT_COPY_CONSTRUCTOR(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2821 | }; |
| 2822 | |
| 2823 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2824 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2825 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2826 | explicit HGoto(uint32_t dex_pc = kNoDexPc) |
| 2827 | : HTemplateInstruction(kGoto, SideEffects::None(), dex_pc) { |
| 2828 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2829 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2830 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2831 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2832 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2833 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2834 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2835 | } |
| 2836 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2837 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2838 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2839 | protected: |
| 2840 | DEFAULT_COPY_CONSTRUCTOR(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2841 | }; |
| 2842 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2843 | class HConstant : public HExpression<0> { |
| 2844 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2845 | explicit HConstant(InstructionKind kind, DataType::Type type, uint32_t dex_pc = kNoDexPc) |
| 2846 | : HExpression(kind, type, SideEffects::None(), dex_pc) { |
| 2847 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2848 | |
| 2849 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2850 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2851 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2852 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2853 | // Is this constant 0 in the arithmetic sense? |
| 2854 | virtual bool IsArithmeticZero() const { return false; } |
| 2855 | // Is this constant a 0-bit pattern? |
| 2856 | virtual bool IsZeroBitPattern() const { return false; } |
| 2857 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2858 | virtual bool IsOne() const { return false; } |
| 2859 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2860 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2861 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2862 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2863 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2864 | protected: |
| 2865 | DEFAULT_COPY_CONSTRUCTOR(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2866 | }; |
| 2867 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2868 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2869 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2870 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2871 | return true; |
| 2872 | } |
| 2873 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2874 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2875 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2876 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2877 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2878 | // The null constant representation is a 0-bit pattern. |
| 2879 | virtual bool IsZeroBitPattern() const { return true; } |
| 2880 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2881 | DECLARE_INSTRUCTION(NullConstant); |
| 2882 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2883 | protected: |
| 2884 | DEFAULT_COPY_CONSTRUCTOR(NullConstant); |
| 2885 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2886 | private: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2887 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2888 | : HConstant(kNullConstant, DataType::Type::kReference, dex_pc) { |
| 2889 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2890 | |
| 2891 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2892 | }; |
| 2893 | |
| 2894 | // Constants of the type int. Those can be from Dex instructions, or |
| 2895 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2896 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2897 | public: |
| 2898 | int32_t GetValue() const { return value_; } |
| 2899 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2900 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2901 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2902 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2903 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2904 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2905 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2906 | return other->AsIntConstant()->value_ == value_; |
| 2907 | } |
| 2908 | |
| 2909 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2910 | |
| 2911 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2912 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2913 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2914 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2915 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2916 | // Integer constants are used to encode Boolean values as well, |
| 2917 | // where 1 means true and 0 means false. |
| 2918 | bool IsTrue() const { return GetValue() == 1; } |
| 2919 | bool IsFalse() const { return GetValue() == 0; } |
| 2920 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2921 | DECLARE_INSTRUCTION(IntConstant); |
| 2922 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2923 | protected: |
| 2924 | DEFAULT_COPY_CONSTRUCTOR(IntConstant); |
| 2925 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2926 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2927 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2928 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), value_(value) { |
| 2929 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2930 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2931 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), |
| 2932 | value_(value ? 1 : 0) { |
| 2933 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2934 | |
| 2935 | const int32_t value_; |
| 2936 | |
| 2937 | friend class HGraph; |
| 2938 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2939 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2940 | }; |
| 2941 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2942 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2943 | public: |
| 2944 | int64_t GetValue() const { return value_; } |
| 2945 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2946 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2947 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2948 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2949 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2950 | return other->AsLongConstant()->value_ == value_; |
| 2951 | } |
| 2952 | |
| 2953 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2954 | |
| 2955 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2956 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2957 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2958 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2959 | |
| 2960 | DECLARE_INSTRUCTION(LongConstant); |
| 2961 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2962 | protected: |
| 2963 | DEFAULT_COPY_CONSTRUCTOR(LongConstant); |
| 2964 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2965 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2966 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2967 | : HConstant(kLongConstant, DataType::Type::kInt64, dex_pc), |
| 2968 | value_(value) { |
| 2969 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2970 | |
| 2971 | const int64_t value_; |
| 2972 | |
| 2973 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2974 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2975 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2976 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2977 | public: |
| 2978 | float GetValue() const { return value_; } |
| 2979 | |
| 2980 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2981 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2982 | } |
| 2983 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2984 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2985 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2986 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2987 | } |
| 2988 | |
| 2989 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2990 | |
| 2991 | bool IsMinusOne() const OVERRIDE { |
| 2992 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2993 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2994 | bool IsArithmeticZero() const OVERRIDE { |
| 2995 | return std::fpclassify(value_) == FP_ZERO; |
| 2996 | } |
| 2997 | bool IsArithmeticPositiveZero() const { |
| 2998 | return IsArithmeticZero() && !std::signbit(value_); |
| 2999 | } |
| 3000 | bool IsArithmeticNegativeZero() const { |
| 3001 | return IsArithmeticZero() && std::signbit(value_); |
| 3002 | } |
| 3003 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3004 | 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] | 3005 | } |
| 3006 | bool IsOne() const OVERRIDE { |
| 3007 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3008 | } |
| 3009 | bool IsNaN() const { |
| 3010 | return std::isnan(value_); |
| 3011 | } |
| 3012 | |
| 3013 | DECLARE_INSTRUCTION(FloatConstant); |
| 3014 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3015 | protected: |
| 3016 | DEFAULT_COPY_CONSTRUCTOR(FloatConstant); |
| 3017 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3018 | private: |
| 3019 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3020 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3021 | value_(value) { |
| 3022 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3023 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3024 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3025 | value_(bit_cast<float, int32_t>(value)) { |
| 3026 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3027 | |
| 3028 | const float value_; |
| 3029 | |
| 3030 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3031 | friend class SsaBuilder; |
| 3032 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3033 | }; |
| 3034 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3035 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3036 | public: |
| 3037 | double GetValue() const { return value_; } |
| 3038 | |
| 3039 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3040 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3041 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3042 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 3043 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3044 | } |
| 3045 | |
| 3046 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 3047 | |
| 3048 | bool IsMinusOne() const OVERRIDE { |
| 3049 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 3050 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3051 | bool IsArithmeticZero() const OVERRIDE { |
| 3052 | return std::fpclassify(value_) == FP_ZERO; |
| 3053 | } |
| 3054 | bool IsArithmeticPositiveZero() const { |
| 3055 | return IsArithmeticZero() && !std::signbit(value_); |
| 3056 | } |
| 3057 | bool IsArithmeticNegativeZero() const { |
| 3058 | return IsArithmeticZero() && std::signbit(value_); |
| 3059 | } |
| 3060 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3061 | 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] | 3062 | } |
| 3063 | bool IsOne() const OVERRIDE { |
| 3064 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3065 | } |
| 3066 | bool IsNaN() const { |
| 3067 | return std::isnan(value_); |
| 3068 | } |
| 3069 | |
| 3070 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3071 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3072 | protected: |
| 3073 | DEFAULT_COPY_CONSTRUCTOR(DoubleConstant); |
| 3074 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3075 | private: |
| 3076 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3077 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3078 | value_(value) { |
| 3079 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3080 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3081 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3082 | value_(bit_cast<double, int64_t>(value)) { |
| 3083 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3084 | |
| 3085 | const double value_; |
| 3086 | |
| 3087 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3088 | friend class SsaBuilder; |
| 3089 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3090 | }; |
| 3091 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3092 | // Conditional branch. A block ending with an HIf instruction must have |
| 3093 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3094 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3095 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3096 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3097 | : HTemplateInstruction(kIf, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3098 | SetRawInputAt(0, input); |
| 3099 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3100 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3101 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3102 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3103 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3104 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3105 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3109 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3110 | } |
| 3111 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3112 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3113 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3114 | protected: |
| 3115 | DEFAULT_COPY_CONSTRUCTOR(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3116 | }; |
| 3117 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3118 | |
| 3119 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 3120 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 3121 | // non-exceptional control flow. |
| 3122 | // Normal-flow successor is stored at index zero, exception handlers under |
| 3123 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3124 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3125 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3126 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3127 | kEntry, |
| 3128 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3129 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3130 | }; |
| 3131 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3132 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3133 | : HTemplateInstruction(kTryBoundary, SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3134 | SetPackedField<BoundaryKindField>(kind); |
| 3135 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3136 | |
| 3137 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3138 | |
| 3139 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3140 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3141 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 3142 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 3143 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 3144 | } |
| 3145 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3146 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 3147 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3148 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 3149 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 3150 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | // If not present already, adds `handler` to its block's list of exception |
| 3154 | // handlers. |
| 3155 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3156 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3157 | GetBlock()->AddSuccessor(handler); |
| 3158 | } |
| 3159 | } |
| 3160 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3161 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 3162 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3163 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3164 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 3165 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3166 | DECLARE_INSTRUCTION(TryBoundary); |
| 3167 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3168 | protected: |
| 3169 | DEFAULT_COPY_CONSTRUCTOR(TryBoundary); |
| 3170 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3171 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3172 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 3173 | static constexpr size_t kFieldBoundaryKindSize = |
| 3174 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 3175 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 3176 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 3177 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 3178 | "Too many packed fields."); |
| 3179 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3180 | }; |
| 3181 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3182 | // Deoptimize to interpreter, upon checking a condition. |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3183 | class HDeoptimize FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3184 | public: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3185 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 3186 | // across. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3187 | HDeoptimize(ArenaAllocator* allocator, |
| 3188 | HInstruction* cond, |
| 3189 | DeoptimizationKind kind, |
| 3190 | uint32_t dex_pc) |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3191 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3192 | kDeoptimize, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3193 | SideEffects::All(), |
| 3194 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3195 | allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3196 | /* number_of_inputs */ 1, |
| 3197 | kArenaAllocMisc) { |
| 3198 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 3199 | SetPackedField<DeoptimizeKindField>(kind); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3200 | SetRawInputAt(0, cond); |
| 3201 | } |
| 3202 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3203 | bool IsClonable() const OVERRIDE { return true; } |
| 3204 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3205 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3206 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3207 | // instead of `guard`. |
| 3208 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3209 | // at the point of the `HDeoptimize`. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3210 | HDeoptimize(ArenaAllocator* allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3211 | HInstruction* cond, |
| 3212 | HInstruction* guard, |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3213 | DeoptimizationKind kind, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3214 | uint32_t dex_pc) |
| 3215 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3216 | kDeoptimize, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3217 | SideEffects::CanTriggerGC(), |
| 3218 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3219 | allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3220 | /* number_of_inputs */ 2, |
| 3221 | kArenaAllocMisc) { |
| 3222 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3223 | SetPackedField<DeoptimizeKindField>(kind); |
| 3224 | SetRawInputAt(0, cond); |
| 3225 | SetRawInputAt(1, guard); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3226 | } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3227 | |
| 3228 | bool CanBeMoved() const OVERRIDE { return GetPackedFlag<kFieldCanBeMoved>(); } |
| 3229 | |
| 3230 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 3231 | return (other->CanBeMoved() == CanBeMoved()) && (other->AsDeoptimize()->GetKind() == GetKind()); |
| 3232 | } |
| 3233 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3234 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3235 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3236 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3237 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3238 | DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3239 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3240 | DataType::Type GetType() const OVERRIDE { |
| 3241 | return GuardsAnInput() ? GuardedInput()->GetType() : DataType::Type::kVoid; |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | bool GuardsAnInput() const { |
| 3245 | return InputCount() == 2; |
| 3246 | } |
| 3247 | |
| 3248 | HInstruction* GuardedInput() const { |
| 3249 | DCHECK(GuardsAnInput()); |
| 3250 | return InputAt(1); |
| 3251 | } |
| 3252 | |
| 3253 | void RemoveGuard() { |
| 3254 | RemoveInputAt(1); |
| 3255 | } |
| 3256 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3257 | DECLARE_INSTRUCTION(Deoptimize); |
| 3258 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3259 | protected: |
| 3260 | DEFAULT_COPY_CONSTRUCTOR(Deoptimize); |
| 3261 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3262 | private: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3263 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3264 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3265 | static constexpr size_t kFieldDeoptimizeKindSize = |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3266 | MinimumBitsToStore(static_cast<size_t>(DeoptimizationKind::kLast)); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3267 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3268 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3269 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3270 | "Too many packed fields."); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3271 | using DeoptimizeKindField = |
| 3272 | BitField<DeoptimizationKind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3273 | }; |
| 3274 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3275 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3276 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3277 | // if it's true, starts to do deoptimization. |
| 3278 | // It has a 4-byte slot on stack. |
| 3279 | // TODO: allocate a register for this flag. |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3280 | class HShouldDeoptimizeFlag FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3281 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3282 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3283 | // with regard to other passes. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3284 | HShouldDeoptimizeFlag(ArenaAllocator* allocator, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3285 | : HVariableInputSizeInstruction(kShouldDeoptimizeFlag, |
| 3286 | SideEffects::None(), |
| 3287 | dex_pc, |
| 3288 | allocator, |
| 3289 | 0, |
| 3290 | kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3291 | } |
| 3292 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3293 | DataType::Type GetType() const OVERRIDE { return DataType::Type::kInt32; } |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3294 | |
| 3295 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3296 | // further guard elimination/motion since a guard might have been used for justification |
| 3297 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3298 | // to avoid other optimizations trying to move it. |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3299 | bool CanBeMoved() const OVERRIDE { return false; } |
| 3300 | |
| 3301 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3302 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3303 | protected: |
| 3304 | DEFAULT_COPY_CONSTRUCTOR(ShouldDeoptimizeFlag); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3305 | }; |
| 3306 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3307 | // Represents the ArtMethod that was passed as a first argument to |
| 3308 | // the method. It is used by instructions that depend on it, like |
| 3309 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3310 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3311 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3312 | explicit HCurrentMethod(DataType::Type type, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3313 | : HExpression(kCurrentMethod, type, SideEffects::None(), dex_pc) { |
| 3314 | } |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3315 | |
| 3316 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3317 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3318 | protected: |
| 3319 | DEFAULT_COPY_CONSTRUCTOR(CurrentMethod); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3320 | }; |
| 3321 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3322 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3323 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3324 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3325 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3326 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3327 | kVTable, |
| 3328 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3329 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3330 | }; |
| 3331 | HClassTableGet(HInstruction* cls, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3332 | DataType::Type type, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3333 | TableKind kind, |
| 3334 | size_t index, |
| 3335 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3336 | : HExpression(kClassTableGet, type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3337 | index_(index) { |
| 3338 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3339 | SetRawInputAt(0, cls); |
| 3340 | } |
| 3341 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3342 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3343 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3344 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3345 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3346 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3347 | } |
| 3348 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3349 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3350 | size_t GetIndex() const { return index_; } |
| 3351 | |
| 3352 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3353 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3354 | protected: |
| 3355 | DEFAULT_COPY_CONSTRUCTOR(ClassTableGet); |
| 3356 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3357 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3358 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 3359 | static constexpr size_t kFieldTableKindSize = |
| 3360 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3361 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3362 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3363 | "Too many packed fields."); |
| 3364 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3365 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3366 | // The index of the ArtMethod in the table. |
| 3367 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3368 | }; |
| 3369 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3370 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3371 | // have one successor for each entry in the switch table, and the final successor |
| 3372 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3373 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3374 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3375 | HPackedSwitch(int32_t start_value, |
| 3376 | uint32_t num_entries, |
| 3377 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3378 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3379 | : HTemplateInstruction(kPackedSwitch, SideEffects::None(), dex_pc), |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3380 | start_value_(start_value), |
| 3381 | num_entries_(num_entries) { |
| 3382 | SetRawInputAt(0, input); |
| 3383 | } |
| 3384 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3385 | bool IsClonable() const OVERRIDE { return true; } |
| 3386 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3387 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3388 | |
| 3389 | int32_t GetStartValue() const { return start_value_; } |
| 3390 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3391 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3392 | |
| 3393 | HBasicBlock* GetDefaultBlock() const { |
| 3394 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3395 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3396 | } |
| 3397 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3398 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3399 | protected: |
| 3400 | DEFAULT_COPY_CONSTRUCTOR(PackedSwitch); |
| 3401 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3402 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3403 | const int32_t start_value_; |
| 3404 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3405 | }; |
| 3406 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3407 | class HUnaryOperation : public HExpression<1> { |
| 3408 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3409 | HUnaryOperation(InstructionKind kind, |
| 3410 | DataType::Type result_type, |
| 3411 | HInstruction* input, |
| 3412 | uint32_t dex_pc = kNoDexPc) |
| 3413 | : HExpression(kind, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3414 | SetRawInputAt(0, input); |
| 3415 | } |
| 3416 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3417 | // All of the UnaryOperation instructions are clonable. |
| 3418 | bool IsClonable() const OVERRIDE { return true; } |
| 3419 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3420 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3421 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3422 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3423 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3424 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3425 | return true; |
| 3426 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3427 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3428 | // Try to statically evaluate `this` and return a HConstant |
| 3429 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3430 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3431 | HConstant* TryStaticEvaluation() const; |
| 3432 | |
| 3433 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3434 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3435 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3436 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3437 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3438 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3439 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3440 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3441 | protected: |
| 3442 | DEFAULT_COPY_CONSTRUCTOR(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3443 | }; |
| 3444 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3445 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3446 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3447 | HBinaryOperation(InstructionKind kind, |
| 3448 | DataType::Type result_type, |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3449 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3450 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3451 | SideEffects side_effects = SideEffects::None(), |
| 3452 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3453 | : HExpression(kind, result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3454 | SetRawInputAt(0, left); |
| 3455 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3456 | } |
| 3457 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3458 | // All of the BinaryOperation instructions are clonable. |
| 3459 | bool IsClonable() const OVERRIDE { return true; } |
| 3460 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3461 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3462 | HInstruction* GetRight() const { return InputAt(1); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3463 | DataType::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3464 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3465 | virtual bool IsCommutative() const { return false; } |
| 3466 | |
| 3467 | // Put constant on the right. |
| 3468 | // Returns whether order is changed. |
| 3469 | bool OrderInputsWithConstantOnTheRight() { |
| 3470 | HInstruction* left = InputAt(0); |
| 3471 | HInstruction* right = InputAt(1); |
| 3472 | if (left->IsConstant() && !right->IsConstant()) { |
| 3473 | ReplaceInput(right, 0); |
| 3474 | ReplaceInput(left, 1); |
| 3475 | return true; |
| 3476 | } |
| 3477 | return false; |
| 3478 | } |
| 3479 | |
| 3480 | // Order inputs by instruction id, but favor constant on the right side. |
| 3481 | // This helps GVN for commutative ops. |
| 3482 | void OrderInputs() { |
| 3483 | DCHECK(IsCommutative()); |
| 3484 | HInstruction* left = InputAt(0); |
| 3485 | HInstruction* right = InputAt(1); |
| 3486 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3487 | return; |
| 3488 | } |
| 3489 | if (OrderInputsWithConstantOnTheRight()) { |
| 3490 | return; |
| 3491 | } |
| 3492 | // Order according to instruction id. |
| 3493 | if (left->GetId() > right->GetId()) { |
| 3494 | ReplaceInput(right, 0); |
| 3495 | ReplaceInput(left, 1); |
| 3496 | } |
| 3497 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3498 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3499 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3500 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3501 | return true; |
| 3502 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3503 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3504 | // Try to statically evaluate `this` and return a HConstant |
| 3505 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3506 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3507 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3508 | |
| 3509 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3510 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3511 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3512 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3513 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3514 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3515 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3516 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3517 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3518 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3519 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3520 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3521 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3522 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3523 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3524 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3525 | // 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] | 3526 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3527 | HConstant* GetConstantRight() const; |
| 3528 | |
| 3529 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3530 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3531 | HInstruction* GetLeastConstantLeft() const; |
| 3532 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3533 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3534 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3535 | protected: |
| 3536 | DEFAULT_COPY_CONSTRUCTOR(BinaryOperation); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3537 | }; |
| 3538 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3539 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3540 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3541 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3542 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3543 | kGtBias, // return 1 for NaN comparisons |
| 3544 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3545 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3546 | }; |
| 3547 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3548 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3549 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3550 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3551 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3552 | HCondition(InstructionKind kind, |
| 3553 | HInstruction* first, |
| 3554 | HInstruction* second, |
| 3555 | uint32_t dex_pc = kNoDexPc) |
| 3556 | : HBinaryOperation(kind, |
| 3557 | DataType::Type::kBool, |
| 3558 | first, |
| 3559 | second, |
| 3560 | SideEffects::None(), |
| 3561 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3562 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3563 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3564 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3565 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3566 | // `instruction`, and disregard moves in between. |
| 3567 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3568 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3569 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3570 | |
| 3571 | virtual IfCondition GetCondition() const = 0; |
| 3572 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3573 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3574 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3575 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3576 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3577 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3578 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3579 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3580 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3581 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3582 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3583 | } |
| 3584 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3585 | bool IsFPConditionTrueIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3586 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3587 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3588 | if (if_cond == kCondNE) { |
| 3589 | return true; |
| 3590 | } else if (if_cond == kCondEQ) { |
| 3591 | return false; |
| 3592 | } |
| 3593 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | bool IsFPConditionFalseIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3597 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3598 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3599 | if (if_cond == kCondEQ) { |
| 3600 | return true; |
| 3601 | } else if (if_cond == kCondNE) { |
| 3602 | return false; |
| 3603 | } |
| 3604 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3605 | } |
| 3606 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3607 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3608 | // Needed if we merge a HCompare into a HCondition. |
| 3609 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3610 | static constexpr size_t kFieldComparisonBiasSize = |
| 3611 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3612 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3613 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3614 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3615 | using ComparisonBiasField = |
| 3616 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3617 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3618 | template <typename T> |
| 3619 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3620 | |
| 3621 | template <typename T> |
| 3622 | int32_t CompareFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3623 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3624 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3625 | // Handle the bias. |
| 3626 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3627 | } |
| 3628 | |
| 3629 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3630 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3631 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3632 | } |
| 3633 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3634 | DEFAULT_COPY_CONSTRUCTOR(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3635 | }; |
| 3636 | |
| 3637 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3638 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3639 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3640 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3641 | : HCondition(kEqual, first, second, dex_pc) { |
| 3642 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3643 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3644 | bool IsCommutative() const OVERRIDE { return true; } |
| 3645 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3646 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3647 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3648 | return MakeConstantCondition(true, GetDexPc()); |
| 3649 | } |
| 3650 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3651 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3652 | } |
| 3653 | // In the following Evaluate methods, a HCompare instruction has |
| 3654 | // been merged into this HEqual instruction; evaluate it as |
| 3655 | // `Compare(x, y) == 0`. |
| 3656 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3657 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3658 | GetDexPc()); |
| 3659 | } |
| 3660 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3661 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3662 | } |
| 3663 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3664 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3665 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3666 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3667 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3668 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3669 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3670 | return kCondEQ; |
| 3671 | } |
| 3672 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3673 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3674 | return kCondNE; |
| 3675 | } |
| 3676 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3677 | protected: |
| 3678 | DEFAULT_COPY_CONSTRUCTOR(Equal); |
| 3679 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3680 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3681 | 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] | 3682 | }; |
| 3683 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3684 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3685 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3686 | HNotEqual(HInstruction* first, HInstruction* second, |
| 3687 | uint32_t dex_pc = kNoDexPc) |
| 3688 | : HCondition(kNotEqual, first, second, dex_pc) { |
| 3689 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3690 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3691 | bool IsCommutative() const OVERRIDE { return true; } |
| 3692 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3693 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3694 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3695 | return MakeConstantCondition(false, GetDexPc()); |
| 3696 | } |
| 3697 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3698 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3699 | } |
| 3700 | // In the following Evaluate methods, a HCompare instruction has |
| 3701 | // been merged into this HNotEqual instruction; evaluate it as |
| 3702 | // `Compare(x, y) != 0`. |
| 3703 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3704 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3705 | } |
| 3706 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3707 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3708 | } |
| 3709 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3710 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3711 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3712 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3713 | DECLARE_INSTRUCTION(NotEqual); |
| 3714 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3715 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3716 | return kCondNE; |
| 3717 | } |
| 3718 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3719 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3720 | return kCondEQ; |
| 3721 | } |
| 3722 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3723 | protected: |
| 3724 | DEFAULT_COPY_CONSTRUCTOR(NotEqual); |
| 3725 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3726 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3727 | 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] | 3728 | }; |
| 3729 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3730 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3731 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3732 | HLessThan(HInstruction* first, HInstruction* second, |
| 3733 | uint32_t dex_pc = kNoDexPc) |
| 3734 | : HCondition(kLessThan, first, second, dex_pc) { |
| 3735 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3736 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3737 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3738 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3739 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3740 | // In the following Evaluate methods, a HCompare instruction has |
| 3741 | // been merged into this HLessThan instruction; evaluate it as |
| 3742 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3743 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3744 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3745 | } |
| 3746 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3747 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3748 | } |
| 3749 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3750 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3751 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3752 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3753 | DECLARE_INSTRUCTION(LessThan); |
| 3754 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3755 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3756 | return kCondLT; |
| 3757 | } |
| 3758 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3759 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3760 | return kCondGE; |
| 3761 | } |
| 3762 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3763 | protected: |
| 3764 | DEFAULT_COPY_CONSTRUCTOR(LessThan); |
| 3765 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3766 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3767 | 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] | 3768 | }; |
| 3769 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3770 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3771 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3772 | HLessThanOrEqual(HInstruction* first, HInstruction* second, |
| 3773 | uint32_t dex_pc = kNoDexPc) |
| 3774 | : HCondition(kLessThanOrEqual, first, second, dex_pc) { |
| 3775 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3776 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3777 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3778 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3779 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3780 | // In the following Evaluate methods, a HCompare instruction has |
| 3781 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3782 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3783 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3784 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3785 | } |
| 3786 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3787 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3788 | } |
| 3789 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3790 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3791 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3792 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3793 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3794 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3795 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3796 | return kCondLE; |
| 3797 | } |
| 3798 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3799 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3800 | return kCondGT; |
| 3801 | } |
| 3802 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3803 | protected: |
| 3804 | DEFAULT_COPY_CONSTRUCTOR(LessThanOrEqual); |
| 3805 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3806 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3807 | 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] | 3808 | }; |
| 3809 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3810 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3811 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3812 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3813 | : HCondition(kGreaterThan, first, second, dex_pc) { |
| 3814 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3815 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3816 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3817 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3818 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3819 | // In the following Evaluate methods, a HCompare instruction has |
| 3820 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3821 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3822 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3823 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3824 | } |
| 3825 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3826 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3827 | } |
| 3828 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3829 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3830 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3831 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3832 | DECLARE_INSTRUCTION(GreaterThan); |
| 3833 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3834 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3835 | return kCondGT; |
| 3836 | } |
| 3837 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3838 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3839 | return kCondLE; |
| 3840 | } |
| 3841 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3842 | protected: |
| 3843 | DEFAULT_COPY_CONSTRUCTOR(GreaterThan); |
| 3844 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3845 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3846 | 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] | 3847 | }; |
| 3848 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3849 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3850 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3851 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3852 | : HCondition(kGreaterThanOrEqual, first, second, dex_pc) { |
| 3853 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3854 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3855 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3856 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3857 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3858 | // In the following Evaluate methods, a HCompare instruction has |
| 3859 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3860 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3861 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3862 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3863 | } |
| 3864 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3865 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3866 | } |
| 3867 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3868 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3869 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3870 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3871 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3872 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3873 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3874 | return kCondGE; |
| 3875 | } |
| 3876 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3877 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3878 | return kCondLT; |
| 3879 | } |
| 3880 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3881 | protected: |
| 3882 | DEFAULT_COPY_CONSTRUCTOR(GreaterThanOrEqual); |
| 3883 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3884 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3885 | 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] | 3886 | }; |
| 3887 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3888 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3889 | public: |
| 3890 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3891 | : HCondition(kBelow, first, second, dex_pc) { |
| 3892 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3893 | |
| 3894 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3895 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3896 | } |
| 3897 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3898 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3899 | } |
| 3900 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3901 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3902 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3903 | UNREACHABLE(); |
| 3904 | } |
| 3905 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3906 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3907 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3908 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | DECLARE_INSTRUCTION(Below); |
| 3912 | |
| 3913 | IfCondition GetCondition() const OVERRIDE { |
| 3914 | return kCondB; |
| 3915 | } |
| 3916 | |
| 3917 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3918 | return kCondAE; |
| 3919 | } |
| 3920 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3921 | protected: |
| 3922 | DEFAULT_COPY_CONSTRUCTOR(Below); |
| 3923 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3924 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3925 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3926 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3927 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3928 | }; |
| 3929 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3930 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3931 | public: |
| 3932 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3933 | : HCondition(kBelowOrEqual, first, second, dex_pc) { |
| 3934 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3935 | |
| 3936 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3937 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3938 | } |
| 3939 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3940 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3941 | } |
| 3942 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3943 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3944 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3945 | UNREACHABLE(); |
| 3946 | } |
| 3947 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3948 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3949 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3950 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3954 | |
| 3955 | IfCondition GetCondition() const OVERRIDE { |
| 3956 | return kCondBE; |
| 3957 | } |
| 3958 | |
| 3959 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3960 | return kCondA; |
| 3961 | } |
| 3962 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3963 | protected: |
| 3964 | DEFAULT_COPY_CONSTRUCTOR(BelowOrEqual); |
| 3965 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3966 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3967 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3968 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3969 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3970 | }; |
| 3971 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3972 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3973 | public: |
| 3974 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3975 | : HCondition(kAbove, first, second, dex_pc) { |
| 3976 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3977 | |
| 3978 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3979 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3980 | } |
| 3981 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3982 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3983 | } |
| 3984 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3985 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3986 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3987 | UNREACHABLE(); |
| 3988 | } |
| 3989 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3990 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3991 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3992 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3993 | } |
| 3994 | |
| 3995 | DECLARE_INSTRUCTION(Above); |
| 3996 | |
| 3997 | IfCondition GetCondition() const OVERRIDE { |
| 3998 | return kCondA; |
| 3999 | } |
| 4000 | |
| 4001 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 4002 | return kCondBE; |
| 4003 | } |
| 4004 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4005 | protected: |
| 4006 | DEFAULT_COPY_CONSTRUCTOR(Above); |
| 4007 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4008 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4009 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4010 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 4011 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4012 | }; |
| 4013 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4014 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4015 | public: |
| 4016 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4017 | : HCondition(kAboveOrEqual, first, second, dex_pc) { |
| 4018 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4019 | |
| 4020 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4021 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4022 | } |
| 4023 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4024 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4025 | } |
| 4026 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4027 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4028 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4029 | UNREACHABLE(); |
| 4030 | } |
| 4031 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4032 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4033 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4034 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 4038 | |
| 4039 | IfCondition GetCondition() const OVERRIDE { |
| 4040 | return kCondAE; |
| 4041 | } |
| 4042 | |
| 4043 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 4044 | return kCondB; |
| 4045 | } |
| 4046 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4047 | protected: |
| 4048 | DEFAULT_COPY_CONSTRUCTOR(AboveOrEqual); |
| 4049 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4050 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4051 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4052 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 4053 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4054 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4055 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4056 | // Instruction to check how two inputs compare to each other. |
| 4057 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4058 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4059 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4060 | // Note that `comparison_type` is the type of comparison performed |
| 4061 | // between the comparison's inputs, not the type of the instantiated |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4062 | // HCompare instruction (which is always DataType::Type::kInt). |
| 4063 | HCompare(DataType::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4064 | HInstruction* first, |
| 4065 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4066 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4067 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4068 | : HBinaryOperation(kCompare, |
| 4069 | DataType::Type::kInt32, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4070 | first, |
| 4071 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4072 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4073 | dex_pc) { |
| 4074 | SetPackedField<ComparisonBiasField>(bias); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4075 | DCHECK_EQ(comparison_type, DataType::Kind(first->GetType())); |
| 4076 | DCHECK_EQ(comparison_type, DataType::Kind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4077 | } |
| 4078 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4079 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4080 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 4081 | |
| 4082 | template <typename T> |
| 4083 | int32_t ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4084 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4085 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 4086 | // Handle the bias. |
| 4087 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 4088 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4089 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4090 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4091 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 4092 | // reach this code path when processing a freshly built HIR |
| 4093 | // graph. However HCompare integer instructions can be synthesized |
| 4094 | // by the instruction simplifier to implement IntegerCompare and |
| 4095 | // IntegerSignum intrinsics, so we have to handle this case. |
| 4096 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4097 | } |
| 4098 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4099 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4100 | } |
| 4101 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4102 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4103 | } |
| 4104 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4105 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4106 | } |
| 4107 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4108 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4109 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4110 | } |
| 4111 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4112 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4113 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4114 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4115 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4116 | bool IsGtBias() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4117 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4118 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4119 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4120 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4121 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type type ATTRIBUTE_UNUSED) { |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 4122 | // Comparisons do not require a runtime call in any back end. |
| 4123 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4124 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4125 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4126 | DECLARE_INSTRUCTION(Compare); |
| 4127 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4128 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4129 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 4130 | static constexpr size_t kFieldComparisonBiasSize = |
| 4131 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 4132 | static constexpr size_t kNumberOfComparePackedBits = |
| 4133 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 4134 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4135 | using ComparisonBiasField = |
| 4136 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 4137 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4138 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 4139 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 4140 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 4141 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 4142 | } |
| 4143 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4144 | DEFAULT_COPY_CONSTRUCTOR(Compare); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4145 | }; |
| 4146 | |
Nicolas Geoffray | 2b615ba | 2017-01-06 14:40:07 +0000 | [diff] [blame] | 4147 | class HNewInstance FINAL : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4148 | public: |
| 4149 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4150 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4151 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4152 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4153 | bool finalizable, |
| 4154 | QuickEntrypointEnum entrypoint) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4155 | : HExpression(kNewInstance, |
| 4156 | DataType::Type::kReference, |
| 4157 | SideEffects::CanTriggerGC(), |
| 4158 | dex_pc), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4159 | type_index_(type_index), |
| 4160 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4161 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4162 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4163 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4164 | } |
| 4165 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4166 | bool IsClonable() const OVERRIDE { return true; } |
| 4167 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4168 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4169 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4170 | |
| 4171 | // Calls runtime so needs an environment. |
| 4172 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4173 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4174 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 4175 | bool CanThrow() const OVERRIDE { return true; } |
| 4176 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4177 | bool NeedsChecks() const { |
| 4178 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 4179 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4180 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4181 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4182 | |
| 4183 | bool CanBeNull() const OVERRIDE { return false; } |
| 4184 | |
| 4185 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4186 | |
| 4187 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 4188 | entrypoint_ = entrypoint; |
| 4189 | } |
| 4190 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4191 | HLoadClass* GetLoadClass() const { |
| 4192 | HInstruction* input = InputAt(0); |
| 4193 | if (input->IsClinitCheck()) { |
| 4194 | input = input->InputAt(0); |
| 4195 | } |
| 4196 | DCHECK(input->IsLoadClass()); |
| 4197 | return input->AsLoadClass(); |
| 4198 | } |
| 4199 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4200 | bool IsStringAlloc() const; |
| 4201 | |
| 4202 | DECLARE_INSTRUCTION(NewInstance); |
| 4203 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4204 | protected: |
| 4205 | DEFAULT_COPY_CONSTRUCTOR(NewInstance); |
| 4206 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4207 | private: |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4208 | static constexpr size_t kFlagFinalizable = kNumberOfExpressionPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4209 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 4210 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 4211 | "Too many packed fields."); |
| 4212 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4213 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4214 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4215 | QuickEntrypointEnum entrypoint_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4216 | }; |
| 4217 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 4218 | enum IntrinsicNeedsEnvironmentOrCache { |
| 4219 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 4220 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4221 | }; |
| 4222 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4223 | enum IntrinsicSideEffects { |
| 4224 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 4225 | kReadSideEffects, // Intrinsic may read heap memory. |
| 4226 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 4227 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 4228 | }; |
| 4229 | |
| 4230 | enum IntrinsicExceptions { |
| 4231 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 4232 | kCanThrow // Intrinsic may throw exceptions. |
| 4233 | }; |
| 4234 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4235 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4236 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4237 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4238 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 4239 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4240 | SetRawInputAt(index, argument); |
| 4241 | } |
| 4242 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4243 | // Return the number of arguments. This number can be lower than |
| 4244 | // the number of inputs returned by InputCount(), as some invoke |
| 4245 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 4246 | // inputs at the end of their list of inputs. |
| 4247 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 4248 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4249 | DataType::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4250 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4251 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4252 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4253 | InvokeType GetInvokeType() const { |
| 4254 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4255 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4256 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 4257 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4258 | return intrinsic_; |
| 4259 | } |
| 4260 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4261 | void SetIntrinsic(Intrinsics intrinsic, |
| 4262 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 4263 | IntrinsicSideEffects side_effects, |
| 4264 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4265 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4266 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4267 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4268 | } |
| 4269 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4270 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4271 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4272 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4273 | |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4274 | void SetAlwaysThrows(bool always_throws) { SetPackedFlag<kFlagAlwaysThrows>(always_throws); } |
| 4275 | |
| 4276 | bool AlwaysThrows() const OVERRIDE { return GetPackedFlag<kFlagAlwaysThrows>(); } |
| 4277 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4278 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4279 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4280 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4281 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 4282 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4283 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4284 | uint32_t* GetIntrinsicOptimizations() { |
| 4285 | return &intrinsic_optimizations_; |
| 4286 | } |
| 4287 | |
| 4288 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4289 | return &intrinsic_optimizations_; |
| 4290 | } |
| 4291 | |
| 4292 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4293 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4294 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4295 | void SetResolvedMethod(ArtMethod* method) { resolved_method_ = method; } |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4296 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4297 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4298 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4299 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4300 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4301 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4302 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4303 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4304 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4305 | static constexpr size_t kFieldReturnTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4306 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4307 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4308 | static constexpr size_t kFlagAlwaysThrows = kFlagCanThrow + 1; |
| 4309 | static constexpr size_t kNumberOfInvokePackedBits = kFlagAlwaysThrows + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4310 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4311 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4312 | using ReturnTypeField = BitField<DataType::Type, kFieldReturnType, kFieldReturnTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4313 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4314 | HInvoke(InstructionKind kind, |
| 4315 | ArenaAllocator* allocator, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4316 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4317 | uint32_t number_of_other_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4318 | DataType::Type return_type, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4319 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4320 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4321 | ArtMethod* resolved_method, |
| 4322 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4323 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4324 | kind, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4325 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4326 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4327 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4328 | number_of_arguments + number_of_other_inputs, |
| 4329 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4330 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4331 | resolved_method_(resolved_method), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4332 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4333 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4334 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4335 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4336 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4337 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4338 | } |
| 4339 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4340 | DEFAULT_COPY_CONSTRUCTOR(Invoke); |
| 4341 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4342 | uint32_t number_of_arguments_; |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4343 | ArtMethod* resolved_method_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4344 | const uint32_t dex_method_index_; |
| 4345 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4346 | |
| 4347 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4348 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4349 | }; |
| 4350 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4351 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4352 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4353 | HInvokeUnresolved(ArenaAllocator* allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4354 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4355 | DataType::Type return_type, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4356 | uint32_t dex_pc, |
| 4357 | uint32_t dex_method_index, |
| 4358 | InvokeType invoke_type) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4359 | : HInvoke(kInvokeUnresolved, |
| 4360 | allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4361 | number_of_arguments, |
| 4362 | 0u /* number_of_other_inputs */, |
| 4363 | return_type, |
| 4364 | dex_pc, |
| 4365 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4366 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4367 | invoke_type) { |
| 4368 | } |
| 4369 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4370 | bool IsClonable() const OVERRIDE { return true; } |
| 4371 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4372 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4373 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4374 | protected: |
| 4375 | DEFAULT_COPY_CONSTRUCTOR(InvokeUnresolved); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4376 | }; |
| 4377 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4378 | class HInvokePolymorphic FINAL : public HInvoke { |
| 4379 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4380 | HInvokePolymorphic(ArenaAllocator* allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4381 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4382 | DataType::Type return_type, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4383 | uint32_t dex_pc, |
| 4384 | uint32_t dex_method_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4385 | : HInvoke(kInvokePolymorphic, |
| 4386 | allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4387 | number_of_arguments, |
| 4388 | 0u /* number_of_other_inputs */, |
| 4389 | return_type, |
| 4390 | dex_pc, |
| 4391 | dex_method_index, |
| 4392 | nullptr, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4393 | kVirtual) { |
| 4394 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4395 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4396 | bool IsClonable() const OVERRIDE { return true; } |
| 4397 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4398 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4399 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4400 | protected: |
| 4401 | DEFAULT_COPY_CONSTRUCTOR(InvokePolymorphic); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4402 | }; |
| 4403 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4404 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4405 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4406 | // Requirements of this method call regarding the class |
| 4407 | // initialization (clinit) check of its declaring class. |
| 4408 | enum class ClinitCheckRequirement { |
| 4409 | kNone, // Class already initialized. |
| 4410 | kExplicit, // Static call having explicit clinit check as last input. |
| 4411 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4412 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4413 | }; |
| 4414 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4415 | // Determines how to load the target ArtMethod*. |
| 4416 | enum class MethodLoadKind { |
| 4417 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4418 | kStringInit, |
| 4419 | |
| 4420 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4421 | kRecursive, |
| 4422 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4423 | // Use PC-relative boot image ArtMethod* address that will be known at link time. |
| 4424 | // Used for boot image methods referenced by boot image code. |
| 4425 | kBootImageLinkTimePcRelative, |
| 4426 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4427 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4428 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 4429 | kDirectAddress, |
| 4430 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4431 | // Load from an entry in the .bss section using a PC-relative load. |
| 4432 | // Used for classes outside boot image when .bss is accessible with a PC-relative load. |
| 4433 | kBssEntry, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4434 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4435 | // Make a runtime call to resolve and call the method. This is the last-resort-kind |
| 4436 | // used when other kinds are unimplemented on a particular architecture. |
| 4437 | kRuntimeCall, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4438 | }; |
| 4439 | |
| 4440 | // Determines the location of the code pointer. |
| 4441 | enum class CodePtrLocation { |
| 4442 | // Recursive call, use local PC-relative call instruction. |
| 4443 | kCallSelf, |
| 4444 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4445 | // Use code pointer from the ArtMethod*. |
| 4446 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4447 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4448 | kCallArtMethod, |
| 4449 | }; |
| 4450 | |
| 4451 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4452 | MethodLoadKind method_load_kind; |
| 4453 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4454 | // The method load data holds |
| 4455 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4456 | // Note that there are multiple string init methods, each having its own offset. |
| 4457 | // - the method address for kDirectAddress |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4458 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4459 | }; |
| 4460 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4461 | HInvokeStaticOrDirect(ArenaAllocator* allocator, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4462 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4463 | DataType::Type return_type, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4464 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4465 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4466 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4467 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4468 | InvokeType invoke_type, |
| 4469 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4470 | ClinitCheckRequirement clinit_check_requirement) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4471 | : HInvoke(kInvokeStaticOrDirect, |
| 4472 | allocator, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4473 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4474 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4475 | // potentially one other if the clinit check is explicit, and potentially |
| 4476 | // one other if the method is a string factory. |
| 4477 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4478 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4479 | return_type, |
| 4480 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4481 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4482 | resolved_method, |
| 4483 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4484 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4485 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4486 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4487 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4488 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4489 | bool IsClonable() const OVERRIDE { return true; } |
| 4490 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4491 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4492 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4493 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4494 | |
| 4495 | // Using the current method is the default and once we find a better |
| 4496 | // method load kind, we should not go back to using the current method. |
| 4497 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4498 | |
| 4499 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4500 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4501 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4502 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4503 | dispatch_info_ = dispatch_info; |
| 4504 | } |
| 4505 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 4506 | DispatchInfo GetDispatchInfo() const { |
| 4507 | return dispatch_info_; |
| 4508 | } |
| 4509 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4510 | void AddSpecialInput(HInstruction* input) { |
| 4511 | // We allow only one special input. |
| 4512 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4513 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4514 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4515 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4516 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4517 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4518 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4519 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4520 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4521 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4522 | DCHECK(!input_records.empty()); |
| 4523 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4524 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4525 | // Note: `last_input` may be null during arguments setup. |
| 4526 | if (last_input != nullptr) { |
| 4527 | // `last_input` is the last input of a static invoke marked as having |
| 4528 | // an explicit clinit check. It must either be: |
| 4529 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4530 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4531 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4532 | } |
| 4533 | } |
| 4534 | return input_records; |
| 4535 | } |
| 4536 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4537 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4538 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4539 | // TODO: for intrinsics we can generate implicit null checks. |
| 4540 | return false; |
| 4541 | } |
| 4542 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4543 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4544 | return GetPackedField<ReturnTypeField>() == DataType::Type::kReference && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4545 | } |
| 4546 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4547 | // Get the index of the special input, if any. |
| 4548 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4549 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4550 | // method pointer; otherwise there may be one platform-specific special input, |
| 4551 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4552 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4553 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4554 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4555 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4556 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4557 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4558 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4559 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4560 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4561 | bool HasPcRelativeMethodLoadKind() const { |
| 4562 | return GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4563 | GetMethodLoadKind() == MethodLoadKind::kBssEntry; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4564 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4565 | bool HasCurrentMethodInput() const { |
| 4566 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4567 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4568 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4569 | return true; |
| 4570 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4571 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4572 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4573 | return false; |
| 4574 | } |
| 4575 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4576 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4577 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4578 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4579 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4580 | } |
| 4581 | |
| 4582 | uint64_t GetMethodAddress() const { |
| 4583 | DCHECK(HasMethodAddress()); |
| 4584 | return dispatch_info_.method_load_data; |
| 4585 | } |
| 4586 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4587 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4588 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4589 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4590 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4591 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4592 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4593 | // Is this instruction a call to a static method? |
| 4594 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4595 | return GetInvokeType() == kStatic; |
| 4596 | } |
| 4597 | |
| 4598 | MethodReference GetTargetMethod() const { |
| 4599 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4600 | } |
| 4601 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4602 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4603 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4604 | // instruction; only relevant for static calls with explicit clinit check. |
| 4605 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4606 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4607 | size_t last_input_index = inputs_.size() - 1u; |
| 4608 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4609 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4610 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4611 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4612 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4613 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4614 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4615 | } |
| 4616 | |
| 4617 | // 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] | 4618 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4619 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4620 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4621 | } |
| 4622 | |
| 4623 | // Is this a call to a static method whose declaring class has an |
| 4624 | // implicit intialization check requirement? |
| 4625 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4626 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4627 | } |
| 4628 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4629 | // Does this method load kind need the current method as an input? |
| 4630 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4631 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kRuntimeCall; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4632 | } |
| 4633 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4634 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4635 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4636 | protected: |
| 4637 | DEFAULT_COPY_CONSTRUCTOR(InvokeStaticOrDirect); |
| 4638 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4639 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4640 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4641 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4642 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4643 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4644 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4645 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4646 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4647 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4648 | kFieldClinitCheckRequirement, |
| 4649 | kFieldClinitCheckRequirementSize>; |
| 4650 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4651 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | ea179f4 | 2018-02-08 22:30:18 +0000 | [diff] [blame] | 4652 | const MethodReference target_method_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4653 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4654 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4655 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4656 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4657 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4658 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4659 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4660 | HInvokeVirtual(ArenaAllocator* allocator, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4661 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4662 | DataType::Type return_type, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4663 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4664 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4665 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4666 | uint32_t vtable_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4667 | : HInvoke(kInvokeVirtual, |
| 4668 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4669 | number_of_arguments, |
| 4670 | 0u, |
| 4671 | return_type, |
| 4672 | dex_pc, |
| 4673 | dex_method_index, |
| 4674 | resolved_method, |
| 4675 | kVirtual), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4676 | vtable_index_(vtable_index) { |
| 4677 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4678 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4679 | bool IsClonable() const OVERRIDE { return true; } |
| 4680 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4681 | bool CanBeNull() const OVERRIDE { |
| 4682 | switch (GetIntrinsic()) { |
| 4683 | case Intrinsics::kThreadCurrentThread: |
| 4684 | case Intrinsics::kStringBufferAppend: |
| 4685 | case Intrinsics::kStringBufferToString: |
| 4686 | case Intrinsics::kStringBuilderAppend: |
| 4687 | case Intrinsics::kStringBuilderToString: |
| 4688 | return false; |
| 4689 | default: |
| 4690 | return HInvoke::CanBeNull(); |
| 4691 | } |
| 4692 | } |
| 4693 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4694 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4695 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4696 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4697 | } |
| 4698 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4699 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4700 | |
| 4701 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4702 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4703 | protected: |
| 4704 | DEFAULT_COPY_CONSTRUCTOR(InvokeVirtual); |
| 4705 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4706 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4707 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4708 | const uint32_t vtable_index_; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4709 | }; |
| 4710 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4711 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4712 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4713 | HInvokeInterface(ArenaAllocator* allocator, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4714 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4715 | DataType::Type return_type, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4716 | uint32_t dex_pc, |
| 4717 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4718 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4719 | uint32_t imt_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4720 | : HInvoke(kInvokeInterface, |
| 4721 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4722 | number_of_arguments, |
| 4723 | 0u, |
| 4724 | return_type, |
| 4725 | dex_pc, |
| 4726 | dex_method_index, |
| 4727 | resolved_method, |
| 4728 | kInterface), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4729 | imt_index_(imt_index) { |
| 4730 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4731 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4732 | bool IsClonable() const OVERRIDE { return true; } |
| 4733 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4734 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4735 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4736 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4737 | } |
| 4738 | |
Nicolas Geoffray | fbdfa6d | 2017-02-03 10:43:13 +0000 | [diff] [blame] | 4739 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 4740 | // The assembly stub currently needs it. |
| 4741 | return true; |
| 4742 | } |
| 4743 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4744 | uint32_t GetImtIndex() const { return imt_index_; } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4745 | |
| 4746 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4747 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4748 | protected: |
| 4749 | DEFAULT_COPY_CONSTRUCTOR(InvokeInterface); |
| 4750 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4751 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4752 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4753 | const uint32_t imt_index_; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4754 | }; |
| 4755 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4756 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4757 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4758 | 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] | 4759 | : HUnaryOperation(kNeg, result_type, input, dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4760 | DCHECK_EQ(result_type, DataType::Kind(input->GetType())); |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4761 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4762 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4763 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4764 | |
| 4765 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4766 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4767 | } |
| 4768 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4769 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4770 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4771 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4772 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4773 | } |
| 4774 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4775 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4776 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4777 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4778 | DECLARE_INSTRUCTION(Neg); |
| 4779 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4780 | protected: |
| 4781 | DEFAULT_COPY_CONSTRUCTOR(Neg); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4782 | }; |
| 4783 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4784 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4785 | public: |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4786 | HNewArray(HInstruction* cls, HInstruction* length, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4787 | : HExpression(kNewArray, DataType::Type::kReference, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4788 | SetRawInputAt(0, cls); |
| 4789 | SetRawInputAt(1, length); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4790 | } |
| 4791 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4792 | bool IsClonable() const OVERRIDE { return true; } |
| 4793 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4794 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4795 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4796 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4797 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4798 | bool CanThrow() const OVERRIDE { return true; } |
| 4799 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4800 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4801 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4802 | HLoadClass* GetLoadClass() const { |
| 4803 | DCHECK(InputAt(0)->IsLoadClass()); |
| 4804 | return InputAt(0)->AsLoadClass(); |
| 4805 | } |
| 4806 | |
| 4807 | HInstruction* GetLength() const { |
| 4808 | return InputAt(1); |
| 4809 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4810 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4811 | DECLARE_INSTRUCTION(NewArray); |
| 4812 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4813 | protected: |
| 4814 | DEFAULT_COPY_CONSTRUCTOR(NewArray); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4815 | }; |
| 4816 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4817 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4818 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4819 | HAdd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4820 | HInstruction* left, |
| 4821 | HInstruction* right, |
| 4822 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4823 | : HBinaryOperation(kAdd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4824 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4825 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4826 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4827 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4828 | 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] | 4829 | |
| 4830 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4831 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4832 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4833 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4834 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4835 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4836 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4837 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4838 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4839 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4840 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4841 | } |
| 4842 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4843 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4844 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4845 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4846 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4847 | DECLARE_INSTRUCTION(Add); |
| 4848 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4849 | protected: |
| 4850 | DEFAULT_COPY_CONSTRUCTOR(Add); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4851 | }; |
| 4852 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4853 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4854 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4855 | HSub(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4856 | HInstruction* left, |
| 4857 | HInstruction* right, |
| 4858 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4859 | : HBinaryOperation(kSub, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4860 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4861 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4862 | 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] | 4863 | |
| 4864 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4865 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4866 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4867 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4868 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4869 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4870 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4871 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4872 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4873 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4874 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4875 | } |
| 4876 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4877 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4878 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4879 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4880 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4881 | DECLARE_INSTRUCTION(Sub); |
| 4882 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4883 | protected: |
| 4884 | DEFAULT_COPY_CONSTRUCTOR(Sub); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4885 | }; |
| 4886 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4887 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4888 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4889 | HMul(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4890 | HInstruction* left, |
| 4891 | HInstruction* right, |
| 4892 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4893 | : HBinaryOperation(kMul, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4894 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4895 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4896 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4897 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4898 | 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] | 4899 | |
| 4900 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4901 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4902 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4903 | } |
| 4904 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4905 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4906 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4907 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4908 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4909 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4910 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4911 | } |
| 4912 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4913 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4914 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4915 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4916 | |
| 4917 | DECLARE_INSTRUCTION(Mul); |
| 4918 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4919 | protected: |
| 4920 | DEFAULT_COPY_CONSTRUCTOR(Mul); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4921 | }; |
| 4922 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4923 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4924 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4925 | HDiv(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) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4929 | : HBinaryOperation(kDiv, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4930 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4931 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4932 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4933 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4934 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4935 | // Our graph structure ensures we never have 0 for `y` during |
| 4936 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4937 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4938 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4939 | return (y == -1) ? -x : x / y; |
| 4940 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4941 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4942 | template <typename T> |
| 4943 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4944 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4945 | return x / y; |
| 4946 | } |
| 4947 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4948 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4949 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4950 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4951 | } |
| 4952 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4953 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4954 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4955 | } |
| 4956 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4957 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4958 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4959 | } |
| 4960 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4961 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4962 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4963 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4964 | |
| 4965 | DECLARE_INSTRUCTION(Div); |
| 4966 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4967 | protected: |
| 4968 | DEFAULT_COPY_CONSTRUCTOR(Div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4969 | }; |
| 4970 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4971 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4972 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4973 | HRem(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4974 | HInstruction* left, |
| 4975 | HInstruction* right, |
| 4976 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4977 | : HBinaryOperation(kRem, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4978 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4979 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4980 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4981 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4982 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4983 | // Our graph structure ensures we never have 0 for `y` during |
| 4984 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4985 | DCHECK_NE(y, 0); |
| 4986 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4987 | return (y == -1) ? 0 : x % y; |
| 4988 | } |
| 4989 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4990 | template <typename T> |
| 4991 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4992 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4993 | return std::fmod(x, y); |
| 4994 | } |
| 4995 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4996 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4997 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4998 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4999 | } |
| 5000 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5001 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5002 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5003 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5004 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 5005 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5006 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5007 | } |
| 5008 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 5009 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5010 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5011 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5012 | |
| 5013 | DECLARE_INSTRUCTION(Rem); |
| 5014 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5015 | protected: |
| 5016 | DEFAULT_COPY_CONSTRUCTOR(Rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5017 | }; |
| 5018 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame^] | 5019 | class HAbs FINAL : public HUnaryOperation { |
| 5020 | public: |
| 5021 | HAbs(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5022 | : HUnaryOperation(kAbs, result_type, input, dex_pc) {} |
| 5023 | |
| 5024 | // Evaluation for integral values. |
| 5025 | template <typename T> static T ComputeIntegral(T x) { |
| 5026 | return x < 0 ? -x : x; |
| 5027 | } |
| 5028 | |
| 5029 | // Evaluation for floating-point values. |
| 5030 | // Note, as a "quality of implementation", rather than pure "spec compliance", |
| 5031 | // we require that Math.abs() clears the sign bit (but changes nothing else) |
| 5032 | // for all floating-point numbers, including NaN (signaling NaN may become quiet though). |
| 5033 | // http://b/30758343 |
| 5034 | template <typename T, typename S> static T ComputeFP(T x) { |
| 5035 | S bits = bit_cast<S, T>(x); |
| 5036 | return bit_cast<T, S>(bits & std::numeric_limits<S>::max()); |
| 5037 | } |
| 5038 | |
| 5039 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
| 5040 | return GetBlock()->GetGraph()->GetIntConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5041 | } |
| 5042 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
| 5043 | return GetBlock()->GetGraph()->GetLongConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5044 | } |
| 5045 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 5046 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5047 | ComputeFP<float, int32_t>(x->GetValue()), GetDexPc()); |
| 5048 | } |
| 5049 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 5050 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5051 | ComputeFP<double, int64_t>(x->GetValue()), GetDexPc()); |
| 5052 | } |
| 5053 | |
| 5054 | DECLARE_INSTRUCTION(Abs); |
| 5055 | |
| 5056 | protected: |
| 5057 | DEFAULT_COPY_CONSTRUCTOR(Abs); |
| 5058 | }; |
| 5059 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5060 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5061 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 5062 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 5063 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5064 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5065 | : HExpression(kDivZeroCheck, value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5066 | SetRawInputAt(0, value); |
| 5067 | } |
| 5068 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5069 | DataType::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 5070 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5071 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5072 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5073 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5074 | return true; |
| 5075 | } |
| 5076 | |
| 5077 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5078 | bool CanThrow() const OVERRIDE { return true; } |
| 5079 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5080 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 5081 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5082 | protected: |
| 5083 | DEFAULT_COPY_CONSTRUCTOR(DivZeroCheck); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5084 | }; |
| 5085 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5086 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5087 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5088 | HShl(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5089 | HInstruction* value, |
| 5090 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5091 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5092 | : HBinaryOperation(kShl, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5093 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5094 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5095 | } |
| 5096 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5097 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5098 | 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] | 5099 | return value << (distance & max_shift_distance); |
| 5100 | } |
| 5101 | |
| 5102 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5103 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5104 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5105 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5106 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5107 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5108 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5109 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5110 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5111 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5112 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5113 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5114 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5115 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5116 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5117 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5118 | UNREACHABLE(); |
| 5119 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5120 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5121 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5122 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5123 | UNREACHABLE(); |
| 5124 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5125 | |
| 5126 | DECLARE_INSTRUCTION(Shl); |
| 5127 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5128 | protected: |
| 5129 | DEFAULT_COPY_CONSTRUCTOR(Shl); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5130 | }; |
| 5131 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5132 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5133 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5134 | HShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5135 | HInstruction* value, |
| 5136 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5137 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5138 | : HBinaryOperation(kShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5139 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5140 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5141 | } |
| 5142 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5143 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5144 | 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] | 5145 | return value >> (distance & max_shift_distance); |
| 5146 | } |
| 5147 | |
| 5148 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5149 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5150 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5151 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5152 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5153 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5154 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5155 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5156 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5157 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5158 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5159 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5160 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5161 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5162 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5163 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5164 | UNREACHABLE(); |
| 5165 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5166 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5167 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5168 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5169 | UNREACHABLE(); |
| 5170 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5171 | |
| 5172 | DECLARE_INSTRUCTION(Shr); |
| 5173 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5174 | protected: |
| 5175 | DEFAULT_COPY_CONSTRUCTOR(Shr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5176 | }; |
| 5177 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5178 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5179 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5180 | HUShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5181 | HInstruction* value, |
| 5182 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5183 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5184 | : HBinaryOperation(kUShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5185 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5186 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5187 | } |
| 5188 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5189 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5190 | 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] | 5191 | typedef typename std::make_unsigned<T>::type V; |
| 5192 | V ux = static_cast<V>(value); |
| 5193 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 5194 | } |
| 5195 | |
| 5196 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5197 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5198 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5199 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5200 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5201 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5202 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5203 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5204 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5205 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5206 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5207 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5208 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5209 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5210 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5211 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5212 | UNREACHABLE(); |
| 5213 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5214 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5215 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5216 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5217 | UNREACHABLE(); |
| 5218 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5219 | |
| 5220 | DECLARE_INSTRUCTION(UShr); |
| 5221 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5222 | protected: |
| 5223 | DEFAULT_COPY_CONSTRUCTOR(UShr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5224 | }; |
| 5225 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5226 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5227 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5228 | HAnd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5229 | HInstruction* left, |
| 5230 | HInstruction* right, |
| 5231 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5232 | : HBinaryOperation(kAnd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5233 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5234 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5235 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5236 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5237 | 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] | 5238 | |
| 5239 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5240 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5241 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5242 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5243 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5244 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5245 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5246 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5247 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5248 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5249 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5250 | UNREACHABLE(); |
| 5251 | } |
| 5252 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5253 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5254 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5255 | UNREACHABLE(); |
| 5256 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5257 | |
| 5258 | DECLARE_INSTRUCTION(And); |
| 5259 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5260 | protected: |
| 5261 | DEFAULT_COPY_CONSTRUCTOR(And); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5262 | }; |
| 5263 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5264 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5265 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5266 | HOr(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5267 | HInstruction* left, |
| 5268 | HInstruction* right, |
| 5269 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5270 | : HBinaryOperation(kOr, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5271 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5272 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5273 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5274 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5275 | 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] | 5276 | |
| 5277 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5278 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5279 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5280 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5281 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5282 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5283 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5284 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5285 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5286 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5287 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5288 | UNREACHABLE(); |
| 5289 | } |
| 5290 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5291 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5292 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5293 | UNREACHABLE(); |
| 5294 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5295 | |
| 5296 | DECLARE_INSTRUCTION(Or); |
| 5297 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5298 | protected: |
| 5299 | DEFAULT_COPY_CONSTRUCTOR(Or); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5300 | }; |
| 5301 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5302 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5303 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5304 | HXor(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5305 | HInstruction* left, |
| 5306 | HInstruction* right, |
| 5307 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5308 | : HBinaryOperation(kXor, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5309 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5310 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5311 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5312 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5313 | 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] | 5314 | |
| 5315 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5316 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5317 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5318 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5319 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5320 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5321 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5322 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5323 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5324 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5325 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5326 | UNREACHABLE(); |
| 5327 | } |
| 5328 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5329 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5330 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5331 | UNREACHABLE(); |
| 5332 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5333 | |
| 5334 | DECLARE_INSTRUCTION(Xor); |
| 5335 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5336 | protected: |
| 5337 | DEFAULT_COPY_CONSTRUCTOR(Xor); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5338 | }; |
| 5339 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5340 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5341 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5342 | HRor(DataType::Type result_type, HInstruction* value, HInstruction* distance) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5343 | : HBinaryOperation(kRor, result_type, value, distance) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5344 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5345 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5346 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5347 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5348 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5349 | 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] | 5350 | typedef typename std::make_unsigned<T>::type V; |
| 5351 | V ux = static_cast<V>(value); |
| 5352 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5353 | return static_cast<T>(ux); |
| 5354 | } else { |
| 5355 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5356 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 5357 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5358 | } |
| 5359 | } |
| 5360 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5361 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5362 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5363 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5364 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5365 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5366 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5367 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5368 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5369 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5370 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5371 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5372 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5373 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5374 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5375 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5376 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5377 | UNREACHABLE(); |
| 5378 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5379 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5380 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5381 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5382 | UNREACHABLE(); |
| 5383 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5384 | |
| 5385 | DECLARE_INSTRUCTION(Ror); |
| 5386 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5387 | protected: |
| 5388 | DEFAULT_COPY_CONSTRUCTOR(Ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5389 | }; |
| 5390 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5391 | // The value of a parameter in this method. Its location depends on |
| 5392 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5393 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5394 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5395 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5396 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5397 | uint8_t index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5398 | DataType::Type parameter_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5399 | bool is_this = false) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5400 | : HExpression(kParameterValue, parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5401 | dex_file_(dex_file), |
| 5402 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5403 | index_(index) { |
| 5404 | SetPackedFlag<kFlagIsThis>(is_this); |
| 5405 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 5406 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5407 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5408 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5409 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5410 | uint8_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5411 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5412 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5413 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 5414 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5415 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5416 | DECLARE_INSTRUCTION(ParameterValue); |
| 5417 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5418 | protected: |
| 5419 | DEFAULT_COPY_CONSTRUCTOR(ParameterValue); |
| 5420 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5421 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5422 | // Whether or not the parameter value corresponds to 'this' argument. |
| 5423 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 5424 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 5425 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 5426 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 5427 | "Too many packed fields."); |
| 5428 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5429 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5430 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5431 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5432 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5433 | const uint8_t index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5434 | }; |
| 5435 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5436 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5437 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5438 | 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] | 5439 | : HUnaryOperation(kNot, result_type, input, dex_pc) { |
| 5440 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5441 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5442 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5443 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5444 | return true; |
| 5445 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5446 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5447 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5448 | |
| 5449 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5450 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5451 | } |
| 5452 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5453 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5454 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5455 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5456 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5457 | UNREACHABLE(); |
| 5458 | } |
| 5459 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5460 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5461 | UNREACHABLE(); |
| 5462 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5463 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5464 | DECLARE_INSTRUCTION(Not); |
| 5465 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5466 | protected: |
| 5467 | DEFAULT_COPY_CONSTRUCTOR(Not); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5468 | }; |
| 5469 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5470 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5471 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5472 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5473 | : HUnaryOperation(kBooleanNot, DataType::Type::kBool, input, dex_pc) { |
| 5474 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5475 | |
| 5476 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5477 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5478 | return true; |
| 5479 | } |
| 5480 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5481 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5482 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5483 | return !x; |
| 5484 | } |
| 5485 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5486 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5487 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5488 | } |
| 5489 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5490 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5491 | UNREACHABLE(); |
| 5492 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5493 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5494 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5495 | UNREACHABLE(); |
| 5496 | } |
| 5497 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5498 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5499 | UNREACHABLE(); |
| 5500 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5501 | |
| 5502 | DECLARE_INSTRUCTION(BooleanNot); |
| 5503 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5504 | protected: |
| 5505 | DEFAULT_COPY_CONSTRUCTOR(BooleanNot); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5506 | }; |
| 5507 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5508 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5509 | public: |
| 5510 | // Instantiate a type conversion of `input` to `result_type`. |
Vladimir Marko | c8fb211 | 2017-10-03 11:37:52 +0100 | [diff] [blame] | 5511 | 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] | 5512 | : HExpression(kTypeConversion, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5513 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5514 | // Invariant: We should never generate a conversion to a Boolean value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5515 | DCHECK_NE(DataType::Type::kBool, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5519 | DataType::Type GetInputType() const { return GetInput()->GetType(); } |
| 5520 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5521 | |
| 5522 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5523 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5524 | return true; |
| 5525 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5526 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5527 | // Try to statically evaluate the conversion and return a HConstant |
| 5528 | // containing the result. If the input cannot be converted, return nullptr. |
| 5529 | HConstant* TryStaticEvaluation() const; |
| 5530 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5531 | DECLARE_INSTRUCTION(TypeConversion); |
| 5532 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5533 | protected: |
| 5534 | DEFAULT_COPY_CONSTRUCTOR(TypeConversion); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5535 | }; |
| 5536 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5537 | static constexpr uint32_t kNoRegNumber = -1; |
| 5538 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5539 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5540 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5541 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 5542 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5543 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5544 | : HExpression(kNullCheck, value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5545 | SetRawInputAt(0, value); |
| 5546 | } |
| 5547 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5548 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5549 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5550 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5551 | return true; |
| 5552 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5553 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5554 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5555 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5556 | bool CanThrow() const OVERRIDE { return true; } |
| 5557 | |
| 5558 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5559 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5560 | DECLARE_INSTRUCTION(NullCheck); |
| 5561 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5562 | protected: |
| 5563 | DEFAULT_COPY_CONSTRUCTOR(NullCheck); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5564 | }; |
| 5565 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5566 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5567 | // 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] | 5568 | class FieldInfo : public ValueObject { |
| 5569 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5570 | FieldInfo(ArtField* field, |
| 5571 | MemberOffset field_offset, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5572 | DataType::Type field_type, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5573 | bool is_volatile, |
| 5574 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5575 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5576 | const DexFile& dex_file) |
| 5577 | : field_(field), |
| 5578 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5579 | field_type_(field_type), |
| 5580 | is_volatile_(is_volatile), |
| 5581 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5582 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5583 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5584 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5585 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5586 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5587 | DataType::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5588 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5589 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5590 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5591 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5592 | |
| 5593 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5594 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5595 | const MemberOffset field_offset_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5596 | const DataType::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5597 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5598 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5599 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5600 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5601 | }; |
| 5602 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5603 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5604 | public: |
| 5605 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5606 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5607 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5608 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5609 | bool is_volatile, |
| 5610 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5611 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5612 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5613 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5614 | : HExpression(kInstanceFieldGet, |
| 5615 | field_type, |
| 5616 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5617 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5618 | field_info_(field, |
| 5619 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5620 | field_type, |
| 5621 | is_volatile, |
| 5622 | field_idx, |
| 5623 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5624 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5625 | SetRawInputAt(0, value); |
| 5626 | } |
| 5627 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5628 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5629 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5630 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5631 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5632 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5633 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5634 | } |
| 5635 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5636 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5637 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5638 | } |
| 5639 | |
| 5640 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5641 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5642 | } |
| 5643 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5644 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5645 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5646 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5647 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5648 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5649 | void SetType(DataType::Type new_type) { |
| 5650 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5651 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5652 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5653 | SetPackedField<TypeField>(new_type); |
| 5654 | } |
| 5655 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5656 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5657 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5658 | protected: |
| 5659 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldGet); |
| 5660 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5661 | private: |
| 5662 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5663 | }; |
| 5664 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5665 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5666 | public: |
| 5667 | HInstanceFieldSet(HInstruction* object, |
| 5668 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5669 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5670 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5671 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5672 | bool is_volatile, |
| 5673 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5674 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5675 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5676 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5677 | : HTemplateInstruction(kInstanceFieldSet, |
| 5678 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5679 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5680 | field_info_(field, |
| 5681 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5682 | field_type, |
| 5683 | is_volatile, |
| 5684 | field_idx, |
| 5685 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5686 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5687 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5688 | SetRawInputAt(0, object); |
| 5689 | SetRawInputAt(1, value); |
| 5690 | } |
| 5691 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5692 | bool IsClonable() const OVERRIDE { return true; } |
| 5693 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5694 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5695 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5696 | } |
| 5697 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5698 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5699 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5700 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5701 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5702 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5703 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5704 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5705 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5706 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5707 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5708 | protected: |
| 5709 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldSet); |
| 5710 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5711 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5712 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5713 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5714 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5715 | "Too many packed fields."); |
| 5716 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5717 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5718 | }; |
| 5719 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5720 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5721 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5722 | HArrayGet(HInstruction* array, |
| 5723 | HInstruction* index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5724 | DataType::Type type, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5725 | uint32_t dex_pc) |
| 5726 | : HArrayGet(array, |
| 5727 | index, |
| 5728 | type, |
| 5729 | SideEffects::ArrayReadOfType(type), |
| 5730 | dex_pc, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5731 | /* is_string_char_at */ false) { |
| 5732 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5733 | |
| 5734 | HArrayGet(HInstruction* array, |
| 5735 | HInstruction* index, |
| 5736 | DataType::Type type, |
| 5737 | SideEffects side_effects, |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5738 | uint32_t dex_pc, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5739 | bool is_string_char_at) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5740 | : HExpression(kArrayGet, type, side_effects, dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5741 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5742 | SetRawInputAt(0, array); |
| 5743 | SetRawInputAt(1, index); |
| 5744 | } |
| 5745 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5746 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5747 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5748 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5749 | return true; |
| 5750 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5751 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5752 | // TODO: We can be smarter here. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5753 | // Currently, unless the array is the result of NewArray, the array access is always |
| 5754 | // preceded by some form of null NullCheck necessary for the bounds check, usually |
| 5755 | // implicit null check on the ArrayLength input to BoundsCheck or Deoptimize for |
| 5756 | // dynamic BCE. There are cases when these could be removed to produce better code. |
| 5757 | // If we ever add optimizations to do so we should allow an implicit check here |
| 5758 | // (as long as the address falls in the first page). |
| 5759 | // |
| 5760 | // As an example of such fancy optimization, we could eliminate BoundsCheck for |
| 5761 | // a = cond ? new int[1] : null; |
| 5762 | // a[0]; // The Phi does not need bounds check for either input. |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5763 | return false; |
| 5764 | } |
| 5765 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5766 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5767 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5768 | if (kIsDebugBuild && result) { |
| 5769 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5770 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5771 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5772 | if (DataType::IsIntOrLongType(GetType())) { |
| 5773 | DCHECK(DataType::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5774 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5775 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| 5776 | DCHECK(DataType::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5777 | } |
| 5778 | } |
| 5779 | return result; |
| 5780 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5781 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5782 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5783 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5784 | HInstruction* GetArray() const { return InputAt(0); } |
| 5785 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5786 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5787 | void SetType(DataType::Type new_type) { |
| 5788 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5789 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5790 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5791 | SetPackedField<TypeField>(new_type); |
| 5792 | } |
| 5793 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5794 | DECLARE_INSTRUCTION(ArrayGet); |
| 5795 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5796 | protected: |
| 5797 | DEFAULT_COPY_CONSTRUCTOR(ArrayGet); |
| 5798 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5799 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5800 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5801 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5802 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5803 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5804 | // a flag, so that code generators don't need to do the locking. |
| 5805 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5806 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5807 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5808 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5809 | }; |
| 5810 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5811 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5812 | public: |
| 5813 | HArraySet(HInstruction* array, |
| 5814 | HInstruction* index, |
| 5815 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5816 | DataType::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5817 | uint32_t dex_pc) |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5818 | : HArraySet(array, |
| 5819 | index, |
| 5820 | value, |
| 5821 | expected_component_type, |
| 5822 | // Make a best guess for side effects now, may be refined during SSA building. |
| 5823 | ComputeSideEffects(GetComponentType(value->GetType(), expected_component_type)), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5824 | dex_pc) { |
| 5825 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5826 | |
| 5827 | HArraySet(HInstruction* array, |
| 5828 | HInstruction* index, |
| 5829 | HInstruction* value, |
| 5830 | DataType::Type expected_component_type, |
| 5831 | SideEffects side_effects, |
| 5832 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5833 | : HTemplateInstruction(kArraySet, side_effects, dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5834 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5835 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5836 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5837 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5838 | SetRawInputAt(0, array); |
| 5839 | SetRawInputAt(1, index); |
| 5840 | SetRawInputAt(2, value); |
| 5841 | } |
| 5842 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5843 | bool IsClonable() const OVERRIDE { return true; } |
| 5844 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5845 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5846 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5847 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5848 | } |
| 5849 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5850 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5851 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5852 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5853 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5854 | // TODO: Same as for ArrayGet. |
| 5855 | return false; |
| 5856 | } |
| 5857 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5858 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5859 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5860 | } |
| 5861 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5862 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5863 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5864 | } |
| 5865 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5866 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5867 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5868 | } |
| 5869 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5870 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5871 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5872 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5873 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5874 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5875 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5876 | HInstruction* GetArray() const { return InputAt(0); } |
| 5877 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5878 | HInstruction* GetValue() const { return InputAt(2); } |
| 5879 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5880 | DataType::Type GetComponentType() const { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5881 | return GetComponentType(GetValue()->GetType(), GetRawExpectedComponentType()); |
| 5882 | } |
| 5883 | |
| 5884 | static DataType::Type GetComponentType(DataType::Type value_type, |
| 5885 | DataType::Type expected_component_type) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5886 | // The Dex format does not type floating point index operations. Since the |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5887 | // `expected_component_type` comes from SSA building and can therefore not |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5888 | // be correct, we also check what is the value type. If it is a floating |
| 5889 | // point type, we must use that type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5890 | return ((value_type == DataType::Type::kFloat32) || (value_type == DataType::Type::kFloat64)) |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5891 | ? value_type |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5892 | : expected_component_type; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5893 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5894 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5895 | DataType::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5896 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5897 | } |
| 5898 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5899 | static SideEffects ComputeSideEffects(DataType::Type type) { |
| 5900 | return SideEffects::ArrayWriteOfType(type).Union(SideEffectsForArchRuntimeCalls(type)); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5903 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type value_type) { |
| 5904 | return (value_type == DataType::Type::kReference) ? SideEffects::CanTriggerGC() |
| 5905 | : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5906 | } |
| 5907 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5908 | DECLARE_INSTRUCTION(ArraySet); |
| 5909 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5910 | protected: |
| 5911 | DEFAULT_COPY_CONSTRUCTOR(ArraySet); |
| 5912 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5913 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5914 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5915 | static constexpr size_t kFieldExpectedComponentTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5916 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5917 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5918 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5919 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5920 | // Cached information for the reference_type_info_ so that codegen |
| 5921 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5922 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5923 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5924 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5925 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5926 | using ExpectedComponentTypeField = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5927 | BitField<DataType::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5928 | }; |
| 5929 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5930 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5931 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5932 | 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] | 5933 | : HExpression(kArrayLength, DataType::Type::kInt32, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5934 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5935 | // Note that arrays do not change length, so the instruction does not |
| 5936 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5937 | SetRawInputAt(0, array); |
| 5938 | } |
| 5939 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5940 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5941 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5942 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5943 | return true; |
| 5944 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5945 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5946 | return obj == InputAt(0); |
| 5947 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5948 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5949 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5950 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5951 | DECLARE_INSTRUCTION(ArrayLength); |
| 5952 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5953 | protected: |
| 5954 | DEFAULT_COPY_CONSTRUCTOR(ArrayLength); |
| 5955 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5956 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5957 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5958 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5959 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5960 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5961 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5962 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5963 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5964 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5965 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5966 | }; |
| 5967 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5968 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5969 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5970 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5971 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5972 | HBoundsCheck(HInstruction* index, |
| 5973 | HInstruction* length, |
| 5974 | uint32_t dex_pc, |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 5975 | bool is_string_char_at = false) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5976 | : HExpression(kBoundsCheck, index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5977 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(index->GetType())); |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 5978 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5979 | SetRawInputAt(0, index); |
| 5980 | SetRawInputAt(1, length); |
| 5981 | } |
| 5982 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5983 | bool IsClonable() const OVERRIDE { return true; } |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5984 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5985 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5986 | return true; |
| 5987 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5988 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5989 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5990 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5991 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5992 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5993 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5994 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5995 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5996 | |
| 5997 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5998 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5999 | protected: |
| 6000 | DEFAULT_COPY_CONSTRUCTOR(BoundsCheck); |
| 6001 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6002 | private: |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 6003 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6004 | }; |
| 6005 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6006 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6007 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 6008 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6009 | : HTemplateInstruction(kSuspendCheck, SideEffects::CanTriggerGC(), dex_pc), |
| 6010 | slow_path_(nullptr) { |
| 6011 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6012 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6013 | bool IsClonable() const OVERRIDE { return true; } |
| 6014 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6015 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6016 | return true; |
| 6017 | } |
| 6018 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6019 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 6020 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6021 | |
| 6022 | DECLARE_INSTRUCTION(SuspendCheck); |
| 6023 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6024 | protected: |
| 6025 | DEFAULT_COPY_CONSTRUCTOR(SuspendCheck); |
| 6026 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6027 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6028 | // Only used for code generation, in order to share the same slow path between back edges |
| 6029 | // of a same loop. |
| 6030 | SlowPathCode* slow_path_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6031 | }; |
| 6032 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6033 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 6034 | // It ensures that we can generate line number and local variables at this point. |
| 6035 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 6036 | public: |
| 6037 | explicit HNativeDebugInfo(uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6038 | : HTemplateInstruction<0>(kNativeDebugInfo, SideEffects::None(), dex_pc) { |
| 6039 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6040 | |
| 6041 | bool NeedsEnvironment() const OVERRIDE { |
| 6042 | return true; |
| 6043 | } |
| 6044 | |
| 6045 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 6046 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6047 | protected: |
| 6048 | DEFAULT_COPY_CONSTRUCTOR(NativeDebugInfo); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6049 | }; |
| 6050 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6051 | /** |
| 6052 | * Instruction to load a Class object. |
| 6053 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6054 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6055 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6056 | // Determines how to load the Class. |
| 6057 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6058 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 6059 | kInvalid = -1, |
| 6060 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6061 | // Use the Class* from the method's own ArtMethod*. |
| 6062 | kReferrersClass, |
| 6063 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6064 | // 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] | 6065 | // Used for boot image classes referenced by boot image code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6066 | kBootImageLinkTimePcRelative, |
| 6067 | |
| 6068 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 6069 | // Used for boot image classes referenced by apps in AOT- and JIT-compiled code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6070 | kBootImageAddress, |
| 6071 | |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6072 | // Use a PC-relative load from a boot image ClassTable mmapped into the .bss |
| 6073 | // of the oat file. |
| 6074 | kBootImageClassTable, |
| 6075 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6076 | // Load from an entry in the .bss section using a PC-relative load. |
| 6077 | // Used for classes outside boot image when .bss is accessible with a PC-relative load. |
| 6078 | kBssEntry, |
| 6079 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6080 | // Load from the root table associated with the JIT compiled method. |
| 6081 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6082 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6083 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6084 | // the codegen is unable to use another appropriate kind. |
| 6085 | kRuntimeCall, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6086 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6087 | kLast = kRuntimeCall |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6088 | }; |
| 6089 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6090 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6091 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6092 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6093 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6094 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6095 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6096 | bool needs_access_check) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6097 | : HInstruction(kLoadClass, SideEffectsForArchRuntimeCalls(), dex_pc), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6098 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6099 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6100 | dex_file_(dex_file), |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6101 | klass_(klass), |
| 6102 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 6103 | // Referrers class should not need access check. We never inline unverified |
| 6104 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6105 | DCHECK(!is_referrers_class || !needs_access_check); |
| 6106 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6107 | SetPackedField<LoadKindField>( |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6108 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kRuntimeCall); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6109 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6110 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6111 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6112 | } |
| 6113 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6114 | bool IsClonable() const OVERRIDE { return true; } |
| 6115 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6116 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6117 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6118 | LoadKind GetLoadKind() const { |
| 6119 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6120 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6121 | |
| 6122 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6123 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6124 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6125 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6126 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6127 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 6128 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6129 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6130 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6131 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6132 | } |
| 6133 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 6134 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 6135 | // The entrypoint the code generator is going to call does not do |
| 6136 | // clinit of the class. |
| 6137 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6138 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6139 | } |
| 6140 | |
| 6141 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6142 | return NeedsAccessCheck() || |
| 6143 | MustGenerateClinitCheck() || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6144 | GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6145 | GetLoadKind() == LoadKind::kBssEntry; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6146 | } |
| 6147 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6148 | bool CanThrow() const OVERRIDE { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6149 | return NeedsAccessCheck() || |
| 6150 | MustGenerateClinitCheck() || |
| 6151 | // If the class is in the boot image, the lookup in the runtime call cannot throw. |
| 6152 | // This keeps CanThrow() consistent between non-PIC (using kBootImageAddress) and |
| 6153 | // PIC and subsequently avoids a DCE behavior dependency on the PIC option. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6154 | ((GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6155 | GetLoadKind() == LoadKind::kBssEntry) && |
| 6156 | !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6157 | } |
| 6158 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6159 | ReferenceTypeInfo GetLoadedClassRTI() { |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6160 | return loaded_class_rti_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6161 | } |
| 6162 | |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6163 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 6164 | // Make sure we only set exact types (the loaded class should never be merged). |
| 6165 | DCHECK(rti.IsExact()); |
| 6166 | loaded_class_rti_ = rti; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6167 | } |
| 6168 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6169 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6170 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6171 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6172 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6173 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6174 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 6175 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6176 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6177 | return SideEffects::CanTriggerGC(); |
| 6178 | } |
| 6179 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6180 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6181 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6182 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6183 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6184 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6185 | void MarkInBootImage() { |
| 6186 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 6187 | } |
| 6188 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6189 | void AddSpecialInput(HInstruction* special_input); |
| 6190 | |
| 6191 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6192 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6193 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6194 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6195 | } |
| 6196 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6197 | DataType::Type GetType() const OVERRIDE { |
| 6198 | return DataType::Type::kReference; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6199 | } |
| 6200 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6201 | Handle<mirror::Class> GetClass() const { |
| 6202 | return klass_; |
| 6203 | } |
| 6204 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6205 | DECLARE_INSTRUCTION(LoadClass); |
| 6206 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6207 | protected: |
| 6208 | DEFAULT_COPY_CONSTRUCTOR(LoadClass); |
| 6209 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6210 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6211 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6212 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6213 | // Whether this instruction must generate the initialization check. |
| 6214 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6215 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6216 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 6217 | static constexpr size_t kFieldLoadKindSize = |
| 6218 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6219 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6220 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6221 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 6222 | |
| 6223 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6224 | return load_kind == LoadKind::kReferrersClass || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6225 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6226 | load_kind == LoadKind::kBootImageClassTable || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6227 | load_kind == LoadKind::kBssEntry || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6228 | load_kind == LoadKind::kRuntimeCall; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6229 | } |
| 6230 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6231 | void SetLoadKindInternal(LoadKind load_kind); |
| 6232 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6233 | // The special input is the HCurrentMethod for kRuntimeCall or kReferrersClass. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6234 | // 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] | 6235 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6236 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6237 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6238 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 6239 | // - The compiling method's dex file if the class is defined there too. |
| 6240 | // - The compiling method's dex file if the class is referenced there. |
| 6241 | // - 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] | 6242 | // kBssEntry or kRuntimeCall, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6243 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6244 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6245 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6246 | Handle<mirror::Class> klass_; |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6247 | |
| 6248 | ReferenceTypeInfo loaded_class_rti_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6249 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6250 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 6251 | |
| 6252 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6253 | inline void HLoadClass::SetLoadKind(LoadKind load_kind) { |
| 6254 | // The load kind should be determined before inserting the instruction to the graph. |
| 6255 | DCHECK(GetBlock() == nullptr); |
| 6256 | DCHECK(GetEnvironment() == nullptr); |
| 6257 | SetPackedField<LoadKindField>(load_kind); |
| 6258 | if (load_kind != LoadKind::kRuntimeCall && load_kind != LoadKind::kReferrersClass) { |
| 6259 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6260 | } |
| 6261 | if (!NeedsEnvironment()) { |
| 6262 | SetSideEffects(SideEffects::None()); |
| 6263 | } |
| 6264 | } |
| 6265 | |
| 6266 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6267 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6268 | // The special input is used for PC-relative loads on some architectures, |
| 6269 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6270 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6271 | GetLoadKind() == LoadKind::kBootImageAddress || |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6272 | GetLoadKind() == LoadKind::kBootImageClassTable || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6273 | GetLoadKind() == LoadKind::kBssEntry) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6274 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6275 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 6276 | special_input->AddUseAt(this, 0); |
| 6277 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6278 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6279 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6280 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6281 | // Determines how to load the String. |
| 6282 | enum class LoadKind { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6283 | // 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] | 6284 | // Used for boot image strings referenced by boot image code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6285 | kBootImageLinkTimePcRelative, |
| 6286 | |
| 6287 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 6288 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6289 | kBootImageAddress, |
| 6290 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6291 | // Use a PC-relative load from a boot image InternTable mmapped into the .bss |
| 6292 | // of the oat file. |
| 6293 | kBootImageInternTable, |
| 6294 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6295 | // Load from an entry in the .bss section using a PC-relative load. |
| 6296 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 6297 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6298 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6299 | // Load from the root table associated with the JIT compiled method. |
| 6300 | kJitTableAddress, |
| 6301 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6302 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6303 | // the codegen is unable to use another appropriate kind. |
| 6304 | kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6305 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6306 | kLast = kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6307 | }; |
| 6308 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6309 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6310 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6311 | const DexFile& dex_file, |
| 6312 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6313 | : HInstruction(kLoadString, SideEffectsForArchRuntimeCalls(), dex_pc), |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6314 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6315 | string_index_(string_index), |
| 6316 | dex_file_(dex_file) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6317 | SetPackedField<LoadKindField>(LoadKind::kRuntimeCall); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6318 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6319 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6320 | bool IsClonable() const OVERRIDE { return true; } |
| 6321 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6322 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6323 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6324 | LoadKind GetLoadKind() const { |
| 6325 | return GetPackedField<LoadKindField>(); |
| 6326 | } |
| 6327 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6328 | const DexFile& GetDexFile() const { |
| 6329 | return dex_file_; |
| 6330 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6331 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6332 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6333 | return string_index_; |
| 6334 | } |
| 6335 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6336 | Handle<mirror::String> GetString() const { |
| 6337 | return string_; |
| 6338 | } |
| 6339 | |
| 6340 | void SetString(Handle<mirror::String> str) { |
| 6341 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6342 | } |
| 6343 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6344 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6345 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6346 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6347 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6348 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6349 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6350 | // Will call the runtime if we need to load the string through |
| 6351 | // the dex cache and the string is not guaranteed to be there yet. |
| 6352 | bool NeedsEnvironment() const OVERRIDE { |
| 6353 | LoadKind load_kind = GetLoadKind(); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6354 | if (load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6355 | load_kind == LoadKind::kBootImageAddress || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6356 | load_kind == LoadKind::kBootImageInternTable || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6357 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6358 | return false; |
| 6359 | } |
Vladimir Marko | 4d1be49 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6360 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6361 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6362 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6363 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6364 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6365 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6366 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 6367 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6368 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6369 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6370 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6371 | return SideEffects::CanTriggerGC(); |
| 6372 | } |
| 6373 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6374 | void AddSpecialInput(HInstruction* special_input); |
| 6375 | |
| 6376 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6377 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6378 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6379 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6380 | } |
| 6381 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6382 | DataType::Type GetType() const OVERRIDE { |
| 6383 | return DataType::Type::kReference; |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6384 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6385 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6386 | DECLARE_INSTRUCTION(LoadString); |
| 6387 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6388 | protected: |
| 6389 | DEFAULT_COPY_CONSTRUCTOR(LoadString); |
| 6390 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6391 | private: |
Vladimir Marko | 4d1be49 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6392 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6393 | static constexpr size_t kFieldLoadKindSize = |
| 6394 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 6395 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6396 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6397 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6398 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6399 | void SetLoadKindInternal(LoadKind load_kind); |
| 6400 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6401 | // The special input is the HCurrentMethod for kRuntimeCall. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6402 | // 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] | 6403 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6404 | HUserRecord<HInstruction*> special_input_; |
| 6405 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6406 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6407 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6408 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6409 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6410 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6411 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 6412 | |
| 6413 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6414 | inline void HLoadString::SetLoadKind(LoadKind load_kind) { |
| 6415 | // The load kind should be determined before inserting the instruction to the graph. |
| 6416 | DCHECK(GetBlock() == nullptr); |
| 6417 | DCHECK(GetEnvironment() == nullptr); |
| 6418 | DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); |
| 6419 | SetPackedField<LoadKindField>(load_kind); |
| 6420 | if (load_kind != LoadKind::kRuntimeCall) { |
| 6421 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6422 | } |
| 6423 | if (!NeedsEnvironment()) { |
| 6424 | SetSideEffects(SideEffects::None()); |
| 6425 | } |
| 6426 | } |
| 6427 | |
| 6428 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6429 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6430 | // The special input is used for PC-relative loads on some architectures, |
| 6431 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6432 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6433 | GetLoadKind() == LoadKind::kBootImageAddress || |
| 6434 | GetLoadKind() == LoadKind::kBootImageInternTable || |
| 6435 | GetLoadKind() == LoadKind::kBssEntry) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6436 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 6437 | // so use the GetInputRecords() from the base class to set the input record. |
| 6438 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6439 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6440 | special_input->AddUseAt(this, 0); |
| 6441 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6442 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6443 | /** |
| 6444 | * Performs an initialization check on its Class object input. |
| 6445 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6446 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6447 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 6448 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 6449 | : HExpression( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6450 | kClinitCheck, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6451 | DataType::Type::kReference, |
Mingyao Yang | 217eb06 | 2017-12-11 15:20:07 -0800 | [diff] [blame] | 6452 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6453 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6454 | SetRawInputAt(0, constant); |
| 6455 | } |
| 6456 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6457 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6458 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6459 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6460 | return true; |
| 6461 | } |
| 6462 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6463 | bool NeedsEnvironment() const OVERRIDE { |
| 6464 | // May call runtime to initialize the class. |
| 6465 | return true; |
| 6466 | } |
| 6467 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 6468 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6469 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6470 | HLoadClass* GetLoadClass() const { |
| 6471 | DCHECK(InputAt(0)->IsLoadClass()); |
| 6472 | return InputAt(0)->AsLoadClass(); |
| 6473 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6474 | |
| 6475 | DECLARE_INSTRUCTION(ClinitCheck); |
| 6476 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6477 | |
| 6478 | protected: |
| 6479 | DEFAULT_COPY_CONSTRUCTOR(ClinitCheck); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6480 | }; |
| 6481 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6482 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6483 | public: |
| 6484 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6485 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6486 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6487 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6488 | bool is_volatile, |
| 6489 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6490 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6491 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6492 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6493 | : HExpression(kStaticFieldGet, |
| 6494 | field_type, |
| 6495 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 6496 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6497 | field_info_(field, |
| 6498 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6499 | field_type, |
| 6500 | is_volatile, |
| 6501 | field_idx, |
| 6502 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6503 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6504 | SetRawInputAt(0, cls); |
| 6505 | } |
| 6506 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6507 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6508 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 6509 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6510 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6511 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 6512 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6513 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6514 | } |
| 6515 | |
| 6516 | size_t ComputeHashCode() const OVERRIDE { |
| 6517 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6518 | } |
| 6519 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6520 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6521 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6522 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6523 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6524 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6525 | void SetType(DataType::Type new_type) { |
| 6526 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6527 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6528 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6529 | SetPackedField<TypeField>(new_type); |
| 6530 | } |
| 6531 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6532 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 6533 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6534 | protected: |
| 6535 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldGet); |
| 6536 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6537 | private: |
| 6538 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6539 | }; |
| 6540 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6541 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6542 | public: |
| 6543 | HStaticFieldSet(HInstruction* cls, |
| 6544 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6545 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6546 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6547 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6548 | bool is_volatile, |
| 6549 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6550 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6551 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6552 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6553 | : HTemplateInstruction(kStaticFieldSet, |
| 6554 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 6555 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6556 | field_info_(field, |
| 6557 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6558 | field_type, |
| 6559 | is_volatile, |
| 6560 | field_idx, |
| 6561 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6562 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6563 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6564 | SetRawInputAt(0, cls); |
| 6565 | SetRawInputAt(1, value); |
| 6566 | } |
| 6567 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6568 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6569 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6570 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6571 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6572 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6573 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6574 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6575 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6576 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6577 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6578 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6579 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6580 | protected: |
| 6581 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldSet); |
| 6582 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6583 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6584 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6585 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6586 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6587 | "Too many packed fields."); |
| 6588 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6589 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6590 | }; |
| 6591 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6592 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6593 | public: |
| 6594 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6595 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6596 | uint32_t field_index, |
| 6597 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6598 | : HExpression(kUnresolvedInstanceFieldGet, |
| 6599 | field_type, |
| 6600 | SideEffects::AllExceptGCDependency(), |
| 6601 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6602 | field_index_(field_index) { |
| 6603 | SetRawInputAt(0, obj); |
| 6604 | } |
| 6605 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6606 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6607 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6608 | bool CanThrow() const OVERRIDE { return true; } |
| 6609 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6610 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6611 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6612 | |
| 6613 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6614 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6615 | protected: |
| 6616 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldGet); |
| 6617 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6618 | private: |
| 6619 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6620 | }; |
| 6621 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6622 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6623 | public: |
| 6624 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6625 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6626 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6627 | uint32_t field_index, |
| 6628 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6629 | : HTemplateInstruction(kUnresolvedInstanceFieldSet, |
| 6630 | SideEffects::AllExceptGCDependency(), |
| 6631 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6632 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6633 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6634 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6635 | SetRawInputAt(0, obj); |
| 6636 | SetRawInputAt(1, value); |
| 6637 | } |
| 6638 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6639 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6640 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6641 | bool CanThrow() const OVERRIDE { return true; } |
| 6642 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6643 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6644 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6645 | |
| 6646 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6647 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6648 | protected: |
| 6649 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldSet); |
| 6650 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6651 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6652 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6653 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6654 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6655 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6656 | kFieldFieldType + kFieldFieldTypeSize; |
| 6657 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6658 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6659 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6660 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6661 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6662 | }; |
| 6663 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6664 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6665 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6666 | HUnresolvedStaticFieldGet(DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6667 | uint32_t field_index, |
| 6668 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6669 | : HExpression(kUnresolvedStaticFieldGet, |
| 6670 | field_type, |
| 6671 | SideEffects::AllExceptGCDependency(), |
| 6672 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6673 | field_index_(field_index) { |
| 6674 | } |
| 6675 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6676 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6677 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6678 | bool CanThrow() const OVERRIDE { return true; } |
| 6679 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6680 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6681 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6682 | |
| 6683 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6684 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6685 | protected: |
| 6686 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldGet); |
| 6687 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6688 | private: |
| 6689 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6690 | }; |
| 6691 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6692 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6693 | public: |
| 6694 | HUnresolvedStaticFieldSet(HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6695 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6696 | uint32_t field_index, |
| 6697 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6698 | : HTemplateInstruction(kUnresolvedStaticFieldSet, |
| 6699 | SideEffects::AllExceptGCDependency(), |
| 6700 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6701 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6702 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6703 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6704 | SetRawInputAt(0, value); |
| 6705 | } |
| 6706 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6707 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6708 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6709 | bool CanThrow() const OVERRIDE { return true; } |
| 6710 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6711 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6712 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6713 | |
| 6714 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6715 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6716 | protected: |
| 6717 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldSet); |
| 6718 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6719 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6720 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6721 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6722 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6723 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6724 | kFieldFieldType + kFieldFieldTypeSize; |
| 6725 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6726 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6727 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6728 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6729 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6730 | }; |
| 6731 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6732 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6733 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6734 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6735 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6736 | : HExpression(kLoadException, DataType::Type::kReference, SideEffects::None(), dex_pc) { |
| 6737 | } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6738 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6739 | bool CanBeNull() const OVERRIDE { return false; } |
| 6740 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6741 | DECLARE_INSTRUCTION(LoadException); |
| 6742 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6743 | protected: |
| 6744 | DEFAULT_COPY_CONSTRUCTOR(LoadException); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6745 | }; |
| 6746 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6747 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6748 | // Must not be removed because the runtime expects the TLS to get cleared. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6749 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6750 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6751 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6752 | : HTemplateInstruction(kClearException, SideEffects::AllWrites(), dex_pc) { |
| 6753 | } |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6754 | |
| 6755 | DECLARE_INSTRUCTION(ClearException); |
| 6756 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6757 | protected: |
| 6758 | DEFAULT_COPY_CONSTRUCTOR(ClearException); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6759 | }; |
| 6760 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6761 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6762 | public: |
| 6763 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6764 | : HTemplateInstruction(kThrow, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6765 | SetRawInputAt(0, exception); |
| 6766 | } |
| 6767 | |
| 6768 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6769 | |
| 6770 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6771 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6772 | bool CanThrow() const OVERRIDE { return true; } |
| 6773 | |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 6774 | bool AlwaysThrows() const OVERRIDE { return true; } |
| 6775 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6776 | DECLARE_INSTRUCTION(Throw); |
| 6777 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6778 | protected: |
| 6779 | DEFAULT_COPY_CONSTRUCTOR(Throw); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6780 | }; |
| 6781 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6782 | /** |
| 6783 | * Implementation strategies for the code generator of a HInstanceOf |
| 6784 | * or `HCheckCast`. |
| 6785 | */ |
| 6786 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6787 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6788 | kExactCheck, // Can do a single class compare. |
| 6789 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6790 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6791 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6792 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6793 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6794 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6795 | }; |
| 6796 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6797 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6798 | |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6799 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6800 | public: |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6801 | HInstanceOf(HInstruction* object, |
| 6802 | HLoadClass* target_class, |
| 6803 | TypeCheckKind check_kind, |
| 6804 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6805 | : HExpression(kInstanceOf, |
| 6806 | DataType::Type::kBool, |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6807 | SideEffectsForArchRuntimeCalls(check_kind), |
| 6808 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6809 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6810 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6811 | SetRawInputAt(0, object); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6812 | SetRawInputAt(1, target_class); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6813 | } |
| 6814 | |
| 6815 | HLoadClass* GetTargetClass() const { |
| 6816 | HInstruction* load_class = InputAt(1); |
| 6817 | DCHECK(load_class->IsLoadClass()); |
| 6818 | return load_class->AsLoadClass(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6819 | } |
| 6820 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6821 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6822 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6823 | |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6824 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6825 | return true; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6826 | } |
| 6827 | |
Vladimir Marko | eb0ebed | 2018-01-10 18:26:38 +0000 | [diff] [blame] | 6828 | bool NeedsEnvironment() const OVERRIDE { |
| 6829 | return CanCallRuntime(GetTypeCheckKind()); |
| 6830 | } |
| 6831 | |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6832 | // Used only in code generation. |
| 6833 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6834 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6835 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6836 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
| 6837 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6838 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6839 | // Mips currently does runtime calls for any other checks. |
| 6840 | return check_kind != TypeCheckKind::kExactCheck; |
| 6841 | } |
| 6842 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6843 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6844 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6845 | } |
| 6846 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6847 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6848 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6849 | protected: |
| 6850 | DEFAULT_COPY_CONSTRUCTOR(InstanceOf); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6851 | |
| 6852 | private: |
| 6853 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6854 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6855 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6856 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6857 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6858 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6859 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6860 | }; |
| 6861 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6862 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6863 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6864 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6865 | : HExpression(kBoundType, DataType::Type::kReference, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6866 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6867 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6868 | SetPackedFlag<kFlagCanBeNull>(true); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6869 | DCHECK_EQ(input->GetType(), DataType::Type::kReference); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6870 | SetRawInputAt(0, input); |
| 6871 | } |
| 6872 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6873 | bool IsClonable() const OVERRIDE { return true; } |
| 6874 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6875 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6876 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6877 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6878 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6879 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6880 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6881 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6882 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6883 | } |
| 6884 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6885 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6886 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6887 | DECLARE_INSTRUCTION(BoundType); |
| 6888 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6889 | protected: |
| 6890 | DEFAULT_COPY_CONSTRUCTOR(BoundType); |
| 6891 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6892 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6893 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6894 | // is false then CanBeNull() cannot be true). |
| 6895 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6896 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6897 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6898 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6899 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6900 | // 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] | 6901 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6902 | // It is used to bound the type in cases like: |
| 6903 | // if (x instanceof ClassX) { |
| 6904 | // // uper_bound_ will be ClassX |
| 6905 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6906 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6907 | }; |
| 6908 | |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6909 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6910 | public: |
| 6911 | HCheckCast(HInstruction* object, |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6912 | HLoadClass* target_class, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6913 | TypeCheckKind check_kind, |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6914 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6915 | : HTemplateInstruction(kCheckCast, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6916 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6917 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
| 6918 | SetRawInputAt(0, object); |
| 6919 | SetRawInputAt(1, target_class); |
| 6920 | } |
| 6921 | |
| 6922 | HLoadClass* GetTargetClass() const { |
| 6923 | HInstruction* load_class = InputAt(1); |
| 6924 | DCHECK(load_class->IsLoadClass()); |
| 6925 | return load_class->AsLoadClass(); |
| 6926 | } |
| 6927 | |
| 6928 | bool IsClonable() const OVERRIDE { return true; } |
| 6929 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6930 | |
| 6931 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6932 | return true; |
| 6933 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6934 | |
| 6935 | bool NeedsEnvironment() const OVERRIDE { |
| 6936 | // Instruction may throw a CheckCastError. |
| 6937 | return true; |
| 6938 | } |
| 6939 | |
| 6940 | bool CanThrow() const OVERRIDE { return true; } |
| 6941 | |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6942 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6943 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6944 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6945 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
| 6946 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6947 | DECLARE_INSTRUCTION(CheckCast); |
| 6948 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6949 | protected: |
| 6950 | DEFAULT_COPY_CONSTRUCTOR(CheckCast); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6951 | |
| 6952 | private: |
| 6953 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6954 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6955 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6956 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6957 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6958 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6959 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6960 | }; |
| 6961 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6962 | /** |
| 6963 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6964 | * @details We define the combined barrier types that are actually required |
| 6965 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6966 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6967 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6968 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6969 | * The current recipe is as follows: |
| 6970 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6971 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6972 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6973 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6974 | * class has final fields. |
| 6975 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6976 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6977 | */ |
| 6978 | enum MemBarrierKind { |
| 6979 | kAnyStore, |
| 6980 | kLoadAny, |
| 6981 | kStoreStore, |
| 6982 | kAnyAny, |
| 6983 | kNTStoreStore, |
| 6984 | kLastBarrierKind = kNTStoreStore |
| 6985 | }; |
| 6986 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6987 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6988 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6989 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6990 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6991 | : HTemplateInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6992 | kMemoryBarrier, |
| 6993 | SideEffects::AllWritesAndReads(), // Assume write/read on all fields/arrays. |
| 6994 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6995 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6996 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6997 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6998 | bool IsClonable() const OVERRIDE { return true; } |
| 6999 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7000 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7001 | |
| 7002 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 7003 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7004 | protected: |
| 7005 | DEFAULT_COPY_CONSTRUCTOR(MemoryBarrier); |
| 7006 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7007 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7008 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 7009 | static constexpr size_t kFieldBarrierKindSize = |
| 7010 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 7011 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 7012 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 7013 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 7014 | "Too many packed fields."); |
| 7015 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7016 | }; |
| 7017 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7018 | // A constructor fence orders all prior stores to fields that could be accessed via a final field of |
| 7019 | // the specified object(s), with respect to any subsequent store that might "publish" |
| 7020 | // (i.e. make visible) the specified object to another thread. |
| 7021 | // |
| 7022 | // JLS 17.5.1 "Semantics of final fields" states that a freeze action happens |
| 7023 | // for all final fields (that were set) at the end of the invoked constructor. |
| 7024 | // |
| 7025 | // The constructor fence models the freeze actions for the final fields of an object |
| 7026 | // being constructed (semantically at the end of the constructor). Constructor fences |
| 7027 | // have a per-object affinity; two separate objects being constructed get two separate |
| 7028 | // constructor fences. |
| 7029 | // |
| 7030 | // (Note: that if calling a super-constructor or forwarding to another constructor, |
| 7031 | // the freezes would happen at the end of *that* constructor being invoked). |
| 7032 | // |
| 7033 | // The memory model guarantees that when the object being constructed is "published" after |
| 7034 | // constructor completion (i.e. escapes the current thread via a store), then any final field |
| 7035 | // writes must be observable on other threads (once they observe that publication). |
| 7036 | // |
| 7037 | // Further, anything written before the freeze, and read by dereferencing through the final field, |
| 7038 | // must also be visible (so final object field could itself have an object with non-final fields; |
| 7039 | // yet the freeze must also extend to them). |
| 7040 | // |
| 7041 | // Constructor example: |
| 7042 | // |
| 7043 | // class HasFinal { |
| 7044 | // final int field; Optimizing IR for <init>()V: |
| 7045 | // HasFinal() { |
| 7046 | // field = 123; HInstanceFieldSet(this, HasFinal.field, 123) |
| 7047 | // // freeze(this.field); HConstructorFence(this) |
| 7048 | // } HReturn |
| 7049 | // } |
| 7050 | // |
| 7051 | // HConstructorFence can serve double duty as a fence for new-instance/new-array allocations of |
| 7052 | // already-initialized classes; in that case the allocation must act as a "default-initializer" |
| 7053 | // of the object which effectively writes the class pointer "final field". |
| 7054 | // |
| 7055 | // For example, we can model default-initialiation as roughly the equivalent of the following: |
| 7056 | // |
| 7057 | // class Object { |
| 7058 | // private final Class header; |
| 7059 | // } |
| 7060 | // |
| 7061 | // Java code: Optimizing IR: |
| 7062 | // |
| 7063 | // T new_instance<T>() { |
| 7064 | // Object obj = allocate_memory(T.class.size); obj = HInvoke(art_quick_alloc_object, T) |
| 7065 | // obj.header = T.class; // header write is done by above call. |
| 7066 | // // freeze(obj.header) HConstructorFence(obj) |
| 7067 | // return (T)obj; |
| 7068 | // } |
| 7069 | // |
| 7070 | // See also: |
| 7071 | // * CompilerDriver::RequiresConstructorBarrier |
| 7072 | // * QuasiAtomic::ThreadFenceForConstructor |
| 7073 | // |
| 7074 | class HConstructorFence FINAL : public HVariableInputSizeInstruction { |
| 7075 | // A fence has variable inputs because the inputs can be removed |
| 7076 | // after prepare_for_register_allocation phase. |
| 7077 | // (TODO: In the future a fence could freeze multiple objects |
| 7078 | // after merging two fences together.) |
| 7079 | public: |
| 7080 | // `fence_object` is the reference that needs to be protected for correct publication. |
| 7081 | // |
| 7082 | // It makes sense in the following situations: |
| 7083 | // * <init> constructors, it's the "this" parameter (i.e. HParameterValue, s.t. IsThis() == true). |
| 7084 | // * new-instance-like instructions, it's the return value (i.e. HNewInstance). |
| 7085 | // |
| 7086 | // After construction the `fence_object` becomes the 0th input. |
| 7087 | // This is not an input in a real sense, but just a convenient place to stash the information |
| 7088 | // about the associated object. |
| 7089 | HConstructorFence(HInstruction* fence_object, |
| 7090 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7091 | ArenaAllocator* allocator) |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7092 | // We strongly suspect there is not a more accurate way to describe the fine-grained reordering |
| 7093 | // constraints described in the class header. We claim that these SideEffects constraints |
| 7094 | // enforce a superset of the real constraints. |
| 7095 | // |
| 7096 | // The ordering described above is conservatively modeled with SideEffects as follows: |
| 7097 | // |
| 7098 | // * To prevent reordering of the publication stores: |
| 7099 | // ----> "Reads of objects" is the initial SideEffect. |
| 7100 | // * For every primitive final field store in the constructor: |
| 7101 | // ----> Union that field's type as a read (e.g. "Read of T") into the SideEffect. |
| 7102 | // * If there are any stores to reference final fields in the constructor: |
| 7103 | // ----> Use a more conservative "AllReads" SideEffect because any stores to any references |
| 7104 | // that are reachable from `fence_object` also need to be prevented for reordering |
| 7105 | // (and we do not want to do alias analysis to figure out what those stores are). |
| 7106 | // |
| 7107 | // In the implementation, this initially starts out as an "all reads" side effect; this is an |
| 7108 | // even more conservative approach than the one described above, and prevents all of the |
| 7109 | // above reordering without analyzing any of the instructions in the constructor. |
| 7110 | // |
| 7111 | // If in a later phase we discover that there are no writes to reference final fields, |
| 7112 | // 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] | 7113 | : HVariableInputSizeInstruction(kConstructorFence, |
| 7114 | SideEffects::AllReads(), |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7115 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7116 | allocator, |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7117 | /* number_of_inputs */ 1, |
| 7118 | kArenaAllocConstructorFenceInputs) { |
| 7119 | DCHECK(fence_object != nullptr); |
| 7120 | SetRawInputAt(0, fence_object); |
| 7121 | } |
| 7122 | |
| 7123 | // The object associated with this constructor fence. |
| 7124 | // |
| 7125 | // (Note: This will be null after the prepare_for_register_allocation phase, |
| 7126 | // as all constructor fence inputs are removed there). |
| 7127 | HInstruction* GetFenceObject() const { |
| 7128 | return InputAt(0); |
| 7129 | } |
| 7130 | |
| 7131 | // Find all the HConstructorFence uses (`fence_use`) for `this` and: |
| 7132 | // - Delete `fence_use` from `this`'s use list. |
| 7133 | // - Delete `this` from `fence_use`'s inputs list. |
| 7134 | // - If the `fence_use` is dead, remove it from the graph. |
| 7135 | // |
| 7136 | // A fence is considered dead once it no longer has any uses |
| 7137 | // and all of the inputs are dead. |
| 7138 | // |
| 7139 | // This must *not* be called during/after prepare_for_register_allocation, |
| 7140 | // because that removes all the inputs to the fences but the fence is actually |
| 7141 | // still considered live. |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7142 | // |
| 7143 | // Returns how many HConstructorFence instructions were removed from graph. |
| 7144 | static size_t RemoveConstructorFences(HInstruction* instruction); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7145 | |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7146 | // Combine all inputs of `this` and `other` instruction and remove |
| 7147 | // `other` from the graph. |
| 7148 | // |
| 7149 | // Inputs are unique after the merge. |
| 7150 | // |
| 7151 | // Requirement: `this` must not be the same as `other. |
| 7152 | void Merge(HConstructorFence* other); |
| 7153 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7154 | // Check if this constructor fence is protecting |
| 7155 | // an HNewInstance or HNewArray that is also the immediate |
| 7156 | // predecessor of `this`. |
| 7157 | // |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7158 | // If `ignore_inputs` is true, then the immediate predecessor doesn't need |
| 7159 | // to be one of the inputs of `this`. |
| 7160 | // |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7161 | // Returns the associated HNewArray or HNewInstance, |
| 7162 | // or null otherwise. |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7163 | HInstruction* GetAssociatedAllocation(bool ignore_inputs = false); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7164 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7165 | DECLARE_INSTRUCTION(ConstructorFence); |
| 7166 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7167 | protected: |
| 7168 | DEFAULT_COPY_CONSTRUCTOR(ConstructorFence); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7169 | }; |
| 7170 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 7171 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7172 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7173 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7174 | kEnter, |
| 7175 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7176 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7177 | }; |
| 7178 | |
| 7179 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7180 | : HTemplateInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7181 | kMonitorOperation, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7182 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 7183 | dex_pc) { |
| 7184 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7185 | SetRawInputAt(0, object); |
| 7186 | } |
| 7187 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7188 | // Instruction may go into runtime, so we need an environment. |
| 7189 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 7190 | |
| 7191 | bool CanThrow() const OVERRIDE { |
| 7192 | // Verifier guarantees that monitor-exit cannot throw. |
| 7193 | // This is important because it allows the HGraphBuilder to remove |
| 7194 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 7195 | return IsEnter(); |
| 7196 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7197 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7198 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 7199 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7200 | |
| 7201 | DECLARE_INSTRUCTION(MonitorOperation); |
| 7202 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7203 | protected: |
| 7204 | DEFAULT_COPY_CONSTRUCTOR(MonitorOperation); |
| 7205 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7206 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7207 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 7208 | static constexpr size_t kFieldOperationKindSize = |
| 7209 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 7210 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 7211 | kFieldOperationKind + kFieldOperationKindSize; |
| 7212 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7213 | "Too many packed fields."); |
| 7214 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7215 | }; |
| 7216 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 7217 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7218 | public: |
| 7219 | HSelect(HInstruction* condition, |
| 7220 | HInstruction* true_value, |
| 7221 | HInstruction* false_value, |
| 7222 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7223 | : HExpression(kSelect, HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7224 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 7225 | |
| 7226 | // First input must be `true_value` or `false_value` to allow codegens to |
| 7227 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 7228 | // that architectures which implement HSelect as a conditional move also |
| 7229 | // will not need to invert the condition. |
| 7230 | SetRawInputAt(0, false_value); |
| 7231 | SetRawInputAt(1, true_value); |
| 7232 | SetRawInputAt(2, condition); |
| 7233 | } |
| 7234 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7235 | bool IsClonable() const OVERRIDE { return true; } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7236 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 7237 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 7238 | HInstruction* GetCondition() const { return InputAt(2); } |
| 7239 | |
| 7240 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7241 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 7242 | return true; |
| 7243 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7244 | |
| 7245 | bool CanBeNull() const OVERRIDE { |
| 7246 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 7247 | } |
| 7248 | |
| 7249 | DECLARE_INSTRUCTION(Select); |
| 7250 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7251 | protected: |
| 7252 | DEFAULT_COPY_CONSTRUCTOR(Select); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7253 | }; |
| 7254 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 7255 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7256 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7257 | MoveOperands(Location source, |
| 7258 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7259 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7260 | HInstruction* instruction) |
| 7261 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7262 | |
| 7263 | Location GetSource() const { return source_; } |
| 7264 | Location GetDestination() const { return destination_; } |
| 7265 | |
| 7266 | void SetSource(Location value) { source_ = value; } |
| 7267 | void SetDestination(Location value) { destination_ = value; } |
| 7268 | |
| 7269 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 7270 | // destination (but not the source). |
| 7271 | Location MarkPending() { |
| 7272 | DCHECK(!IsPending()); |
| 7273 | Location dest = destination_; |
| 7274 | destination_ = Location::NoLocation(); |
| 7275 | return dest; |
| 7276 | } |
| 7277 | |
| 7278 | void ClearPending(Location dest) { |
| 7279 | DCHECK(IsPending()); |
| 7280 | destination_ = dest; |
| 7281 | } |
| 7282 | |
| 7283 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7284 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 7285 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7286 | } |
| 7287 | |
| 7288 | // True if this blocks a move from the given location. |
| 7289 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 7290 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7291 | } |
| 7292 | |
| 7293 | // A move is redundant if it's been eliminated, if its source and |
| 7294 | // destination are the same, or if its destination is unneeded. |
| 7295 | bool IsRedundant() const { |
| 7296 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 7297 | } |
| 7298 | |
| 7299 | // We clear both operands to indicate move that's been eliminated. |
| 7300 | void Eliminate() { |
| 7301 | source_ = destination_ = Location::NoLocation(); |
| 7302 | } |
| 7303 | |
| 7304 | bool IsEliminated() const { |
| 7305 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 7306 | return source_.IsInvalid(); |
| 7307 | } |
| 7308 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7309 | DataType::Type GetType() const { return type_; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7310 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7311 | bool Is64BitMove() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7312 | return DataType::Is64BitType(type_); |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7313 | } |
| 7314 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7315 | HInstruction* GetInstruction() const { return instruction_; } |
| 7316 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7317 | private: |
| 7318 | Location source_; |
| 7319 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7320 | // The type this move is for. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7321 | DataType::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7322 | // The instruction this move is assocatied with. Null when this move is |
| 7323 | // for moving an input in the expected locations of user (including a phi user). |
| 7324 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 7325 | // in the same parallel move. |
| 7326 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7327 | }; |
| 7328 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7329 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 7330 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7331 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 7332 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 7333 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7334 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7335 | explicit HParallelMove(ArenaAllocator* allocator, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7336 | : HTemplateInstruction(kParallelMove, SideEffects::None(), dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7337 | moves_(allocator->Adapter(kArenaAllocMoveOperands)) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7338 | moves_.reserve(kDefaultNumberOfMoves); |
| 7339 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7340 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7341 | void AddMove(Location source, |
| 7342 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7343 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7344 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 7345 | DCHECK(source.IsValid()); |
| 7346 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7347 | if (kIsDebugBuild) { |
| 7348 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7349 | for (const MoveOperands& move : moves_) { |
| 7350 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7351 | // Special case the situation where the move is for the spill slot |
| 7352 | // of the instruction. |
| 7353 | if ((GetPrevious() == instruction) |
| 7354 | || ((GetPrevious() == nullptr) |
| 7355 | && instruction->IsPhi() |
| 7356 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7357 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7358 | << "Doing parallel moves for the same instruction."; |
| 7359 | } else { |
| 7360 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 7361 | } |
| 7362 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 7363 | } |
| 7364 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7365 | for (const MoveOperands& move : moves_) { |
| 7366 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7367 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7368 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7369 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7370 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7371 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7372 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7373 | } |
| 7374 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7375 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7376 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7377 | } |
| 7378 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7379 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7380 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 7381 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7382 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7383 | protected: |
| 7384 | DEFAULT_COPY_CONSTRUCTOR(ParallelMove); |
| 7385 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7386 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7387 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7388 | }; |
| 7389 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7390 | // This instruction computes an intermediate address pointing in the 'middle' of an object. The |
| 7391 | // result pointer cannot be handled by GC, so extra care is taken to make sure that this value is |
| 7392 | // never used across anything that can trigger GC. |
| 7393 | // The result of this instruction is not a pointer in the sense of `DataType::Type::kreference`. |
| 7394 | // So we represent it by the type `DataType::Type::kInt`. |
| 7395 | class HIntermediateAddress FINAL : public HExpression<2> { |
| 7396 | public: |
| 7397 | HIntermediateAddress(HInstruction* base_address, HInstruction* offset, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7398 | : HExpression(kIntermediateAddress, |
| 7399 | DataType::Type::kInt32, |
| 7400 | SideEffects::DependsOnGC(), |
| 7401 | dex_pc) { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7402 | DCHECK_EQ(DataType::Size(DataType::Type::kInt32), |
| 7403 | DataType::Size(DataType::Type::kReference)) |
| 7404 | << "kPrimInt and kPrimNot have different sizes."; |
| 7405 | SetRawInputAt(0, base_address); |
| 7406 | SetRawInputAt(1, offset); |
| 7407 | } |
| 7408 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7409 | bool IsClonable() const OVERRIDE { return true; } |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7410 | bool CanBeMoved() const OVERRIDE { return true; } |
| 7411 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 7412 | return true; |
| 7413 | } |
| 7414 | bool IsActualObject() const OVERRIDE { return false; } |
| 7415 | |
| 7416 | HInstruction* GetBaseAddress() const { return InputAt(0); } |
| 7417 | HInstruction* GetOffset() const { return InputAt(1); } |
| 7418 | |
| 7419 | DECLARE_INSTRUCTION(IntermediateAddress); |
| 7420 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7421 | protected: |
| 7422 | DEFAULT_COPY_CONSTRUCTOR(IntermediateAddress); |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7423 | }; |
| 7424 | |
| 7425 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7426 | } // namespace art |
| 7427 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 7428 | #include "nodes_vector.h" |
| 7429 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7430 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 7431 | #include "nodes_shared.h" |
| 7432 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7433 | #ifdef ART_ENABLE_CODEGEN_mips |
| 7434 | #include "nodes_mips.h" |
| 7435 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7436 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 7437 | #include "nodes_x86.h" |
| 7438 | #endif |
| 7439 | |
| 7440 | namespace art { |
| 7441 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7442 | class OptimizingCompilerStats; |
| 7443 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7444 | class HGraphVisitor : public ValueObject { |
| 7445 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7446 | explicit HGraphVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7447 | : stats_(stats), |
| 7448 | graph_(graph) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 7449 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7450 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7451 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7452 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 7453 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7454 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7455 | void VisitInsertionOrder(); |
| 7456 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7457 | // Visit the graph following dominator tree reverse post-order. |
| 7458 | void VisitReversePostOrder(); |
| 7459 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 7460 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7461 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7462 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7463 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7464 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 7465 | |
| 7466 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7467 | |
| 7468 | #undef DECLARE_VISIT_INSTRUCTION |
| 7469 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7470 | protected: |
| 7471 | OptimizingCompilerStats* stats_; |
| 7472 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7473 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 7474 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7475 | |
| 7476 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 7477 | }; |
| 7478 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7479 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 7480 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7481 | explicit HGraphDelegateVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7482 | : HGraphVisitor(graph, stats) {} |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7483 | virtual ~HGraphDelegateVisitor() {} |
| 7484 | |
| 7485 | // Visit functions that delegate to to super class. |
| 7486 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 7487 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7488 | |
| 7489 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7490 | |
| 7491 | #undef DECLARE_VISIT_INSTRUCTION |
| 7492 | |
| 7493 | private: |
| 7494 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 7495 | }; |
| 7496 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7497 | // Create a clone of the instruction, insert it into the graph; replace the old one with a new |
| 7498 | // and remove the old instruction. |
| 7499 | HInstruction* ReplaceInstrOrPhiByClone(HInstruction* instr); |
| 7500 | |
| 7501 | // Create a clone for each clonable instructions/phis and replace the original with the clone. |
| 7502 | // |
| 7503 | // Used for testing individual instruction cloner. |
| 7504 | class CloneAndReplaceInstructionVisitor : public HGraphDelegateVisitor { |
| 7505 | public: |
| 7506 | explicit CloneAndReplaceInstructionVisitor(HGraph* graph) |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7507 | : HGraphDelegateVisitor(graph), instr_replaced_by_clones_count_(0) {} |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7508 | |
| 7509 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 7510 | if (instruction->IsClonable()) { |
| 7511 | ReplaceInstrOrPhiByClone(instruction); |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7512 | instr_replaced_by_clones_count_++; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7513 | } |
| 7514 | } |
| 7515 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7516 | size_t GetInstrReplacedByClonesCount() const { return instr_replaced_by_clones_count_; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7517 | |
| 7518 | private: |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7519 | size_t instr_replaced_by_clones_count_; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7520 | |
| 7521 | DISALLOW_COPY_AND_ASSIGN(CloneAndReplaceInstructionVisitor); |
| 7522 | }; |
| 7523 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7524 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7525 | // of an inner loop. The order in which the blocks are iterated is on their |
| 7526 | // block id. |
| 7527 | class HBlocksInLoopIterator : public ValueObject { |
| 7528 | public: |
| 7529 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 7530 | : blocks_in_loop_(info.GetBlocks()), |
| 7531 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 7532 | index_(0) { |
| 7533 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 7534 | Advance(); |
| 7535 | } |
| 7536 | } |
| 7537 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7538 | bool Done() const { return index_ == blocks_.size(); } |
| 7539 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7540 | void Advance() { |
| 7541 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7542 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7543 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 7544 | break; |
| 7545 | } |
| 7546 | } |
| 7547 | } |
| 7548 | |
| 7549 | private: |
| 7550 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7551 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7552 | size_t index_; |
| 7553 | |
| 7554 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 7555 | }; |
| 7556 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7557 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7558 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 7559 | // post order. |
| 7560 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 7561 | public: |
| 7562 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 7563 | : blocks_in_loop_(info.GetBlocks()), |
| 7564 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 7565 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7566 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7567 | Advance(); |
| 7568 | } |
| 7569 | } |
| 7570 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7571 | bool Done() const { return index_ == blocks_.size(); } |
| 7572 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7573 | void Advance() { |
| 7574 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7575 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 7576 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7577 | break; |
| 7578 | } |
| 7579 | } |
| 7580 | } |
| 7581 | |
| 7582 | private: |
| 7583 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7584 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7585 | size_t index_; |
| 7586 | |
| 7587 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 7588 | }; |
| 7589 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7590 | // Returns int64_t value of a properly typed constant. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7591 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7592 | if (constant->IsIntConstant()) { |
| 7593 | return constant->AsIntConstant()->GetValue(); |
| 7594 | } else if (constant->IsLongConstant()) { |
| 7595 | return constant->AsLongConstant()->GetValue(); |
| 7596 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 7597 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7598 | return 0; |
| 7599 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7600 | } |
| 7601 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7602 | // Returns true iff instruction is an integral constant (and sets value on success). |
| 7603 | inline bool IsInt64AndGet(HInstruction* instruction, /*out*/ int64_t* value) { |
| 7604 | if (instruction->IsIntConstant()) { |
| 7605 | *value = instruction->AsIntConstant()->GetValue(); |
| 7606 | return true; |
| 7607 | } else if (instruction->IsLongConstant()) { |
| 7608 | *value = instruction->AsLongConstant()->GetValue(); |
| 7609 | return true; |
| 7610 | } else if (instruction->IsNullConstant()) { |
| 7611 | *value = 0; |
| 7612 | return true; |
| 7613 | } |
| 7614 | return false; |
| 7615 | } |
| 7616 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 7617 | // Returns true iff instruction is the given integral constant. |
| 7618 | inline bool IsInt64Value(HInstruction* instruction, int64_t value) { |
| 7619 | int64_t val = 0; |
| 7620 | return IsInt64AndGet(instruction, &val) && val == value; |
| 7621 | } |
| 7622 | |
| 7623 | // Returns true iff instruction is a zero bit pattern. |
| 7624 | inline bool IsZeroBitPattern(HInstruction* instruction) { |
| 7625 | return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern(); |
| 7626 | } |
| 7627 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7628 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 7629 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 7630 | inline const H##type* HInstruction::As##type() const { \ |
| 7631 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 7632 | } \ |
| 7633 | inline H##type* HInstruction::As##type() { \ |
| 7634 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 7635 | } |
| 7636 | |
| 7637 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7638 | #undef INSTRUCTION_TYPE_CHECK |
| 7639 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 7640 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 7641 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 7642 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 7643 | size_t number_of_new_blocks, |
| 7644 | size_t after) { |
| 7645 | DCHECK_LT(after, blocks->size()); |
| 7646 | size_t old_size = blocks->size(); |
| 7647 | size_t new_size = old_size + number_of_new_blocks; |
| 7648 | blocks->resize(new_size); |
| 7649 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 7650 | } |
| 7651 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7652 | /* |
| 7653 | * Hunt "under the hood" of array lengths (leading to array references), |
| 7654 | * null checks (also leading to array references), and new arrays |
| 7655 | * (leading to the actual length). This makes it more likely related |
| 7656 | * instructions become actually comparable. |
| 7657 | */ |
| 7658 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 7659 | while (instruction->IsArrayLength() || |
| 7660 | instruction->IsNullCheck() || |
| 7661 | instruction->IsNewArray()) { |
| 7662 | instruction = instruction->IsNewArray() |
| 7663 | ? instruction->AsNewArray()->GetLength() |
| 7664 | : instruction->InputAt(0); |
| 7665 | } |
| 7666 | return instruction; |
| 7667 | } |
| 7668 | |
Artem Serov | 21c7e6f | 2017-07-27 16:04:42 +0100 | [diff] [blame] | 7669 | void RemoveEnvironmentUses(HInstruction* instruction); |
| 7670 | bool HasEnvironmentUsedByOthers(HInstruction* instruction); |
| 7671 | void ResetEnvironmentInputRecords(HInstruction* instruction); |
| 7672 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7673 | } // namespace art |
| 7674 | |
| 7675 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |