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" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 35 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 36 | #include "handle.h" |
| 37 | #include "handle_scope.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 38 | #include "intrinsics_enum.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 39 | #include "invoke_type.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 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 829 | // Returns whether this loop information contains `block`. |
| 830 | // Note that this loop information *must* be populated before entering this function. |
| 831 | bool Contains(const HBasicBlock& block) const; |
| 832 | |
| 833 | // Returns whether this loop information is an inner loop of `other`. |
| 834 | // Note that `other` *must* be populated before entering this function. |
| 835 | bool IsIn(const HLoopInformation& other) const; |
| 836 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 837 | // Returns true if instruction is not defined within this loop. |
| 838 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 839 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 840 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 841 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 842 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 843 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 844 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 845 | void ClearAllBlocks() { |
| 846 | blocks_.ClearAllBits(); |
| 847 | } |
| 848 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 849 | bool HasBackEdgeNotDominatedByHeader() const; |
| 850 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 851 | bool IsPopulated() const { |
| 852 | return blocks_.GetHighestBitSet() != -1; |
| 853 | } |
| 854 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 855 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 856 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 857 | bool HasExitEdge() const; |
| 858 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 859 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 860 | // Internal recursive implementation of `Populate`. |
| 861 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 862 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 863 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 864 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 865 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 866 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 867 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 868 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 869 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 870 | |
| 871 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 872 | }; |
| 873 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 874 | // Stores try/catch information for basic blocks. |
| 875 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 876 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 877 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 878 | public: |
| 879 | // Try block information constructor. |
| 880 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 881 | : try_entry_(&try_entry), |
| 882 | catch_dex_file_(nullptr), |
| 883 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 884 | DCHECK(try_entry_ != nullptr); |
| 885 | } |
| 886 | |
| 887 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 888 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 889 | : try_entry_(nullptr), |
| 890 | catch_dex_file_(&dex_file), |
| 891 | catch_type_index_(catch_type_index) {} |
| 892 | |
| 893 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 894 | |
| 895 | const HTryBoundary& GetTryEntry() const { |
| 896 | DCHECK(IsTryBlock()); |
| 897 | return *try_entry_; |
| 898 | } |
| 899 | |
| 900 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 901 | |
| 902 | bool IsCatchAllTypeIndex() const { |
| 903 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 904 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 905 | } |
| 906 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 907 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 908 | DCHECK(IsCatchBlock()); |
| 909 | return catch_type_index_; |
| 910 | } |
| 911 | |
| 912 | const DexFile& GetCatchDexFile() const { |
| 913 | DCHECK(IsCatchBlock()); |
| 914 | return *catch_dex_file_; |
| 915 | } |
| 916 | |
| 917 | private: |
| 918 | // One of possibly several TryBoundary instructions entering the block's try. |
| 919 | // Only set for try blocks. |
| 920 | const HTryBoundary* try_entry_; |
| 921 | |
| 922 | // Exception type information. Only set for catch blocks. |
| 923 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 924 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 925 | }; |
| 926 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 927 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 928 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 929 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 930 | // A block in a method. Contains the list of instructions represented |
| 931 | // as a double linked list. Each block knows its predecessors and |
| 932 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 933 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 934 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 935 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 936 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 937 | : graph_(graph), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 938 | predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), |
| 939 | successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 940 | loop_information_(nullptr), |
| 941 | dominator_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 942 | dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 943 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 944 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 945 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 946 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 947 | try_catch_information_(nullptr) { |
| 948 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 949 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 950 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 951 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 952 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 953 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 954 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 957 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 958 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 959 | } |
| 960 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 961 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 962 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 963 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 964 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 965 | return ContainsElement(successors_, block, start_from); |
| 966 | } |
| 967 | |
| 968 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 969 | return dominated_blocks_; |
| 970 | } |
| 971 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 972 | bool IsEntryBlock() const { |
| 973 | return graph_->GetEntryBlock() == this; |
| 974 | } |
| 975 | |
| 976 | bool IsExitBlock() const { |
| 977 | return graph_->GetExitBlock() == this; |
| 978 | } |
| 979 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 980 | bool IsSingleGoto() const; |
Mads Ager | 16e5289 | 2017-07-14 13:11:37 +0200 | [diff] [blame] | 981 | bool IsSingleReturn() const; |
Mingyao Yang | 46721ef | 2017-10-05 14:45:17 -0700 | [diff] [blame] | 982 | bool IsSingleReturnOrReturnVoidAllowingPhis() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 983 | bool IsSingleTryBoundary() const; |
| 984 | |
| 985 | // Returns true if this block emits nothing but a jump. |
| 986 | bool IsSingleJump() const { |
| 987 | HLoopInformation* loop_info = GetLoopInformation(); |
| 988 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 989 | // Back edges generate a suspend check. |
| 990 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 991 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 992 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 993 | void AddBackEdge(HBasicBlock* back_edge) { |
| 994 | if (loop_information_ == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 995 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 996 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 997 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 998 | loop_information_->AddBackEdge(back_edge); |
| 999 | } |
| 1000 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1001 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1002 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1003 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1004 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1005 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1006 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1007 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1008 | HBasicBlock* GetDominator() const { return dominator_; } |
| 1009 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1010 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 1011 | |
| 1012 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 1013 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 1014 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1015 | |
| 1016 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1017 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 1018 | } |
| 1019 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1020 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1021 | |
| 1022 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1023 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1026 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1027 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1028 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1029 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1030 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1031 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1032 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1033 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1034 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1035 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1036 | successors_.push_back(block); |
| 1037 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1040 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1041 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1042 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1043 | new_block->predecessors_.push_back(this); |
| 1044 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1047 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1048 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1049 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1050 | new_block->successors_.push_back(this); |
| 1051 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1054 | // Insert `this` between `predecessor` and `successor. This method |
| 1055 | // preserves the indicies, and will update the first edge found between |
| 1056 | // `predecessor` and `successor`. |
| 1057 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1058 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1059 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1060 | successor->predecessors_[predecessor_index] = this; |
| 1061 | predecessor->successors_[successor_index] = this; |
| 1062 | successors_.push_back(successor); |
| 1063 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1066 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1067 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1070 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1071 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1074 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1075 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1079 | predecessors_.push_back(block); |
| 1080 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1081 | } |
| 1082 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1083 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1084 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1085 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1088 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1089 | DCHECK_EQ(successors_.size(), 2u); |
| 1090 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1091 | } |
| 1092 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1093 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1094 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1095 | } |
| 1096 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1097 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1098 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1099 | } |
| 1100 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1101 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1102 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1103 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1107 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1108 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1112 | // predecessors is at index `idx`. |
| 1113 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1114 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1115 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1116 | } |
| 1117 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1118 | // Create a new block between this block and its predecessors. The new block |
| 1119 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1120 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1121 | // loop and try/catch information are not updated. |
| 1122 | HBasicBlock* CreateImmediateDominator(); |
| 1123 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1124 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1125 | // created, latter block. Note that this method will add the block to the |
| 1126 | // graph, create a Goto at the end of the former block and will create an edge |
| 1127 | // 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] | 1128 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1129 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1130 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1131 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1132 | // created block. Note that this method just updates raw block information, |
| 1133 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1134 | // update the graph, reverse post order, loop information, nor make sure the |
| 1135 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1136 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1137 | |
| 1138 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1139 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1140 | |
| 1141 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1142 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1143 | // that this method does not update the graph, reverse post order, loop |
| 1144 | // information, nor make sure the blocks are consistent (for example ending |
| 1145 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1146 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1147 | |
| 1148 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1149 | // of `this` are moved to `other`. |
| 1150 | // Note that this method does not update the graph, reverse post order, loop |
| 1151 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1152 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1153 | void ReplaceWith(HBasicBlock* other); |
| 1154 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1155 | // Merges the instructions of `other` at the end of `this`. |
| 1156 | void MergeInstructionsWith(HBasicBlock* other); |
| 1157 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1158 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1159 | // order, links to predecessors, successors, dominators and deletes the block |
| 1160 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1161 | // predecessor of `other` and vice versa. |
| 1162 | void MergeWith(HBasicBlock* other); |
| 1163 | |
| 1164 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1165 | // removes it from all loops it is included in and eventually from the graph. |
| 1166 | // The block must not dominate any other block. Predecessors and successors |
| 1167 | // are safely updated. |
| 1168 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1169 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1170 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1171 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1172 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1173 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1174 | // Replace phi `initial` with `replacement` within this block. |
| 1175 | void ReplaceAndRemovePhiWith(HPhi* initial, HPhi* replacement); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1176 | // Replace instruction `initial` with `replacement` within this block. |
| 1177 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1178 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1179 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1180 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1181 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1182 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1183 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1184 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1185 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1186 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1187 | |
| 1188 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1189 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1190 | } |
| 1191 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1192 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1193 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1194 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1195 | } |
| 1196 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1197 | bool IsFirstPredecessorBackEdge() const { |
| 1198 | DCHECK(IsLoopHeader()); |
| 1199 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1200 | } |
| 1201 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1202 | HLoopInformation* GetLoopInformation() const { |
| 1203 | return loop_information_; |
| 1204 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1205 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1206 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1207 | // 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] | 1208 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1209 | void SetInLoop(HLoopInformation* info) { |
| 1210 | if (IsLoopHeader()) { |
| 1211 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1212 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1213 | loop_information_ = info; |
| 1214 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1215 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1216 | // Note that a non loop header having a loop information means this loop information |
| 1217 | // has already been populated |
| 1218 | loop_information_ = info; |
| 1219 | } else { |
| 1220 | // Block is part of an inner loop. Do not update the loop information. |
| 1221 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1222 | // at this point, because this method is being called while populating `info`. |
| 1223 | } |
| 1224 | } |
| 1225 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1226 | // Raw update of the loop information. |
| 1227 | void SetLoopInformation(HLoopInformation* info) { |
| 1228 | loop_information_ = info; |
| 1229 | } |
| 1230 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1231 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1232 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1233 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1234 | |
| 1235 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1236 | try_catch_information_ = try_catch_information; |
| 1237 | } |
| 1238 | |
| 1239 | bool IsTryBlock() const { |
| 1240 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1241 | } |
| 1242 | |
| 1243 | bool IsCatchBlock() const { |
| 1244 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1245 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1246 | |
| 1247 | // Returns the try entry that this block's successors should have. They will |
| 1248 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1249 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1250 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1251 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1252 | bool HasThrowingInstructions() const; |
| 1253 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1254 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1255 | bool Dominates(HBasicBlock* block) const; |
| 1256 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1257 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1258 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1259 | |
| 1260 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1261 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1262 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1263 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1264 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1265 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1266 | bool HasSinglePhi() const; |
| 1267 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1268 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1269 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1270 | ArenaVector<HBasicBlock*> predecessors_; |
| 1271 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1272 | HInstructionList instructions_; |
| 1273 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1274 | HLoopInformation* loop_information_; |
| 1275 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1276 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1277 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1278 | // The dex program counter of the first instruction of this block. |
| 1279 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1280 | size_t lifetime_start_; |
| 1281 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1282 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1283 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1284 | friend class HGraph; |
| 1285 | friend class HInstruction; |
| 1286 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1287 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1288 | }; |
| 1289 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1290 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1291 | // from the innermost to the outermost. |
| 1292 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1293 | public: |
| 1294 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1295 | : current_(block.GetLoopInformation()) {} |
| 1296 | |
| 1297 | bool Done() const { return current_ == nullptr; } |
| 1298 | |
| 1299 | void Advance() { |
| 1300 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1301 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | HLoopInformation* Current() const { |
| 1305 | DCHECK(!Done()); |
| 1306 | return current_; |
| 1307 | } |
| 1308 | |
| 1309 | private: |
| 1310 | HLoopInformation* current_; |
| 1311 | |
| 1312 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1313 | }; |
| 1314 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1315 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1316 | M(Above, Condition) \ |
| 1317 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1318 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1319 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1320 | M(ArrayGet, Instruction) \ |
| 1321 | M(ArrayLength, Instruction) \ |
| 1322 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1323 | M(Below, Condition) \ |
| 1324 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1325 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1326 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1327 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1328 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1329 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1330 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1331 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1332 | M(Compare, BinaryOperation) \ |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1333 | M(ConstructorFence, Instruction) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1334 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1335 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1336 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1337 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1338 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1339 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1340 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1341 | M(Exit, Instruction) \ |
| 1342 | M(FloatConstant, Constant) \ |
| 1343 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1344 | M(GreaterThan, Condition) \ |
| 1345 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1346 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1347 | M(InstanceFieldGet, Instruction) \ |
| 1348 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1349 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1350 | M(IntConstant, Constant) \ |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 1351 | M(IntermediateAddress, Instruction) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1352 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1353 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1354 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1355 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1356 | M(InvokePolymorphic, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1357 | M(LessThan, Condition) \ |
| 1358 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1359 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1360 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1361 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1362 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1363 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1364 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1365 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1366 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1367 | M(Neg, UnaryOperation) \ |
| 1368 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1369 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1370 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1371 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1372 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1373 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1374 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1375 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1376 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1377 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1378 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1379 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1380 | M(Return, Instruction) \ |
| 1381 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1382 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1383 | M(Shl, BinaryOperation) \ |
| 1384 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1385 | M(StaticFieldGet, Instruction) \ |
| 1386 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1387 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1388 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1389 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1390 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1391 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1392 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1393 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1394 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1395 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1396 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1397 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1398 | M(Xor, BinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1399 | M(VecReplicateScalar, VecUnaryOperation) \ |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1400 | M(VecExtractScalar, VecUnaryOperation) \ |
| 1401 | M(VecReduce, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1402 | M(VecCnv, VecUnaryOperation) \ |
| 1403 | M(VecNeg, VecUnaryOperation) \ |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1404 | M(VecAbs, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1405 | M(VecNot, VecUnaryOperation) \ |
| 1406 | M(VecAdd, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1407 | M(VecHalvingAdd, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1408 | M(VecSub, VecBinaryOperation) \ |
| 1409 | M(VecMul, VecBinaryOperation) \ |
| 1410 | M(VecDiv, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1411 | M(VecMin, VecBinaryOperation) \ |
| 1412 | M(VecMax, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1413 | M(VecAnd, VecBinaryOperation) \ |
| 1414 | M(VecAndNot, VecBinaryOperation) \ |
| 1415 | M(VecOr, VecBinaryOperation) \ |
| 1416 | M(VecXor, VecBinaryOperation) \ |
| 1417 | M(VecShl, VecBinaryOperation) \ |
| 1418 | M(VecShr, VecBinaryOperation) \ |
| 1419 | M(VecUShr, VecBinaryOperation) \ |
Aart Bik | 8de5916 | 2017-04-21 09:42:01 -0700 | [diff] [blame] | 1420 | M(VecSetScalars, VecOperation) \ |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1421 | M(VecMultiplyAccumulate, VecOperation) \ |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1422 | M(VecSADAccumulate, VecOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1423 | M(VecLoad, VecMemoryOperation) \ |
| 1424 | M(VecStore, VecMemoryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1425 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1426 | /* |
| 1427 | * Instructions, shared across several (not all) architectures. |
| 1428 | */ |
| 1429 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1430 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1431 | #else |
| 1432 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1433 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1434 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1435 | M(MultiplyAccumulate, Instruction) \ |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 1436 | M(IntermediateAddressIndex, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1437 | #endif |
| 1438 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1439 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1440 | |
| 1441 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1442 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1443 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1444 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1445 | #else |
| 1446 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1447 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 1448 | M(MipsPackedSwitch, Instruction) \ |
| 1449 | M(IntermediateArrayAddressIndex, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1450 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1451 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1452 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1453 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1454 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1455 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1456 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1457 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1458 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1459 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1460 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1461 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1462 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1463 | |
| 1464 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1465 | |
| 1466 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1467 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1468 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1469 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1470 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1471 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1472 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1473 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1474 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1475 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1476 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1477 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1478 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1479 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1480 | M(BinaryOperation, Instruction) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1481 | M(Invoke, Instruction) \ |
| 1482 | M(VecOperation, Instruction) \ |
| 1483 | M(VecUnaryOperation, VecOperation) \ |
| 1484 | M(VecBinaryOperation, VecOperation) \ |
| 1485 | M(VecMemoryOperation, VecOperation) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1486 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1487 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1488 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1489 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1490 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1491 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1492 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1493 | #undef FORWARD_DECLARATION |
| 1494 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1495 | #define DECLARE_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1496 | private: \ |
| 1497 | H##type& operator=(const H##type&) = delete; \ |
| 1498 | public: \ |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1499 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1500 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1501 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1502 | return other->Is##type(); \ |
| 1503 | } \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1504 | HInstruction* Clone(ArenaAllocator* arena) const OVERRIDE { \ |
| 1505 | DCHECK(IsClonable()); \ |
| 1506 | return new (arena) H##type(*this->As##type()); \ |
| 1507 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1508 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1509 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1510 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1511 | private: \ |
| 1512 | H##type& operator=(const H##type&) = delete; \ |
| 1513 | public: \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1514 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1515 | const H##type* As##type() const { return this; } \ |
| 1516 | H##type* As##type() { return this; } |
| 1517 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1518 | #define DEFAULT_COPY_CONSTRUCTOR(type) \ |
| 1519 | explicit H##type(const H##type& other) = default; |
| 1520 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1521 | template <typename T> |
Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 1522 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode>, |
| 1523 | public IntrusiveForwardListNode<HUseListNode<T>> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1524 | public: |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1525 | // Get the instruction which has this use as one of the inputs. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1526 | T GetUser() const { return user_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1527 | // Get the position of the input record that this use corresponds to. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1528 | size_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1529 | // Set the position of the input record that this use corresponds to. |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1530 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1531 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1532 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1533 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1534 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1535 | |
| 1536 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1537 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1538 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1539 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1540 | |
| 1541 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1542 | }; |
| 1543 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1544 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1545 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1546 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1547 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1548 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1549 | // by the used instructions. |
| 1550 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1551 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1552 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1553 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1554 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1555 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1556 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1557 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1558 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1559 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1560 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1564 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1565 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1566 | |
| 1567 | private: |
| 1568 | // Instruction used by the user. |
| 1569 | HInstruction* instruction_; |
| 1570 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1571 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1572 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1573 | }; |
| 1574 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1575 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1576 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1577 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1578 | struct HInputExtractor { |
| 1579 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1580 | return record.GetInstruction(); |
| 1581 | } |
| 1582 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1583 | return record.GetInstruction(); |
| 1584 | } |
| 1585 | }; |
| 1586 | |
| 1587 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1588 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1589 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1590 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1591 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1592 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1593 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1594 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1595 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1596 | * modify the value of a reference field read [although it may modify the |
| 1597 | * reference fetch prior to reading the field, which is represented by its own |
| 1598 | * write/read dependence]). The analysis makes conservative points-to |
| 1599 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1600 | * the same, and any reference read depends on any reference read without |
| 1601 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1602 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1603 | * The internal representation uses 38-bit and is described in the table below. |
| 1604 | * The first line indicates the side effect, and for field/array accesses the |
| 1605 | * 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] | 1606 | * DataType::Type enum). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1607 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1608 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1609 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1610 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1611 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1612 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1613 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1614 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1615 | * |
| 1616 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1617 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1618 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1619 | class SideEffects : public ValueObject { |
| 1620 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1621 | SideEffects() : flags_(0) {} |
| 1622 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1623 | static SideEffects None() { |
| 1624 | return SideEffects(0); |
| 1625 | } |
| 1626 | |
| 1627 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1628 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1629 | } |
| 1630 | |
| 1631 | static SideEffects AllChanges() { |
| 1632 | return SideEffects(kAllChangeBits); |
| 1633 | } |
| 1634 | |
| 1635 | static SideEffects AllDependencies() { |
| 1636 | return SideEffects(kAllDependOnBits); |
| 1637 | } |
| 1638 | |
| 1639 | static SideEffects AllExceptGCDependency() { |
| 1640 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1641 | } |
| 1642 | |
| 1643 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1644 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1645 | } |
| 1646 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1647 | static SideEffects AllWrites() { |
| 1648 | return SideEffects(kAllWrites); |
| 1649 | } |
| 1650 | |
| 1651 | static SideEffects AllReads() { |
| 1652 | return SideEffects(kAllReads); |
| 1653 | } |
| 1654 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1655 | static SideEffects FieldWriteOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1656 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1657 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1658 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1659 | } |
| 1660 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1661 | static SideEffects ArrayWriteOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1662 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1663 | } |
| 1664 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1665 | static SideEffects FieldReadOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1666 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1667 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1668 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1671 | static SideEffects ArrayReadOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1672 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1675 | static SideEffects CanTriggerGC() { |
| 1676 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1677 | } |
| 1678 | |
| 1679 | static SideEffects DependsOnGC() { |
| 1680 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1681 | } |
| 1682 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1683 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1684 | SideEffects Union(SideEffects other) const { |
| 1685 | return SideEffects(flags_ | other.flags_); |
| 1686 | } |
| 1687 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1688 | SideEffects Exclusion(SideEffects other) const { |
| 1689 | return SideEffects(flags_ & ~other.flags_); |
| 1690 | } |
| 1691 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1692 | void Add(SideEffects other) { |
| 1693 | flags_ |= other.flags_; |
| 1694 | } |
| 1695 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1696 | bool Includes(SideEffects other) const { |
| 1697 | return (other.flags_ & flags_) == other.flags_; |
| 1698 | } |
| 1699 | |
| 1700 | bool HasSideEffects() const { |
| 1701 | return (flags_ & kAllChangeBits); |
| 1702 | } |
| 1703 | |
| 1704 | bool HasDependencies() const { |
| 1705 | return (flags_ & kAllDependOnBits); |
| 1706 | } |
| 1707 | |
| 1708 | // Returns true if there are no side effects or dependencies. |
| 1709 | bool DoesNothing() const { |
| 1710 | return flags_ == 0; |
| 1711 | } |
| 1712 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1713 | // Returns true if something is written. |
| 1714 | bool DoesAnyWrite() const { |
| 1715 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1716 | } |
| 1717 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1718 | // Returns true if something is read. |
| 1719 | bool DoesAnyRead() const { |
| 1720 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1721 | } |
| 1722 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1723 | // Returns true if potentially everything is written and read |
| 1724 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1725 | bool DoesAllReadWrite() const { |
| 1726 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1727 | } |
| 1728 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1729 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1730 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1733 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1734 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1735 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1736 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1740 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1741 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1742 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1743 | for (int s = kLastBit; s >= 0; s--) { |
| 1744 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1745 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1746 | // This is a bit for the GC side effect. |
| 1747 | if (current_bit_is_set) { |
| 1748 | flags += "GC"; |
| 1749 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1750 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1751 | } else { |
| 1752 | // This is a bit for the array/field analysis. |
| 1753 | // The underscore character stands for the 'can trigger GC' bit. |
| 1754 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1755 | if (current_bit_is_set) { |
| 1756 | flags += kDebug[s]; |
| 1757 | } |
| 1758 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1759 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1760 | flags += "|"; |
| 1761 | } |
| 1762 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1763 | } |
| 1764 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1765 | } |
| 1766 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1767 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1768 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1769 | private: |
| 1770 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1771 | |
| 1772 | static constexpr int kFieldWriteOffset = 0; |
| 1773 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1774 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1775 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1776 | |
| 1777 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1778 | |
| 1779 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1780 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1781 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1782 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1783 | |
| 1784 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1785 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1786 | |
| 1787 | // Aliases. |
| 1788 | |
| 1789 | static_assert(kChangeBits == kDependOnBits, |
| 1790 | "the 'change' bits should match the 'depend on' bits."); |
| 1791 | |
| 1792 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1793 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1794 | static constexpr uint64_t kAllWrites = |
| 1795 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1796 | static constexpr uint64_t kAllReads = |
| 1797 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1798 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1799 | // 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] | 1800 | static uint64_t TypeFlag(DataType::Type type, int offset) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1801 | int shift; |
| 1802 | switch (type) { |
| 1803 | case DataType::Type::kReference: shift = 0; break; |
| 1804 | case DataType::Type::kBool: shift = 1; break; |
| 1805 | case DataType::Type::kInt8: shift = 2; break; |
| 1806 | case DataType::Type::kUint16: shift = 3; break; |
| 1807 | case DataType::Type::kInt16: shift = 4; break; |
| 1808 | case DataType::Type::kInt32: shift = 5; break; |
| 1809 | case DataType::Type::kInt64: shift = 6; break; |
| 1810 | case DataType::Type::kFloat32: shift = 7; break; |
| 1811 | case DataType::Type::kFloat64: shift = 8; break; |
| 1812 | default: |
| 1813 | LOG(FATAL) << "Unexpected data type " << type; |
| 1814 | UNREACHABLE(); |
| 1815 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1816 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1817 | DCHECK_LT(shift, kArrayWriteOffset); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1818 | return UINT64_C(1) << (shift + offset); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | // Private constructor on direct flags value. |
| 1822 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1823 | |
| 1824 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1825 | }; |
| 1826 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1827 | // 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] | 1828 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1829 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1830 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1831 | size_t number_of_vregs, |
| 1832 | ArtMethod* method, |
| 1833 | uint32_t dex_pc, |
| 1834 | HInstruction* holder) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1835 | : vregs_(number_of_vregs, allocator->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1836 | locations_(allocator->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1837 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1838 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1839 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1840 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1841 | } |
| 1842 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1843 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
| 1844 | const HEnvironment& to_copy, |
| 1845 | HInstruction* holder) |
| 1846 | : HEnvironment(allocator, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1847 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1848 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1849 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1850 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1851 | |
Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 1852 | void AllocateLocations() { |
| 1853 | DCHECK(locations_.empty()); |
| 1854 | locations_.resize(vregs_.size()); |
| 1855 | } |
| 1856 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1857 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1858 | if (parent_ != nullptr) { |
| 1859 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1860 | } else { |
| 1861 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1862 | parent_->CopyFrom(parent); |
| 1863 | if (parent->GetParent() != nullptr) { |
| 1864 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1865 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1866 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 1869 | void CopyFrom(ArrayRef<HInstruction* const> locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1870 | void CopyFrom(HEnvironment* environment); |
| 1871 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1872 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1873 | // input to the loop phi instead. This is for inserting instructions that |
| 1874 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1875 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1876 | |
| 1877 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1878 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1882 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1883 | } |
| 1884 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1885 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1886 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1887 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1888 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1889 | HEnvironment* GetParent() const { return parent_; } |
| 1890 | |
| 1891 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1892 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1896 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | uint32_t GetDexPc() const { |
| 1900 | return dex_pc_; |
| 1901 | } |
| 1902 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1903 | ArtMethod* GetMethod() const { |
| 1904 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1905 | } |
| 1906 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1907 | HInstruction* GetHolder() const { |
| 1908 | return holder_; |
| 1909 | } |
| 1910 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1911 | |
| 1912 | bool IsFromInlinedInvoke() const { |
| 1913 | return GetParent() != nullptr; |
| 1914 | } |
| 1915 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1916 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1917 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1918 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1919 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1920 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1921 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1922 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1923 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1924 | HInstruction* const holder_; |
| 1925 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1926 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1927 | |
| 1928 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1929 | }; |
| 1930 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1931 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1932 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1933 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1934 | : previous_(nullptr), |
| 1935 | next_(nullptr), |
| 1936 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1937 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1938 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1939 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1940 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1941 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1942 | locations_(nullptr), |
| 1943 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1944 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1945 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1946 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1947 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1948 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1949 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1950 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1951 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1952 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1953 | enum InstructionKind { |
| 1954 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1955 | }; |
| 1956 | #undef DECLARE_KIND |
| 1957 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1958 | HInstruction* GetNext() const { return next_; } |
| 1959 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1960 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1961 | HInstruction* GetNextDisregardingMoves() const; |
| 1962 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1963 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1964 | HBasicBlock* GetBlock() const { return block_; } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1965 | ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1966 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1967 | bool IsInBlock() const { return block_ != nullptr; } |
| 1968 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1969 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1970 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1971 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1972 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1973 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1974 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1975 | |
| 1976 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1977 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1978 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1979 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1980 | } |
| 1981 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1982 | HInputsRef GetInputs() { |
| 1983 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1984 | } |
| 1985 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1986 | HConstInputsRef GetInputs() const { |
| 1987 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1991 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1992 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 1993 | bool HasInput(HInstruction* input) const { |
| 1994 | for (const HInstruction* i : GetInputs()) { |
| 1995 | if (i == input) { |
| 1996 | return true; |
| 1997 | } |
| 1998 | } |
| 1999 | return false; |
| 2000 | } |
| 2001 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2002 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 2003 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 2004 | } |
| 2005 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2006 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 2007 | virtual const char* DebugName() const = 0; |
| 2008 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2009 | virtual DataType::Type GetType() const { return DataType::Type::kVoid; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2010 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2011 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2012 | |
| 2013 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2014 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2015 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2016 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2017 | // Can the instruction throw? |
| 2018 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 2019 | // 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] | 2020 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2021 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2022 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2023 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2024 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2025 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2026 | // Does not apply for all instructions, but having this at top level greatly |
| 2027 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 2028 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2029 | virtual bool CanBeNull() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2030 | DCHECK_EQ(GetType(), DataType::Type::kReference) << "CanBeNull only applies to reference types"; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2031 | return true; |
| 2032 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2033 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2034 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 2035 | return false; |
| 2036 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2037 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2038 | virtual bool IsActualObject() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2039 | return GetType() == DataType::Type::kReference; |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 2042 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2043 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2044 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2045 | DCHECK_EQ(GetType(), DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2046 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 2047 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2048 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2049 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2050 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2051 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2052 | // Note: fixup_end remains valid across push_front(). |
| 2053 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 2054 | HUseListNode<HInstruction*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2055 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HInstruction*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2056 | uses_.push_front(*new_node); |
| 2057 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2060 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2061 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2062 | // Note: env_fixup_end remains valid across push_front(). |
| 2063 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2064 | HUseListNode<HEnvironment*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2065 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HEnvironment*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2066 | env_uses_.push_front(*new_node); |
| 2067 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2068 | } |
| 2069 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2070 | void RemoveAsUserOfInput(size_t input) { |
| 2071 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2072 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2073 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2074 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2075 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2076 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2077 | void RemoveAsUserOfAllInputs() { |
| 2078 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2079 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2080 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2081 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2082 | } |
| 2083 | } |
| 2084 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2085 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2086 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2087 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2088 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2089 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2090 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2091 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2092 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2093 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2094 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2095 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2096 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2097 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2098 | !CanThrow() && |
| 2099 | !IsSuspendCheck() && |
| 2100 | !IsControlFlow() && |
| 2101 | !IsNativeDebugInfo() && |
| 2102 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2103 | // If we added an explicit barrier then we should keep it. |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2104 | !IsMemoryBarrier() && |
| 2105 | !IsConstructorFence(); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2108 | bool IsDeadAndRemovable() const { |
| 2109 | return IsRemovable() && !HasUses(); |
| 2110 | } |
| 2111 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2112 | // Does this instruction strictly dominate `other_instruction`? |
| 2113 | // Returns false if this instruction and `other_instruction` are the same. |
| 2114 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2115 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2116 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2117 | int GetId() const { return id_; } |
| 2118 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2119 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2120 | int GetSsaIndex() const { return ssa_index_; } |
| 2121 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2122 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2123 | |
| 2124 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2125 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2126 | // Set the `environment_` field. Raw because this method does not |
| 2127 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2128 | void SetRawEnvironment(HEnvironment* environment) { |
| 2129 | DCHECK(environment_ == nullptr); |
| 2130 | DCHECK_EQ(environment->GetHolder(), this); |
| 2131 | environment_ = environment; |
| 2132 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2133 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2134 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2135 | DCHECK(environment_ != nullptr); |
| 2136 | DCHECK_EQ(environment->GetHolder(), this); |
| 2137 | DCHECK(environment->GetParent() == nullptr); |
| 2138 | environment->parent_ = environment_; |
| 2139 | environment_ = environment; |
| 2140 | } |
| 2141 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2142 | void RemoveEnvironment(); |
| 2143 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2144 | // Set the environment of this instruction, copying it from `environment`. While |
| 2145 | // copying, the uses lists are being updated. |
| 2146 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2147 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2148 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2149 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2150 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2151 | if (environment->GetParent() != nullptr) { |
| 2152 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2153 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2154 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2155 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2156 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2157 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2158 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2159 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2160 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2161 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2162 | if (environment->GetParent() != nullptr) { |
| 2163 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2164 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2167 | // Returns the number of entries in the environment. Typically, that is the |
| 2168 | // number of dex registers in a method. It could be more in case of inlining. |
| 2169 | size_t EnvironmentSize() const; |
| 2170 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2171 | LocationSummary* GetLocations() const { return locations_; } |
| 2172 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2173 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2174 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2175 | void ReplaceUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2176 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2177 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2178 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2179 | // uses of this instruction by `other` are *not* updated. |
| 2180 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2181 | ReplaceWith(other); |
| 2182 | other->ReplaceInput(this, use_index); |
| 2183 | } |
| 2184 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2185 | // Move `this` instruction before `cursor` |
| 2186 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2187 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2188 | // Move `this` before its first user and out of any loops. If there is no |
| 2189 | // out-of-loop user that dominates all other users, move the instruction |
| 2190 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2191 | // |
| 2192 | // This can be used only on non-throwing instructions with no side effects that |
| 2193 | // have at least one use but no environment uses. |
| 2194 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2195 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2196 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2197 | bool Is##type() const; \ |
| 2198 | const H##type* As##type() const; \ |
| 2199 | H##type* As##type(); |
| 2200 | |
| 2201 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2202 | #undef INSTRUCTION_TYPE_CHECK |
| 2203 | |
| 2204 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2205 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2206 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2207 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2208 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2209 | #undef INSTRUCTION_TYPE_CHECK |
| 2210 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2211 | // Return a clone of the instruction if it is clonable (shallow copy by default, custom copy |
| 2212 | // if a custom copy-constructor is provided for a particular type). If IsClonable() is false for |
| 2213 | // the instruction then the behaviour of this function is undefined. |
| 2214 | // |
| 2215 | // Note: It is semantically valid to create a clone of the instruction only until |
| 2216 | // prepare_for_register_allocator phase as lifetime, intervals and codegen info are not |
| 2217 | // copied. |
| 2218 | // |
| 2219 | // Note: HEnvironment and some other fields are not copied and are set to default values, see |
| 2220 | // 'explicit HInstruction(const HInstruction& other)' for details. |
| 2221 | virtual HInstruction* Clone(ArenaAllocator* arena ATTRIBUTE_UNUSED) const { |
| 2222 | LOG(FATAL) << "Cloning is not implemented for the instruction " << |
| 2223 | DebugName() << " " << GetId(); |
| 2224 | UNREACHABLE(); |
| 2225 | } |
| 2226 | |
| 2227 | // Return whether instruction can be cloned (copied). |
| 2228 | virtual bool IsClonable() const { return false; } |
| 2229 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2230 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2231 | // TODO: this method is used by LICM and GVN with possibly different |
| 2232 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2233 | virtual bool CanBeMoved() const { return false; } |
| 2234 | |
| 2235 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2236 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2237 | return false; |
| 2238 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2239 | |
| 2240 | // Returns whether any data encoded in the two instructions is equal. |
| 2241 | // This method does not look at the inputs. Both instructions must be |
| 2242 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2243 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2244 | return false; |
| 2245 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2246 | |
| 2247 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2248 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2249 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2250 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2251 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2252 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2253 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2254 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2255 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2256 | InstructionKind GetKind() const PURE; |
| 2257 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2258 | |
| 2259 | virtual size_t ComputeHashCode() const { |
| 2260 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2261 | for (const HInstruction* input : GetInputs()) { |
| 2262 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2263 | } |
| 2264 | return result; |
| 2265 | } |
| 2266 | |
| 2267 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2268 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2269 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2270 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2271 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2272 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2273 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2274 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2275 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2276 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2277 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2278 | |
| 2279 | // Returns whether the code generation of the instruction will require to have access |
| 2280 | // to the current method. Such instructions are: |
| 2281 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2282 | // 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] | 2283 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2284 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2285 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2286 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2287 | } |
| 2288 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2289 | // Returns whether the code generation of the instruction will require to have access |
| 2290 | // to the dex cache of the current method's declaring class via the current method. |
| 2291 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2292 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2293 | // Does this instruction have any use in an environment before |
| 2294 | // control flow hits 'other'? |
| 2295 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2296 | |
| 2297 | // Remove all references to environment uses of this instruction. |
| 2298 | // The caller must ensure that this is safe to do. |
| 2299 | void RemoveEnvironmentUsers(); |
| 2300 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2301 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2302 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2303 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2304 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2305 | // If set, the machine code for this instruction is assumed to be generated by |
| 2306 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2307 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2308 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2309 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2310 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2311 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2312 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2313 | return GetInputRecords()[i]; |
| 2314 | } |
| 2315 | |
| 2316 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2317 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2318 | input_records[index] = input; |
| 2319 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2320 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2321 | uint32_t GetPackedFields() const { |
| 2322 | return packed_fields_; |
| 2323 | } |
| 2324 | |
| 2325 | template <size_t flag> |
| 2326 | bool GetPackedFlag() const { |
| 2327 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2328 | } |
| 2329 | |
| 2330 | template <size_t flag> |
| 2331 | void SetPackedFlag(bool value = true) { |
| 2332 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2333 | } |
| 2334 | |
| 2335 | template <typename BitFieldType> |
| 2336 | typename BitFieldType::value_type GetPackedField() const { |
| 2337 | return BitFieldType::Decode(packed_fields_); |
| 2338 | } |
| 2339 | |
| 2340 | template <typename BitFieldType> |
| 2341 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2342 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2343 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2344 | } |
| 2345 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2346 | // Copy construction for the instruction (used for Clone function). |
| 2347 | // |
| 2348 | // Fields (e.g. lifetime, intervals and codegen info) associated with phases starting from |
| 2349 | // prepare_for_register_allocator are not copied (set to default values). |
| 2350 | // |
| 2351 | // Copy constructors must be provided for every HInstruction type; default copy constructor is |
| 2352 | // fine for most of them. However for some of the instructions a custom copy constructor must be |
| 2353 | // specified (when instruction has non-trivially copyable fields and must have a special behaviour |
| 2354 | // for copying them). |
| 2355 | explicit HInstruction(const HInstruction& other) |
| 2356 | : previous_(nullptr), |
| 2357 | next_(nullptr), |
| 2358 | block_(nullptr), |
| 2359 | dex_pc_(other.dex_pc_), |
| 2360 | id_(-1), |
| 2361 | ssa_index_(-1), |
| 2362 | packed_fields_(other.packed_fields_), |
| 2363 | environment_(nullptr), |
| 2364 | locations_(nullptr), |
| 2365 | live_interval_(nullptr), |
| 2366 | lifetime_position_(kNoLifetime), |
| 2367 | side_effects_(other.side_effects_), |
| 2368 | reference_type_handle_(other.reference_type_handle_) {} |
| 2369 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2370 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2371 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2372 | auto before_use_node = uses_.before_begin(); |
| 2373 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2374 | HInstruction* user = use_node->GetUser(); |
| 2375 | size_t input_index = use_node->GetIndex(); |
| 2376 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2377 | before_use_node = use_node; |
| 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2382 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2383 | if (next != uses_.end()) { |
| 2384 | HInstruction* next_user = next->GetUser(); |
| 2385 | size_t next_index = next->GetIndex(); |
| 2386 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2387 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2392 | auto before_env_use_node = env_uses_.before_begin(); |
| 2393 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2394 | HEnvironment* user = env_use_node->GetUser(); |
| 2395 | size_t input_index = env_use_node->GetIndex(); |
| 2396 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2397 | before_env_use_node = env_use_node; |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2402 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2403 | if (next != env_uses_.end()) { |
| 2404 | HEnvironment* next_user = next->GetUser(); |
| 2405 | size_t next_index = next->GetIndex(); |
| 2406 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2407 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2408 | } |
| 2409 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2410 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2411 | HInstruction* previous_; |
| 2412 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2413 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2414 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2415 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2416 | // An instruction gets an id when it is added to the graph. |
| 2417 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2418 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2419 | int id_; |
| 2420 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2421 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2422 | int ssa_index_; |
| 2423 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2424 | // Packed fields. |
| 2425 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2426 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2427 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2428 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2429 | |
| 2430 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2431 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2432 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2433 | // The environment associated with this instruction. Not null if the instruction |
| 2434 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2435 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2436 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2437 | // Set by the code generator. |
| 2438 | LocationSummary* locations_; |
| 2439 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2440 | // Set by the liveness analysis. |
| 2441 | LiveInterval* live_interval_; |
| 2442 | |
| 2443 | // Set by the liveness analysis, this is the position in a linear |
| 2444 | // order of blocks where this instruction's live interval start. |
| 2445 | size_t lifetime_position_; |
| 2446 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2447 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2448 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2449 | // The reference handle part of the reference type info. |
| 2450 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2451 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2452 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2453 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2454 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2455 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2456 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2457 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2458 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2459 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2460 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2461 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2462 | // Iterates over the instructions, while preserving the next instruction |
| 2463 | // in case the current instruction gets removed from the list by the user |
| 2464 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2465 | class HInstructionIterator : public ValueObject { |
| 2466 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2467 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2468 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2469 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2470 | } |
| 2471 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2472 | bool Done() const { return instruction_ == nullptr; } |
| 2473 | HInstruction* Current() const { return instruction_; } |
| 2474 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2475 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2476 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | private: |
| 2480 | HInstruction* instruction_; |
| 2481 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2482 | |
| 2483 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2484 | }; |
| 2485 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2486 | // Iterates over the instructions without saving the next instruction, |
| 2487 | // therefore handling changes in the graph potentially made by the user |
| 2488 | // of this iterator. |
| 2489 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2490 | public: |
| 2491 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2492 | : instruction_(instructions.first_instruction_) { |
| 2493 | } |
| 2494 | |
| 2495 | bool Done() const { return instruction_ == nullptr; } |
| 2496 | HInstruction* Current() const { return instruction_; } |
| 2497 | void Advance() { |
| 2498 | instruction_ = instruction_->GetNext(); |
| 2499 | } |
| 2500 | |
| 2501 | private: |
| 2502 | HInstruction* instruction_; |
| 2503 | |
| 2504 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2505 | }; |
| 2506 | |
| 2507 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2508 | class HBackwardInstructionIterator : public ValueObject { |
| 2509 | public: |
| 2510 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2511 | : instruction_(instructions.last_instruction_) { |
| 2512 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2513 | } |
| 2514 | |
| 2515 | bool Done() const { return instruction_ == nullptr; } |
| 2516 | HInstruction* Current() const { return instruction_; } |
| 2517 | void Advance() { |
| 2518 | instruction_ = next_; |
| 2519 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2520 | } |
| 2521 | |
| 2522 | private: |
| 2523 | HInstruction* instruction_; |
| 2524 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2525 | |
| 2526 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2527 | }; |
| 2528 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2529 | class HVariableInputSizeInstruction : public HInstruction { |
| 2530 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2531 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2532 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 2533 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2534 | } |
| 2535 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2536 | void AddInput(HInstruction* input); |
| 2537 | void InsertInputAt(size_t index, HInstruction* input); |
| 2538 | void RemoveInputAt(size_t index); |
| 2539 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2540 | // Removes all the inputs. |
| 2541 | // Also removes this instructions from each input's use list |
| 2542 | // (for non-environment uses only). |
| 2543 | void RemoveAllInputs(); |
| 2544 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2545 | protected: |
| 2546 | HVariableInputSizeInstruction(SideEffects side_effects, |
| 2547 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2548 | ArenaAllocator* allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2549 | size_t number_of_inputs, |
| 2550 | ArenaAllocKind kind) |
| 2551 | : HInstruction(side_effects, dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2552 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2553 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2554 | DEFAULT_COPY_CONSTRUCTOR(VariableInputSizeInstruction); |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2555 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2556 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2557 | }; |
| 2558 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2559 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2560 | class HTemplateInstruction: public HInstruction { |
| 2561 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2562 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2563 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2564 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2565 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2566 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2567 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2568 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2569 | } |
| 2570 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2571 | protected: |
| 2572 | DEFAULT_COPY_CONSTRUCTOR(TemplateInstruction<N>); |
| 2573 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2574 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2575 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2576 | |
| 2577 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2578 | }; |
| 2579 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2580 | // HTemplateInstruction specialization for N=0. |
| 2581 | template<> |
| 2582 | class HTemplateInstruction<0>: public HInstruction { |
| 2583 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2584 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2585 | : HInstruction(side_effects, dex_pc) {} |
| 2586 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2587 | virtual ~HTemplateInstruction() {} |
| 2588 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2589 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2590 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2591 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2592 | } |
| 2593 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2594 | protected: |
| 2595 | DEFAULT_COPY_CONSTRUCTOR(TemplateInstruction<0>); |
| 2596 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2597 | private: |
| 2598 | friend class SsaBuilder; |
| 2599 | }; |
| 2600 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2601 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2602 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2603 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2604 | HExpression<N>(DataType::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2605 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2606 | this->template SetPackedField<TypeField>(type); |
| 2607 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2608 | virtual ~HExpression() {} |
| 2609 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2610 | DataType::Type GetType() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2611 | return TypeField::Decode(this->GetPackedFields()); |
| 2612 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2613 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2614 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2615 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2616 | static constexpr size_t kFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2617 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2618 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2619 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2620 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2621 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2622 | DEFAULT_COPY_CONSTRUCTOR(Expression<N>); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2623 | }; |
| 2624 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2625 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2626 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2627 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2628 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2629 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2630 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2631 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2632 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2633 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2634 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2635 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2636 | protected: |
| 2637 | DEFAULT_COPY_CONSTRUCTOR(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2638 | }; |
| 2639 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2640 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2641 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2642 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2643 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2644 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2645 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2646 | SetRawInputAt(0, value); |
| 2647 | } |
| 2648 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2649 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2650 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2651 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2652 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2653 | protected: |
| 2654 | DEFAULT_COPY_CONSTRUCTOR(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2655 | }; |
| 2656 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2657 | class HPhi FINAL : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2658 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2659 | HPhi(ArenaAllocator* allocator, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2660 | uint32_t reg_number, |
| 2661 | size_t number_of_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2662 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2663 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2664 | : HVariableInputSizeInstruction( |
| 2665 | SideEffects::None(), |
| 2666 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2667 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2668 | number_of_inputs, |
| 2669 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2670 | reg_number_(reg_number) { |
| 2671 | SetPackedField<TypeField>(ToPhiType(type)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2672 | DCHECK_NE(GetType(), DataType::Type::kVoid); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2673 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2674 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2675 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2676 | SetPackedFlag<kFlagIsLive>(true); |
| 2677 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2678 | } |
| 2679 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2680 | bool IsClonable() const OVERRIDE { return true; } |
| 2681 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2682 | // 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] | 2683 | static DataType::Type ToPhiType(DataType::Type type) { |
| 2684 | return DataType::Kind(type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2688 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2689 | DataType::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2690 | void SetType(DataType::Type new_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2691 | // Make sure that only valid type changes occur. The following are allowed: |
| 2692 | // (1) int -> float/ref (primitive type propagation), |
| 2693 | // (2) long -> double (primitive type propagation). |
| 2694 | DCHECK(GetType() == new_type || |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2695 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kFloat32) || |
| 2696 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kReference) || |
| 2697 | (GetType() == DataType::Type::kInt64 && new_type == DataType::Type::kFloat64)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2698 | SetPackedField<TypeField>(new_type); |
| 2699 | } |
| 2700 | |
| 2701 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2702 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2703 | |
| 2704 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2705 | |
| 2706 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2707 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2708 | bool IsDead() const { return !IsLive(); } |
| 2709 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2710 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2711 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2712 | return other != nullptr |
| 2713 | && other->IsPhi() |
| 2714 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2715 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2716 | } |
| 2717 | |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 2718 | bool HasEquivalentPhi() const { |
| 2719 | if (GetPrevious() != nullptr && GetPrevious()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2720 | return true; |
| 2721 | } |
| 2722 | if (GetNext() != nullptr && GetNext()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2723 | return true; |
| 2724 | } |
| 2725 | return false; |
| 2726 | } |
| 2727 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2728 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2729 | // An equivalent phi is a phi having the same dex register and type. |
| 2730 | // It assumes that phis with the same dex register are adjacent. |
| 2731 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2732 | HInstruction* next = GetNext(); |
| 2733 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2734 | if (next->GetType() == GetType()) { |
| 2735 | return next->AsPhi(); |
| 2736 | } |
| 2737 | next = next->GetNext(); |
| 2738 | } |
| 2739 | return nullptr; |
| 2740 | } |
| 2741 | |
| 2742 | DECLARE_INSTRUCTION(Phi); |
| 2743 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2744 | protected: |
| 2745 | DEFAULT_COPY_CONSTRUCTOR(Phi); |
| 2746 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2747 | private: |
| 2748 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2749 | static constexpr size_t kFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2750 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2751 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2752 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2753 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2754 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2755 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2756 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2757 | const uint32_t reg_number_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2758 | }; |
| 2759 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2760 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2761 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2762 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2763 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2764 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2765 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2766 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2767 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2768 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2769 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2770 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2771 | protected: |
| 2772 | DEFAULT_COPY_CONSTRUCTOR(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2773 | }; |
| 2774 | |
| 2775 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2776 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2777 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2778 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2779 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2780 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2781 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2782 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2783 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2784 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2785 | } |
| 2786 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2787 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2788 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2789 | protected: |
| 2790 | DEFAULT_COPY_CONSTRUCTOR(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2791 | }; |
| 2792 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2793 | class HConstant : public HExpression<0> { |
| 2794 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2795 | explicit HConstant(DataType::Type type, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2796 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2797 | |
| 2798 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2799 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2800 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2801 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2802 | // Is this constant 0 in the arithmetic sense? |
| 2803 | virtual bool IsArithmeticZero() const { return false; } |
| 2804 | // Is this constant a 0-bit pattern? |
| 2805 | virtual bool IsZeroBitPattern() const { return false; } |
| 2806 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2807 | virtual bool IsOne() const { return false; } |
| 2808 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2809 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2810 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2811 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2812 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2813 | protected: |
| 2814 | DEFAULT_COPY_CONSTRUCTOR(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2815 | }; |
| 2816 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2817 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2818 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2819 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2820 | return true; |
| 2821 | } |
| 2822 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2823 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2824 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2825 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2826 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2827 | // The null constant representation is a 0-bit pattern. |
| 2828 | virtual bool IsZeroBitPattern() const { return true; } |
| 2829 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2830 | DECLARE_INSTRUCTION(NullConstant); |
| 2831 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2832 | protected: |
| 2833 | DEFAULT_COPY_CONSTRUCTOR(NullConstant); |
| 2834 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2835 | private: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2836 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) |
| 2837 | : HConstant(DataType::Type::kReference, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2838 | |
| 2839 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2840 | }; |
| 2841 | |
| 2842 | // Constants of the type int. Those can be from Dex instructions, or |
| 2843 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2844 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2845 | public: |
| 2846 | int32_t GetValue() const { return value_; } |
| 2847 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2848 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2849 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2850 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2851 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2852 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2853 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2854 | return other->AsIntConstant()->value_ == value_; |
| 2855 | } |
| 2856 | |
| 2857 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2858 | |
| 2859 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2860 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2861 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2862 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2863 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2864 | // Integer constants are used to encode Boolean values as well, |
| 2865 | // where 1 means true and 0 means false. |
| 2866 | bool IsTrue() const { return GetValue() == 1; } |
| 2867 | bool IsFalse() const { return GetValue() == 0; } |
| 2868 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2869 | DECLARE_INSTRUCTION(IntConstant); |
| 2870 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2871 | protected: |
| 2872 | DEFAULT_COPY_CONSTRUCTOR(IntConstant); |
| 2873 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2874 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2875 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2876 | : HConstant(DataType::Type::kInt32, dex_pc), value_(value) {} |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2877 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2878 | : HConstant(DataType::Type::kInt32, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2879 | |
| 2880 | const int32_t value_; |
| 2881 | |
| 2882 | friend class HGraph; |
| 2883 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2884 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2885 | }; |
| 2886 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2887 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2888 | public: |
| 2889 | int64_t GetValue() const { return value_; } |
| 2890 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2891 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2892 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2893 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2894 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2895 | return other->AsLongConstant()->value_ == value_; |
| 2896 | } |
| 2897 | |
| 2898 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2899 | |
| 2900 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2901 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2902 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2903 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2904 | |
| 2905 | DECLARE_INSTRUCTION(LongConstant); |
| 2906 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2907 | protected: |
| 2908 | DEFAULT_COPY_CONSTRUCTOR(LongConstant); |
| 2909 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2910 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2911 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2912 | : HConstant(DataType::Type::kInt64, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2913 | |
| 2914 | const int64_t value_; |
| 2915 | |
| 2916 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2917 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2918 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2919 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2920 | public: |
| 2921 | float GetValue() const { return value_; } |
| 2922 | |
| 2923 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2924 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2925 | } |
| 2926 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2927 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2928 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2929 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2930 | } |
| 2931 | |
| 2932 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2933 | |
| 2934 | bool IsMinusOne() const OVERRIDE { |
| 2935 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2936 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2937 | bool IsArithmeticZero() const OVERRIDE { |
| 2938 | return std::fpclassify(value_) == FP_ZERO; |
| 2939 | } |
| 2940 | bool IsArithmeticPositiveZero() const { |
| 2941 | return IsArithmeticZero() && !std::signbit(value_); |
| 2942 | } |
| 2943 | bool IsArithmeticNegativeZero() const { |
| 2944 | return IsArithmeticZero() && std::signbit(value_); |
| 2945 | } |
| 2946 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2947 | 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] | 2948 | } |
| 2949 | bool IsOne() const OVERRIDE { |
| 2950 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2951 | } |
| 2952 | bool IsNaN() const { |
| 2953 | return std::isnan(value_); |
| 2954 | } |
| 2955 | |
| 2956 | DECLARE_INSTRUCTION(FloatConstant); |
| 2957 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2958 | protected: |
| 2959 | DEFAULT_COPY_CONSTRUCTOR(FloatConstant); |
| 2960 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2961 | private: |
| 2962 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2963 | : HConstant(DataType::Type::kFloat32, dex_pc), value_(value) {} |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2964 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2965 | : HConstant(DataType::Type::kFloat32, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2966 | |
| 2967 | const float value_; |
| 2968 | |
| 2969 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2970 | friend class SsaBuilder; |
| 2971 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2972 | }; |
| 2973 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2974 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2975 | public: |
| 2976 | double GetValue() const { return value_; } |
| 2977 | |
| 2978 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2979 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2980 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2981 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2982 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2983 | } |
| 2984 | |
| 2985 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2986 | |
| 2987 | bool IsMinusOne() const OVERRIDE { |
| 2988 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2989 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2990 | bool IsArithmeticZero() const OVERRIDE { |
| 2991 | return std::fpclassify(value_) == FP_ZERO; |
| 2992 | } |
| 2993 | bool IsArithmeticPositiveZero() const { |
| 2994 | return IsArithmeticZero() && !std::signbit(value_); |
| 2995 | } |
| 2996 | bool IsArithmeticNegativeZero() const { |
| 2997 | return IsArithmeticZero() && std::signbit(value_); |
| 2998 | } |
| 2999 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3000 | 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] | 3001 | } |
| 3002 | bool IsOne() const OVERRIDE { |
| 3003 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3004 | } |
| 3005 | bool IsNaN() const { |
| 3006 | return std::isnan(value_); |
| 3007 | } |
| 3008 | |
| 3009 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3010 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3011 | protected: |
| 3012 | DEFAULT_COPY_CONSTRUCTOR(DoubleConstant); |
| 3013 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3014 | private: |
| 3015 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3016 | : HConstant(DataType::Type::kFloat64, dex_pc), value_(value) {} |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3017 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3018 | : HConstant(DataType::Type::kFloat64, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3019 | |
| 3020 | const double value_; |
| 3021 | |
| 3022 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3023 | friend class SsaBuilder; |
| 3024 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3025 | }; |
| 3026 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3027 | // Conditional branch. A block ending with an HIf instruction must have |
| 3028 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3029 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3030 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3031 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3032 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3033 | SetRawInputAt(0, input); |
| 3034 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3035 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3036 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3037 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3038 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3039 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3040 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3044 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3045 | } |
| 3046 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3047 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3048 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3049 | protected: |
| 3050 | DEFAULT_COPY_CONSTRUCTOR(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3051 | }; |
| 3052 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3053 | |
| 3054 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 3055 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 3056 | // non-exceptional control flow. |
| 3057 | // Normal-flow successor is stored at index zero, exception handlers under |
| 3058 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3059 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3060 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3061 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3062 | kEntry, |
| 3063 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3064 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3065 | }; |
| 3066 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3067 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3068 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 3069 | SetPackedField<BoundaryKindField>(kind); |
| 3070 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3071 | |
| 3072 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3073 | |
| 3074 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3075 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3076 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 3077 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 3078 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 3079 | } |
| 3080 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3081 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 3082 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3083 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 3084 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 3085 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | // If not present already, adds `handler` to its block's list of exception |
| 3089 | // handlers. |
| 3090 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3091 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3092 | GetBlock()->AddSuccessor(handler); |
| 3093 | } |
| 3094 | } |
| 3095 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3096 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 3097 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3098 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3099 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 3100 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3101 | DECLARE_INSTRUCTION(TryBoundary); |
| 3102 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3103 | protected: |
| 3104 | DEFAULT_COPY_CONSTRUCTOR(TryBoundary); |
| 3105 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3106 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3107 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 3108 | static constexpr size_t kFieldBoundaryKindSize = |
| 3109 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 3110 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 3111 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 3112 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 3113 | "Too many packed fields."); |
| 3114 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3115 | }; |
| 3116 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3117 | // Deoptimize to interpreter, upon checking a condition. |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3118 | class HDeoptimize FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3119 | public: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3120 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 3121 | // across. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3122 | HDeoptimize(ArenaAllocator* allocator, |
| 3123 | HInstruction* cond, |
| 3124 | DeoptimizationKind kind, |
| 3125 | uint32_t dex_pc) |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3126 | : HVariableInputSizeInstruction( |
| 3127 | SideEffects::All(), |
| 3128 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3129 | allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3130 | /* number_of_inputs */ 1, |
| 3131 | kArenaAllocMisc) { |
| 3132 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 3133 | SetPackedField<DeoptimizeKindField>(kind); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3134 | SetRawInputAt(0, cond); |
| 3135 | } |
| 3136 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3137 | bool IsClonable() const OVERRIDE { return true; } |
| 3138 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3139 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3140 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3141 | // instead of `guard`. |
| 3142 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3143 | // at the point of the `HDeoptimize`. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3144 | HDeoptimize(ArenaAllocator* allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3145 | HInstruction* cond, |
| 3146 | HInstruction* guard, |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3147 | DeoptimizationKind kind, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3148 | uint32_t dex_pc) |
| 3149 | : HVariableInputSizeInstruction( |
| 3150 | SideEffects::CanTriggerGC(), |
| 3151 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3152 | allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3153 | /* number_of_inputs */ 2, |
| 3154 | kArenaAllocMisc) { |
| 3155 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3156 | SetPackedField<DeoptimizeKindField>(kind); |
| 3157 | SetRawInputAt(0, cond); |
| 3158 | SetRawInputAt(1, guard); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3159 | } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3160 | |
| 3161 | bool CanBeMoved() const OVERRIDE { return GetPackedFlag<kFieldCanBeMoved>(); } |
| 3162 | |
| 3163 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 3164 | return (other->CanBeMoved() == CanBeMoved()) && (other->AsDeoptimize()->GetKind() == GetKind()); |
| 3165 | } |
| 3166 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3167 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3168 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3169 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3170 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3171 | DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3172 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3173 | DataType::Type GetType() const OVERRIDE { |
| 3174 | return GuardsAnInput() ? GuardedInput()->GetType() : DataType::Type::kVoid; |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | bool GuardsAnInput() const { |
| 3178 | return InputCount() == 2; |
| 3179 | } |
| 3180 | |
| 3181 | HInstruction* GuardedInput() const { |
| 3182 | DCHECK(GuardsAnInput()); |
| 3183 | return InputAt(1); |
| 3184 | } |
| 3185 | |
| 3186 | void RemoveGuard() { |
| 3187 | RemoveInputAt(1); |
| 3188 | } |
| 3189 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3190 | DECLARE_INSTRUCTION(Deoptimize); |
| 3191 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3192 | protected: |
| 3193 | DEFAULT_COPY_CONSTRUCTOR(Deoptimize); |
| 3194 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3195 | private: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3196 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3197 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3198 | static constexpr size_t kFieldDeoptimizeKindSize = |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3199 | MinimumBitsToStore(static_cast<size_t>(DeoptimizationKind::kLast)); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3200 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3201 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3202 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3203 | "Too many packed fields."); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3204 | using DeoptimizeKindField = |
| 3205 | BitField<DeoptimizationKind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3206 | }; |
| 3207 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3208 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3209 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3210 | // if it's true, starts to do deoptimization. |
| 3211 | // It has a 4-byte slot on stack. |
| 3212 | // TODO: allocate a register for this flag. |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3213 | class HShouldDeoptimizeFlag FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3214 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3215 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3216 | // with regard to other passes. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3217 | HShouldDeoptimizeFlag(ArenaAllocator* allocator, uint32_t dex_pc) |
| 3218 | : HVariableInputSizeInstruction(SideEffects::None(), dex_pc, allocator, 0, kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3219 | } |
| 3220 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3221 | DataType::Type GetType() const OVERRIDE { return DataType::Type::kInt32; } |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3222 | |
| 3223 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3224 | // further guard elimination/motion since a guard might have been used for justification |
| 3225 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3226 | // to avoid other optimizations trying to move it. |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3227 | bool CanBeMoved() const OVERRIDE { return false; } |
| 3228 | |
| 3229 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3230 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3231 | protected: |
| 3232 | DEFAULT_COPY_CONSTRUCTOR(ShouldDeoptimizeFlag); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3233 | }; |
| 3234 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3235 | // Represents the ArtMethod that was passed as a first argument to |
| 3236 | // the method. It is used by instructions that depend on it, like |
| 3237 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3238 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3239 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3240 | explicit HCurrentMethod(DataType::Type type, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3241 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3242 | |
| 3243 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3244 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3245 | protected: |
| 3246 | DEFAULT_COPY_CONSTRUCTOR(CurrentMethod); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3247 | }; |
| 3248 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3249 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3250 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3251 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3252 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3253 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3254 | kVTable, |
| 3255 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3256 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3257 | }; |
| 3258 | HClassTableGet(HInstruction* cls, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3259 | DataType::Type type, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3260 | TableKind kind, |
| 3261 | size_t index, |
| 3262 | uint32_t dex_pc) |
| 3263 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3264 | index_(index) { |
| 3265 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3266 | SetRawInputAt(0, cls); |
| 3267 | } |
| 3268 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3269 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3270 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3271 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3272 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3273 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3276 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3277 | size_t GetIndex() const { return index_; } |
| 3278 | |
| 3279 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3280 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3281 | protected: |
| 3282 | DEFAULT_COPY_CONSTRUCTOR(ClassTableGet); |
| 3283 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3284 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3285 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 3286 | static constexpr size_t kFieldTableKindSize = |
| 3287 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3288 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3289 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3290 | "Too many packed fields."); |
| 3291 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3292 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3293 | // The index of the ArtMethod in the table. |
| 3294 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3295 | }; |
| 3296 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3297 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3298 | // have one successor for each entry in the switch table, and the final successor |
| 3299 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3300 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3301 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3302 | HPackedSwitch(int32_t start_value, |
| 3303 | uint32_t num_entries, |
| 3304 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3305 | uint32_t dex_pc = kNoDexPc) |
| 3306 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 3307 | start_value_(start_value), |
| 3308 | num_entries_(num_entries) { |
| 3309 | SetRawInputAt(0, input); |
| 3310 | } |
| 3311 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3312 | bool IsClonable() const OVERRIDE { return true; } |
| 3313 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3314 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3315 | |
| 3316 | int32_t GetStartValue() const { return start_value_; } |
| 3317 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3318 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3319 | |
| 3320 | HBasicBlock* GetDefaultBlock() const { |
| 3321 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3322 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3323 | } |
| 3324 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3325 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3326 | protected: |
| 3327 | DEFAULT_COPY_CONSTRUCTOR(PackedSwitch); |
| 3328 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3329 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3330 | const int32_t start_value_; |
| 3331 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3332 | }; |
| 3333 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3334 | class HUnaryOperation : public HExpression<1> { |
| 3335 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3336 | HUnaryOperation(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3337 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3338 | SetRawInputAt(0, input); |
| 3339 | } |
| 3340 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3341 | // All of the UnaryOperation instructions are clonable. |
| 3342 | bool IsClonable() const OVERRIDE { return true; } |
| 3343 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3344 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3345 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3346 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3347 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3348 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3349 | return true; |
| 3350 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3351 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3352 | // Try to statically evaluate `this` and return a HConstant |
| 3353 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3354 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3355 | HConstant* TryStaticEvaluation() const; |
| 3356 | |
| 3357 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3358 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3359 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3360 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3361 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3362 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3363 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3364 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3365 | protected: |
| 3366 | DEFAULT_COPY_CONSTRUCTOR(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3367 | }; |
| 3368 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3369 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3370 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3371 | HBinaryOperation(DataType::Type result_type, |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3372 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3373 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3374 | SideEffects side_effects = SideEffects::None(), |
| 3375 | uint32_t dex_pc = kNoDexPc) |
| 3376 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3377 | SetRawInputAt(0, left); |
| 3378 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3379 | } |
| 3380 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3381 | // All of the BinaryOperation instructions are clonable. |
| 3382 | bool IsClonable() const OVERRIDE { return true; } |
| 3383 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3384 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3385 | HInstruction* GetRight() const { return InputAt(1); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3386 | DataType::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3387 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3388 | virtual bool IsCommutative() const { return false; } |
| 3389 | |
| 3390 | // Put constant on the right. |
| 3391 | // Returns whether order is changed. |
| 3392 | bool OrderInputsWithConstantOnTheRight() { |
| 3393 | HInstruction* left = InputAt(0); |
| 3394 | HInstruction* right = InputAt(1); |
| 3395 | if (left->IsConstant() && !right->IsConstant()) { |
| 3396 | ReplaceInput(right, 0); |
| 3397 | ReplaceInput(left, 1); |
| 3398 | return true; |
| 3399 | } |
| 3400 | return false; |
| 3401 | } |
| 3402 | |
| 3403 | // Order inputs by instruction id, but favor constant on the right side. |
| 3404 | // This helps GVN for commutative ops. |
| 3405 | void OrderInputs() { |
| 3406 | DCHECK(IsCommutative()); |
| 3407 | HInstruction* left = InputAt(0); |
| 3408 | HInstruction* right = InputAt(1); |
| 3409 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3410 | return; |
| 3411 | } |
| 3412 | if (OrderInputsWithConstantOnTheRight()) { |
| 3413 | return; |
| 3414 | } |
| 3415 | // Order according to instruction id. |
| 3416 | if (left->GetId() > right->GetId()) { |
| 3417 | ReplaceInput(right, 0); |
| 3418 | ReplaceInput(left, 1); |
| 3419 | } |
| 3420 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3421 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3422 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3423 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3424 | return true; |
| 3425 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3426 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3427 | // Try to statically evaluate `this` and return a HConstant |
| 3428 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3429 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3430 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3431 | |
| 3432 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3433 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3434 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3435 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3436 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3437 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3438 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3439 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3440 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3441 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3442 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3443 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3444 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3445 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3446 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3447 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3448 | // 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] | 3449 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3450 | HConstant* GetConstantRight() const; |
| 3451 | |
| 3452 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3453 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3454 | HInstruction* GetLeastConstantLeft() const; |
| 3455 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3456 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3457 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3458 | protected: |
| 3459 | DEFAULT_COPY_CONSTRUCTOR(BinaryOperation); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3460 | }; |
| 3461 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3462 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3463 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3464 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3465 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3466 | kGtBias, // return 1 for NaN comparisons |
| 3467 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3468 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3469 | }; |
| 3470 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3471 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3472 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3473 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3474 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3475 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3476 | : HBinaryOperation(DataType::Type::kBool, first, second, SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3477 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3478 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3479 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3480 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3481 | // `instruction`, and disregard moves in between. |
| 3482 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3483 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3484 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3485 | |
| 3486 | virtual IfCondition GetCondition() const = 0; |
| 3487 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3488 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3489 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3490 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3491 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3492 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3493 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3494 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3495 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3496 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3497 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3498 | } |
| 3499 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3500 | bool IsFPConditionTrueIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3501 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3502 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3503 | if (if_cond == kCondNE) { |
| 3504 | return true; |
| 3505 | } else if (if_cond == kCondEQ) { |
| 3506 | return false; |
| 3507 | } |
| 3508 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | bool IsFPConditionFalseIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3512 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3513 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3514 | if (if_cond == kCondEQ) { |
| 3515 | return true; |
| 3516 | } else if (if_cond == kCondNE) { |
| 3517 | return false; |
| 3518 | } |
| 3519 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3520 | } |
| 3521 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3522 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3523 | // Needed if we merge a HCompare into a HCondition. |
| 3524 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3525 | static constexpr size_t kFieldComparisonBiasSize = |
| 3526 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3527 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3528 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3529 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3530 | using ComparisonBiasField = |
| 3531 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3532 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3533 | template <typename T> |
| 3534 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3535 | |
| 3536 | template <typename T> |
| 3537 | int32_t CompareFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3538 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3539 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3540 | // Handle the bias. |
| 3541 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3542 | } |
| 3543 | |
| 3544 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3545 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3546 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3547 | } |
| 3548 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3549 | DEFAULT_COPY_CONSTRUCTOR(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3550 | }; |
| 3551 | |
| 3552 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3553 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3554 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3555 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3556 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3557 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3558 | bool IsCommutative() const OVERRIDE { return true; } |
| 3559 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3560 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3561 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3562 | return MakeConstantCondition(true, GetDexPc()); |
| 3563 | } |
| 3564 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3565 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3566 | } |
| 3567 | // In the following Evaluate methods, a HCompare instruction has |
| 3568 | // been merged into this HEqual instruction; evaluate it as |
| 3569 | // `Compare(x, y) == 0`. |
| 3570 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3571 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3572 | GetDexPc()); |
| 3573 | } |
| 3574 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3575 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3576 | } |
| 3577 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3578 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3579 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3580 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3581 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3582 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3583 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3584 | return kCondEQ; |
| 3585 | } |
| 3586 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3587 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3588 | return kCondNE; |
| 3589 | } |
| 3590 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3591 | protected: |
| 3592 | DEFAULT_COPY_CONSTRUCTOR(Equal); |
| 3593 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3594 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3595 | 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] | 3596 | }; |
| 3597 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3598 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3599 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3600 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3601 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3602 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3603 | bool IsCommutative() const OVERRIDE { return true; } |
| 3604 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3605 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3606 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3607 | return MakeConstantCondition(false, GetDexPc()); |
| 3608 | } |
| 3609 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3610 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3611 | } |
| 3612 | // In the following Evaluate methods, a HCompare instruction has |
| 3613 | // been merged into this HNotEqual instruction; evaluate it as |
| 3614 | // `Compare(x, y) != 0`. |
| 3615 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3616 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3617 | } |
| 3618 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3619 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3620 | } |
| 3621 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3622 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3623 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3624 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3625 | DECLARE_INSTRUCTION(NotEqual); |
| 3626 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3627 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3628 | return kCondNE; |
| 3629 | } |
| 3630 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3631 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3632 | return kCondEQ; |
| 3633 | } |
| 3634 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3635 | protected: |
| 3636 | DEFAULT_COPY_CONSTRUCTOR(NotEqual); |
| 3637 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3638 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3639 | 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] | 3640 | }; |
| 3641 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3642 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3643 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3644 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3645 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3646 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3647 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3648 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3649 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3650 | // In the following Evaluate methods, a HCompare instruction has |
| 3651 | // been merged into this HLessThan instruction; evaluate it as |
| 3652 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3653 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3654 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3655 | } |
| 3656 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3657 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3658 | } |
| 3659 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3660 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3661 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3662 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3663 | DECLARE_INSTRUCTION(LessThan); |
| 3664 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3665 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3666 | return kCondLT; |
| 3667 | } |
| 3668 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3669 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3670 | return kCondGE; |
| 3671 | } |
| 3672 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3673 | protected: |
| 3674 | DEFAULT_COPY_CONSTRUCTOR(LessThan); |
| 3675 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3676 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3677 | 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] | 3678 | }; |
| 3679 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3680 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3681 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3682 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3683 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3684 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3685 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3686 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3687 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3688 | // In the following Evaluate methods, a HCompare instruction has |
| 3689 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3690 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3691 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3692 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3693 | } |
| 3694 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3695 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3696 | } |
| 3697 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3698 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3699 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3700 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3701 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3702 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3703 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3704 | return kCondLE; |
| 3705 | } |
| 3706 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3707 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3708 | return kCondGT; |
| 3709 | } |
| 3710 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3711 | protected: |
| 3712 | DEFAULT_COPY_CONSTRUCTOR(LessThanOrEqual); |
| 3713 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3714 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3715 | template <typename T> static bool Compute(T x, T y) { return x <= y; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3716 | }; |
| 3717 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3718 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3719 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3720 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3721 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3722 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3723 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3724 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3725 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3726 | // In the following Evaluate methods, a HCompare instruction has |
| 3727 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3728 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3729 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3730 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3731 | } |
| 3732 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3733 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3734 | } |
| 3735 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3736 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3737 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3738 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3739 | DECLARE_INSTRUCTION(GreaterThan); |
| 3740 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3741 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3742 | return kCondGT; |
| 3743 | } |
| 3744 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3745 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3746 | return kCondLE; |
| 3747 | } |
| 3748 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3749 | protected: |
| 3750 | DEFAULT_COPY_CONSTRUCTOR(GreaterThan); |
| 3751 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3752 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3753 | 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] | 3754 | }; |
| 3755 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3756 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3757 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3758 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3759 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3760 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3761 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3762 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3763 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3764 | // In the following Evaluate methods, a HCompare instruction has |
| 3765 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3766 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3767 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3768 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3769 | } |
| 3770 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3771 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3772 | } |
| 3773 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3774 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3775 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3776 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3777 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3778 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3779 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3780 | return kCondGE; |
| 3781 | } |
| 3782 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3783 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3784 | return kCondLT; |
| 3785 | } |
| 3786 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3787 | protected: |
| 3788 | DEFAULT_COPY_CONSTRUCTOR(GreaterThanOrEqual); |
| 3789 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3790 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3791 | 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] | 3792 | }; |
| 3793 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3794 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3795 | public: |
| 3796 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3797 | : HCondition(first, second, dex_pc) {} |
| 3798 | |
| 3799 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3800 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3801 | } |
| 3802 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3803 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3804 | } |
| 3805 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3806 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3807 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3808 | UNREACHABLE(); |
| 3809 | } |
| 3810 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3811 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3812 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3813 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | DECLARE_INSTRUCTION(Below); |
| 3817 | |
| 3818 | IfCondition GetCondition() const OVERRIDE { |
| 3819 | return kCondB; |
| 3820 | } |
| 3821 | |
| 3822 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3823 | return kCondAE; |
| 3824 | } |
| 3825 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3826 | protected: |
| 3827 | DEFAULT_COPY_CONSTRUCTOR(Below); |
| 3828 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3829 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3830 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3831 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3832 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3833 | }; |
| 3834 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3835 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3836 | public: |
| 3837 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3838 | : HCondition(first, second, dex_pc) {} |
| 3839 | |
| 3840 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3841 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3842 | } |
| 3843 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3844 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3845 | } |
| 3846 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3847 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3848 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3849 | UNREACHABLE(); |
| 3850 | } |
| 3851 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3852 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3853 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3854 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3858 | |
| 3859 | IfCondition GetCondition() const OVERRIDE { |
| 3860 | return kCondBE; |
| 3861 | } |
| 3862 | |
| 3863 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3864 | return kCondA; |
| 3865 | } |
| 3866 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3867 | protected: |
| 3868 | DEFAULT_COPY_CONSTRUCTOR(BelowOrEqual); |
| 3869 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3870 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3871 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3872 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3873 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3874 | }; |
| 3875 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3876 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3877 | public: |
| 3878 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3879 | : HCondition(first, second, dex_pc) {} |
| 3880 | |
| 3881 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3882 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3883 | } |
| 3884 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3885 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3886 | } |
| 3887 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3888 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3889 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3890 | UNREACHABLE(); |
| 3891 | } |
| 3892 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3893 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3894 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3895 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | DECLARE_INSTRUCTION(Above); |
| 3899 | |
| 3900 | IfCondition GetCondition() const OVERRIDE { |
| 3901 | return kCondA; |
| 3902 | } |
| 3903 | |
| 3904 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3905 | return kCondBE; |
| 3906 | } |
| 3907 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3908 | protected: |
| 3909 | DEFAULT_COPY_CONSTRUCTOR(Above); |
| 3910 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3911 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3912 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3913 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3914 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3915 | }; |
| 3916 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3917 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3918 | public: |
| 3919 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3920 | : HCondition(first, second, dex_pc) {} |
| 3921 | |
| 3922 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3923 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3924 | } |
| 3925 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3926 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3927 | } |
| 3928 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3929 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3930 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3931 | UNREACHABLE(); |
| 3932 | } |
| 3933 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3934 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3935 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3936 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3940 | |
| 3941 | IfCondition GetCondition() const OVERRIDE { |
| 3942 | return kCondAE; |
| 3943 | } |
| 3944 | |
| 3945 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3946 | return kCondB; |
| 3947 | } |
| 3948 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3949 | protected: |
| 3950 | DEFAULT_COPY_CONSTRUCTOR(AboveOrEqual); |
| 3951 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3952 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3953 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3954 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3955 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3956 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3957 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3958 | // Instruction to check how two inputs compare to each other. |
| 3959 | // 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] | 3960 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3961 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3962 | // Note that `comparison_type` is the type of comparison performed |
| 3963 | // between the comparison's inputs, not the type of the instantiated |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3964 | // HCompare instruction (which is always DataType::Type::kInt). |
| 3965 | HCompare(DataType::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3966 | HInstruction* first, |
| 3967 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3968 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3969 | uint32_t dex_pc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3970 | : HBinaryOperation(DataType::Type::kInt32, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3971 | first, |
| 3972 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3973 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3974 | dex_pc) { |
| 3975 | SetPackedField<ComparisonBiasField>(bias); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3976 | DCHECK_EQ(comparison_type, DataType::Kind(first->GetType())); |
| 3977 | DCHECK_EQ(comparison_type, DataType::Kind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3978 | } |
| 3979 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3980 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3981 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3982 | |
| 3983 | template <typename T> |
| 3984 | int32_t ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3985 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3986 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3987 | // Handle the bias. |
| 3988 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3989 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3990 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3991 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3992 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3993 | // reach this code path when processing a freshly built HIR |
| 3994 | // graph. However HCompare integer instructions can be synthesized |
| 3995 | // by the instruction simplifier to implement IntegerCompare and |
| 3996 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3997 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3998 | } |
| 3999 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4000 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4001 | } |
| 4002 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4003 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4004 | } |
| 4005 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4006 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4007 | } |
| 4008 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4009 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4010 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4011 | } |
| 4012 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4013 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4014 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4015 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4016 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4017 | bool IsGtBias() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4018 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4019 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4020 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4021 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4022 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type type ATTRIBUTE_UNUSED) { |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 4023 | // Comparisons do not require a runtime call in any back end. |
| 4024 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4025 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4026 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4027 | DECLARE_INSTRUCTION(Compare); |
| 4028 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4029 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4030 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 4031 | static constexpr size_t kFieldComparisonBiasSize = |
| 4032 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 4033 | static constexpr size_t kNumberOfComparePackedBits = |
| 4034 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 4035 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4036 | using ComparisonBiasField = |
| 4037 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 4038 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4039 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 4040 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 4041 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 4042 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 4043 | } |
| 4044 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4045 | DEFAULT_COPY_CONSTRUCTOR(Compare); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4046 | }; |
| 4047 | |
Nicolas Geoffray | 2b615ba | 2017-01-06 14:40:07 +0000 | [diff] [blame] | 4048 | class HNewInstance FINAL : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4049 | public: |
| 4050 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4051 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4052 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4053 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4054 | bool finalizable, |
| 4055 | QuickEntrypointEnum entrypoint) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4056 | : HExpression(DataType::Type::kReference, SideEffects::CanTriggerGC(), dex_pc), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4057 | type_index_(type_index), |
| 4058 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4059 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4060 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4061 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4062 | } |
| 4063 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4064 | bool IsClonable() const OVERRIDE { return true; } |
| 4065 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4066 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4067 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4068 | |
| 4069 | // Calls runtime so needs an environment. |
| 4070 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4071 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4072 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 4073 | bool CanThrow() const OVERRIDE { return true; } |
| 4074 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4075 | bool NeedsChecks() const { |
| 4076 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 4077 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4078 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4079 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4080 | |
| 4081 | bool CanBeNull() const OVERRIDE { return false; } |
| 4082 | |
| 4083 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4084 | |
| 4085 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 4086 | entrypoint_ = entrypoint; |
| 4087 | } |
| 4088 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4089 | HLoadClass* GetLoadClass() const { |
| 4090 | HInstruction* input = InputAt(0); |
| 4091 | if (input->IsClinitCheck()) { |
| 4092 | input = input->InputAt(0); |
| 4093 | } |
| 4094 | DCHECK(input->IsLoadClass()); |
| 4095 | return input->AsLoadClass(); |
| 4096 | } |
| 4097 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4098 | bool IsStringAlloc() const; |
| 4099 | |
| 4100 | DECLARE_INSTRUCTION(NewInstance); |
| 4101 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4102 | protected: |
| 4103 | DEFAULT_COPY_CONSTRUCTOR(NewInstance); |
| 4104 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4105 | private: |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4106 | static constexpr size_t kFlagFinalizable = kNumberOfExpressionPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4107 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 4108 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 4109 | "Too many packed fields."); |
| 4110 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4111 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4112 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4113 | QuickEntrypointEnum entrypoint_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4114 | }; |
| 4115 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 4116 | enum IntrinsicNeedsEnvironmentOrCache { |
| 4117 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 4118 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4119 | }; |
| 4120 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4121 | enum IntrinsicSideEffects { |
| 4122 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 4123 | kReadSideEffects, // Intrinsic may read heap memory. |
| 4124 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 4125 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 4126 | }; |
| 4127 | |
| 4128 | enum IntrinsicExceptions { |
| 4129 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 4130 | kCanThrow // Intrinsic may throw exceptions. |
| 4131 | }; |
| 4132 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4133 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4134 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4135 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4136 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 4137 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4138 | SetRawInputAt(index, argument); |
| 4139 | } |
| 4140 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4141 | // Return the number of arguments. This number can be lower than |
| 4142 | // the number of inputs returned by InputCount(), as some invoke |
| 4143 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 4144 | // inputs at the end of their list of inputs. |
| 4145 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 4146 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4147 | DataType::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4148 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4149 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4150 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4151 | InvokeType GetInvokeType() const { |
| 4152 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4153 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4154 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 4155 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4156 | return intrinsic_; |
| 4157 | } |
| 4158 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4159 | void SetIntrinsic(Intrinsics intrinsic, |
| 4160 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 4161 | IntrinsicSideEffects side_effects, |
| 4162 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4163 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4164 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4165 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4166 | } |
| 4167 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4168 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4169 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4170 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4171 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4172 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4173 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4174 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4175 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 4176 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4177 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4178 | uint32_t* GetIntrinsicOptimizations() { |
| 4179 | return &intrinsic_optimizations_; |
| 4180 | } |
| 4181 | |
| 4182 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4183 | return &intrinsic_optimizations_; |
| 4184 | } |
| 4185 | |
| 4186 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4187 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4188 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4189 | void SetResolvedMethod(ArtMethod* method) { resolved_method_ = method; } |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4190 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4191 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4192 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4193 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4194 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4195 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4196 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4197 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4198 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4199 | static constexpr size_t kFieldReturnTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4200 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4201 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 4202 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 4203 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4204 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4205 | using ReturnTypeField = BitField<DataType::Type, kFieldReturnType, kFieldReturnTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4206 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4207 | HInvoke(ArenaAllocator* allocator, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4208 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4209 | uint32_t number_of_other_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4210 | DataType::Type return_type, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4211 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4212 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4213 | ArtMethod* resolved_method, |
| 4214 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4215 | : HVariableInputSizeInstruction( |
| 4216 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4217 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4218 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4219 | number_of_arguments + number_of_other_inputs, |
| 4220 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4221 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4222 | resolved_method_(resolved_method), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4223 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4224 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4225 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4226 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4227 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4228 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4229 | } |
| 4230 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4231 | DEFAULT_COPY_CONSTRUCTOR(Invoke); |
| 4232 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4233 | uint32_t number_of_arguments_; |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4234 | ArtMethod* resolved_method_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4235 | const uint32_t dex_method_index_; |
| 4236 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4237 | |
| 4238 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4239 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4240 | }; |
| 4241 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4242 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4243 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4244 | HInvokeUnresolved(ArenaAllocator* allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4245 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4246 | DataType::Type return_type, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4247 | uint32_t dex_pc, |
| 4248 | uint32_t dex_method_index, |
| 4249 | InvokeType invoke_type) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4250 | : HInvoke(allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4251 | number_of_arguments, |
| 4252 | 0u /* number_of_other_inputs */, |
| 4253 | return_type, |
| 4254 | dex_pc, |
| 4255 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4256 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4257 | invoke_type) { |
| 4258 | } |
| 4259 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4260 | bool IsClonable() const OVERRIDE { return true; } |
| 4261 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4262 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4263 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4264 | protected: |
| 4265 | DEFAULT_COPY_CONSTRUCTOR(InvokeUnresolved); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4266 | }; |
| 4267 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4268 | class HInvokePolymorphic FINAL : public HInvoke { |
| 4269 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4270 | HInvokePolymorphic(ArenaAllocator* allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4271 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4272 | DataType::Type return_type, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4273 | uint32_t dex_pc, |
| 4274 | uint32_t dex_method_index) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4275 | : HInvoke(allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4276 | number_of_arguments, |
| 4277 | 0u /* number_of_other_inputs */, |
| 4278 | return_type, |
| 4279 | dex_pc, |
| 4280 | dex_method_index, |
| 4281 | nullptr, |
| 4282 | kVirtual) {} |
| 4283 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4284 | bool IsClonable() const OVERRIDE { return true; } |
| 4285 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4286 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4287 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4288 | protected: |
| 4289 | DEFAULT_COPY_CONSTRUCTOR(InvokePolymorphic); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4290 | }; |
| 4291 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4292 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4293 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4294 | // Requirements of this method call regarding the class |
| 4295 | // initialization (clinit) check of its declaring class. |
| 4296 | enum class ClinitCheckRequirement { |
| 4297 | kNone, // Class already initialized. |
| 4298 | kExplicit, // Static call having explicit clinit check as last input. |
| 4299 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4300 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4301 | }; |
| 4302 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4303 | // Determines how to load the target ArtMethod*. |
| 4304 | enum class MethodLoadKind { |
| 4305 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4306 | kStringInit, |
| 4307 | |
| 4308 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4309 | kRecursive, |
| 4310 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4311 | // Use PC-relative boot image ArtMethod* address that will be known at link time. |
| 4312 | // Used for boot image methods referenced by boot image code. |
| 4313 | kBootImageLinkTimePcRelative, |
| 4314 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4315 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4316 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 4317 | kDirectAddress, |
| 4318 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4319 | // Load from an entry in the .bss section using a PC-relative load. |
| 4320 | // Used for classes outside boot image when .bss is accessible with a PC-relative load. |
| 4321 | kBssEntry, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4322 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4323 | // Make a runtime call to resolve and call the method. This is the last-resort-kind |
| 4324 | // used when other kinds are unimplemented on a particular architecture. |
| 4325 | kRuntimeCall, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4326 | }; |
| 4327 | |
| 4328 | // Determines the location of the code pointer. |
| 4329 | enum class CodePtrLocation { |
| 4330 | // Recursive call, use local PC-relative call instruction. |
| 4331 | kCallSelf, |
| 4332 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4333 | // Use code pointer from the ArtMethod*. |
| 4334 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4335 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4336 | kCallArtMethod, |
| 4337 | }; |
| 4338 | |
| 4339 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4340 | MethodLoadKind method_load_kind; |
| 4341 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4342 | // The method load data holds |
| 4343 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4344 | // Note that there are multiple string init methods, each having its own offset. |
| 4345 | // - the method address for kDirectAddress |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4346 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4347 | }; |
| 4348 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4349 | HInvokeStaticOrDirect(ArenaAllocator* allocator, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4350 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4351 | DataType::Type return_type, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4352 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4353 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4354 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4355 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4356 | InvokeType invoke_type, |
| 4357 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4358 | ClinitCheckRequirement clinit_check_requirement) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4359 | : HInvoke(allocator, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4360 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4361 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4362 | // potentially one other if the clinit check is explicit, and potentially |
| 4363 | // one other if the method is a string factory. |
| 4364 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4365 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4366 | return_type, |
| 4367 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4368 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4369 | resolved_method, |
| 4370 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4371 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4372 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4373 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4374 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4375 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4376 | bool IsClonable() const OVERRIDE { return true; } |
| 4377 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4378 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4379 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4380 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4381 | |
| 4382 | // Using the current method is the default and once we find a better |
| 4383 | // method load kind, we should not go back to using the current method. |
| 4384 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4385 | |
| 4386 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4387 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4388 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4389 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4390 | dispatch_info_ = dispatch_info; |
| 4391 | } |
| 4392 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 4393 | DispatchInfo GetDispatchInfo() const { |
| 4394 | return dispatch_info_; |
| 4395 | } |
| 4396 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4397 | void AddSpecialInput(HInstruction* input) { |
| 4398 | // We allow only one special input. |
| 4399 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4400 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4401 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4402 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4403 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4404 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4405 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4406 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4407 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4408 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4409 | DCHECK(!input_records.empty()); |
| 4410 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4411 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4412 | // Note: `last_input` may be null during arguments setup. |
| 4413 | if (last_input != nullptr) { |
| 4414 | // `last_input` is the last input of a static invoke marked as having |
| 4415 | // an explicit clinit check. It must either be: |
| 4416 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4417 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4418 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4419 | } |
| 4420 | } |
| 4421 | return input_records; |
| 4422 | } |
| 4423 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4424 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4425 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4426 | // TODO: for intrinsics we can generate implicit null checks. |
| 4427 | return false; |
| 4428 | } |
| 4429 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4430 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4431 | return GetPackedField<ReturnTypeField>() == DataType::Type::kReference && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4432 | } |
| 4433 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4434 | // Get the index of the special input, if any. |
| 4435 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4436 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4437 | // method pointer; otherwise there may be one platform-specific special input, |
| 4438 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4439 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4440 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4441 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4442 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4443 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4444 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4445 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4446 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4447 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4448 | bool HasPcRelativeMethodLoadKind() const { |
| 4449 | return GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4450 | GetMethodLoadKind() == MethodLoadKind::kBssEntry; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4451 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4452 | bool HasCurrentMethodInput() const { |
| 4453 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4454 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4455 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4456 | return true; |
| 4457 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4458 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4459 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4460 | return false; |
| 4461 | } |
| 4462 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4463 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4464 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4465 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4466 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4467 | } |
| 4468 | |
| 4469 | uint64_t GetMethodAddress() const { |
| 4470 | DCHECK(HasMethodAddress()); |
| 4471 | return dispatch_info_.method_load_data; |
| 4472 | } |
| 4473 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4474 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4475 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4476 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4477 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4478 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4479 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4480 | // Is this instruction a call to a static method? |
| 4481 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4482 | return GetInvokeType() == kStatic; |
| 4483 | } |
| 4484 | |
| 4485 | MethodReference GetTargetMethod() const { |
| 4486 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4487 | } |
| 4488 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4489 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4490 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4491 | // instruction; only relevant for static calls with explicit clinit check. |
| 4492 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4493 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4494 | size_t last_input_index = inputs_.size() - 1u; |
| 4495 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4496 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4497 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4498 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4499 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4500 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4501 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | // 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] | 4505 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4506 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4507 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4508 | } |
| 4509 | |
| 4510 | // Is this a call to a static method whose declaring class has an |
| 4511 | // implicit intialization check requirement? |
| 4512 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4513 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4514 | } |
| 4515 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4516 | // Does this method load kind need the current method as an input? |
| 4517 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4518 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kRuntimeCall; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4519 | } |
| 4520 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4521 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4522 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4523 | protected: |
| 4524 | DEFAULT_COPY_CONSTRUCTOR(InvokeStaticOrDirect); |
| 4525 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4526 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4527 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4528 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4529 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4530 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4531 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4532 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4533 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4534 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4535 | kFieldClinitCheckRequirement, |
| 4536 | kFieldClinitCheckRequirementSize>; |
| 4537 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4538 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | MethodReference target_method_; |
| 4540 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4541 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4542 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4543 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4544 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4545 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4546 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4547 | HInvokeVirtual(ArenaAllocator* allocator, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4548 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4549 | DataType::Type return_type, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4550 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4551 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4552 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4553 | uint32_t vtable_index) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4554 | : HInvoke(allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4555 | number_of_arguments, |
| 4556 | 0u, |
| 4557 | return_type, |
| 4558 | dex_pc, |
| 4559 | dex_method_index, |
| 4560 | resolved_method, |
| 4561 | kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4562 | vtable_index_(vtable_index) {} |
| 4563 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4564 | bool IsClonable() const OVERRIDE { return true; } |
| 4565 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4566 | bool CanBeNull() const OVERRIDE { |
| 4567 | switch (GetIntrinsic()) { |
| 4568 | case Intrinsics::kThreadCurrentThread: |
| 4569 | case Intrinsics::kStringBufferAppend: |
| 4570 | case Intrinsics::kStringBufferToString: |
| 4571 | case Intrinsics::kStringBuilderAppend: |
| 4572 | case Intrinsics::kStringBuilderToString: |
| 4573 | return false; |
| 4574 | default: |
| 4575 | return HInvoke::CanBeNull(); |
| 4576 | } |
| 4577 | } |
| 4578 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4579 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4580 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4581 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4582 | } |
| 4583 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4584 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4585 | |
| 4586 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4587 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4588 | protected: |
| 4589 | DEFAULT_COPY_CONSTRUCTOR(InvokeVirtual); |
| 4590 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4591 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4592 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4593 | const uint32_t vtable_index_; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4594 | }; |
| 4595 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4596 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4597 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4598 | HInvokeInterface(ArenaAllocator* allocator, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4599 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4600 | DataType::Type return_type, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4601 | uint32_t dex_pc, |
| 4602 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4603 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4604 | uint32_t imt_index) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4605 | : HInvoke(allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4606 | number_of_arguments, |
| 4607 | 0u, |
| 4608 | return_type, |
| 4609 | dex_pc, |
| 4610 | dex_method_index, |
| 4611 | resolved_method, |
| 4612 | kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4613 | imt_index_(imt_index) {} |
| 4614 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4615 | bool IsClonable() const OVERRIDE { return true; } |
| 4616 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4617 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4618 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4619 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4620 | } |
| 4621 | |
Nicolas Geoffray | fbdfa6d | 2017-02-03 10:43:13 +0000 | [diff] [blame] | 4622 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 4623 | // The assembly stub currently needs it. |
| 4624 | return true; |
| 4625 | } |
| 4626 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4627 | uint32_t GetImtIndex() const { return imt_index_; } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4628 | |
| 4629 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4630 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4631 | protected: |
| 4632 | DEFAULT_COPY_CONSTRUCTOR(InvokeInterface); |
| 4633 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4634 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4635 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4636 | const uint32_t imt_index_; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4637 | }; |
| 4638 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4639 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4640 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4641 | HNeg(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4642 | : HUnaryOperation(result_type, input, dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4643 | DCHECK_EQ(result_type, DataType::Kind(input->GetType())); |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4644 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4645 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4646 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4647 | |
| 4648 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4649 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4650 | } |
| 4651 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4652 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4653 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4654 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4655 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4656 | } |
| 4657 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4658 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4659 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4660 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4661 | DECLARE_INSTRUCTION(Neg); |
| 4662 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4663 | protected: |
| 4664 | DEFAULT_COPY_CONSTRUCTOR(Neg); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4665 | }; |
| 4666 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4667 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4668 | public: |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4669 | HNewArray(HInstruction* cls, HInstruction* length, uint32_t dex_pc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4670 | : HExpression(DataType::Type::kReference, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4671 | SetRawInputAt(0, cls); |
| 4672 | SetRawInputAt(1, length); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4673 | } |
| 4674 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4675 | bool IsClonable() const OVERRIDE { return true; } |
| 4676 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4677 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4678 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4679 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4680 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4681 | bool CanThrow() const OVERRIDE { return true; } |
| 4682 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4683 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4684 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4685 | HLoadClass* GetLoadClass() const { |
| 4686 | DCHECK(InputAt(0)->IsLoadClass()); |
| 4687 | return InputAt(0)->AsLoadClass(); |
| 4688 | } |
| 4689 | |
| 4690 | HInstruction* GetLength() const { |
| 4691 | return InputAt(1); |
| 4692 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4693 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4694 | DECLARE_INSTRUCTION(NewArray); |
| 4695 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4696 | protected: |
| 4697 | DEFAULT_COPY_CONSTRUCTOR(NewArray); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4698 | }; |
| 4699 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4700 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4701 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4702 | HAdd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4703 | HInstruction* left, |
| 4704 | HInstruction* right, |
| 4705 | uint32_t dex_pc = kNoDexPc) |
| 4706 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4707 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4708 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4709 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4710 | 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] | 4711 | |
| 4712 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4713 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4714 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4715 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4716 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4717 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4718 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4719 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4720 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4721 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4722 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4723 | } |
| 4724 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4725 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4726 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4727 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4728 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4729 | DECLARE_INSTRUCTION(Add); |
| 4730 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4731 | protected: |
| 4732 | DEFAULT_COPY_CONSTRUCTOR(Add); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4733 | }; |
| 4734 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4735 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4736 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4737 | HSub(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4738 | HInstruction* left, |
| 4739 | HInstruction* right, |
| 4740 | uint32_t dex_pc = kNoDexPc) |
| 4741 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4742 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4743 | 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] | 4744 | |
| 4745 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4746 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4747 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4748 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4749 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4750 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4751 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4752 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4753 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4754 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4755 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4756 | } |
| 4757 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4758 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4759 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4760 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4761 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4762 | DECLARE_INSTRUCTION(Sub); |
| 4763 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4764 | protected: |
| 4765 | DEFAULT_COPY_CONSTRUCTOR(Sub); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4766 | }; |
| 4767 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4768 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4769 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4770 | HMul(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4771 | HInstruction* left, |
| 4772 | HInstruction* right, |
| 4773 | uint32_t dex_pc = kNoDexPc) |
| 4774 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4775 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4776 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4777 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4778 | 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] | 4779 | |
| 4780 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4781 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4782 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4783 | } |
| 4784 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4785 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4786 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4787 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4788 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4789 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4790 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4791 | } |
| 4792 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4793 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4794 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4795 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4796 | |
| 4797 | DECLARE_INSTRUCTION(Mul); |
| 4798 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4799 | protected: |
| 4800 | DEFAULT_COPY_CONSTRUCTOR(Mul); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4801 | }; |
| 4802 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4803 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4804 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4805 | HDiv(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4806 | HInstruction* left, |
| 4807 | HInstruction* right, |
| 4808 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4809 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4810 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4811 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4812 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4813 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4814 | // Our graph structure ensures we never have 0 for `y` during |
| 4815 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4816 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4817 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4818 | return (y == -1) ? -x : x / y; |
| 4819 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4820 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4821 | template <typename T> |
| 4822 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4823 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4824 | return x / y; |
| 4825 | } |
| 4826 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4827 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4828 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4829 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4830 | } |
| 4831 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4832 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4833 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4834 | } |
| 4835 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4836 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4837 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4838 | } |
| 4839 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4840 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4841 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4842 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4843 | |
| 4844 | DECLARE_INSTRUCTION(Div); |
| 4845 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4846 | protected: |
| 4847 | DEFAULT_COPY_CONSTRUCTOR(Div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4848 | }; |
| 4849 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4850 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4851 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4852 | HRem(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4853 | HInstruction* left, |
| 4854 | HInstruction* right, |
| 4855 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4856 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4857 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4858 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4859 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4860 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4861 | // Our graph structure ensures we never have 0 for `y` during |
| 4862 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4863 | DCHECK_NE(y, 0); |
| 4864 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4865 | return (y == -1) ? 0 : x % y; |
| 4866 | } |
| 4867 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4868 | template <typename T> |
| 4869 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4870 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4871 | return std::fmod(x, y); |
| 4872 | } |
| 4873 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4874 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4875 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4876 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4877 | } |
| 4878 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4879 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4880 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4881 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4882 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4883 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4884 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4885 | } |
| 4886 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4887 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4888 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4889 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4890 | |
| 4891 | DECLARE_INSTRUCTION(Rem); |
| 4892 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4893 | protected: |
| 4894 | DEFAULT_COPY_CONSTRUCTOR(Rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4895 | }; |
| 4896 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4897 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4898 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4899 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4900 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4901 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4902 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4903 | SetRawInputAt(0, value); |
| 4904 | } |
| 4905 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4906 | DataType::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4907 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4908 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4909 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4910 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4911 | return true; |
| 4912 | } |
| 4913 | |
| 4914 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4915 | bool CanThrow() const OVERRIDE { return true; } |
| 4916 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4917 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4918 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4919 | protected: |
| 4920 | DEFAULT_COPY_CONSTRUCTOR(DivZeroCheck); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4921 | }; |
| 4922 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4923 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4924 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4925 | HShl(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4926 | HInstruction* value, |
| 4927 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4928 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4929 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4930 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 4931 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4932 | } |
| 4933 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4934 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4935 | 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] | 4936 | return value << (distance & max_shift_distance); |
| 4937 | } |
| 4938 | |
| 4939 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4940 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4941 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4942 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4943 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4944 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4945 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4946 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4947 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4948 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4949 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4950 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4951 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4952 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4953 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4954 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4955 | UNREACHABLE(); |
| 4956 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4957 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4958 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4959 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4960 | UNREACHABLE(); |
| 4961 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4962 | |
| 4963 | DECLARE_INSTRUCTION(Shl); |
| 4964 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4965 | protected: |
| 4966 | DEFAULT_COPY_CONSTRUCTOR(Shl); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4967 | }; |
| 4968 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4969 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4970 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4971 | HShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4972 | HInstruction* value, |
| 4973 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4974 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4975 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4976 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 4977 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4978 | } |
| 4979 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4980 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4981 | 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] | 4982 | return value >> (distance & max_shift_distance); |
| 4983 | } |
| 4984 | |
| 4985 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4986 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4987 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4988 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4989 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4990 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4991 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4992 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4993 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4994 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4995 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4996 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4997 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4998 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4999 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5000 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5001 | UNREACHABLE(); |
| 5002 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5003 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5004 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5005 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5006 | UNREACHABLE(); |
| 5007 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5008 | |
| 5009 | DECLARE_INSTRUCTION(Shr); |
| 5010 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5011 | protected: |
| 5012 | DEFAULT_COPY_CONSTRUCTOR(Shr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5013 | }; |
| 5014 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5015 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5016 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5017 | HUShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5018 | HInstruction* value, |
| 5019 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5020 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5021 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5022 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5023 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5024 | } |
| 5025 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5026 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5027 | 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] | 5028 | typedef typename std::make_unsigned<T>::type V; |
| 5029 | V ux = static_cast<V>(value); |
| 5030 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 5031 | } |
| 5032 | |
| 5033 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5034 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5035 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5036 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5037 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5038 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5039 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5040 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5041 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5042 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5043 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5044 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5045 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5046 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5047 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5048 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5049 | UNREACHABLE(); |
| 5050 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5051 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5052 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5053 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5054 | UNREACHABLE(); |
| 5055 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5056 | |
| 5057 | DECLARE_INSTRUCTION(UShr); |
| 5058 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5059 | protected: |
| 5060 | DEFAULT_COPY_CONSTRUCTOR(UShr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5061 | }; |
| 5062 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5063 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5064 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5065 | HAnd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5066 | HInstruction* left, |
| 5067 | HInstruction* right, |
| 5068 | uint32_t dex_pc = kNoDexPc) |
| 5069 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5070 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5071 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5072 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5073 | 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] | 5074 | |
| 5075 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5076 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5077 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5078 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5079 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5080 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5081 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5082 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5083 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5084 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5085 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5086 | UNREACHABLE(); |
| 5087 | } |
| 5088 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5089 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5090 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5091 | UNREACHABLE(); |
| 5092 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5093 | |
| 5094 | DECLARE_INSTRUCTION(And); |
| 5095 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5096 | protected: |
| 5097 | DEFAULT_COPY_CONSTRUCTOR(And); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5098 | }; |
| 5099 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5100 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5101 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5102 | HOr(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5103 | HInstruction* left, |
| 5104 | HInstruction* right, |
| 5105 | uint32_t dex_pc = kNoDexPc) |
| 5106 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5107 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5108 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5109 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5110 | 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] | 5111 | |
| 5112 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5113 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5114 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5115 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5116 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5117 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5118 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5119 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5120 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5121 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5122 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5123 | UNREACHABLE(); |
| 5124 | } |
| 5125 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5126 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5127 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5128 | UNREACHABLE(); |
| 5129 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5130 | |
| 5131 | DECLARE_INSTRUCTION(Or); |
| 5132 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5133 | protected: |
| 5134 | DEFAULT_COPY_CONSTRUCTOR(Or); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5135 | }; |
| 5136 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5137 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5138 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5139 | HXor(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5140 | HInstruction* left, |
| 5141 | HInstruction* right, |
| 5142 | uint32_t dex_pc = kNoDexPc) |
| 5143 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5144 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5145 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5146 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5147 | 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] | 5148 | |
| 5149 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5150 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5151 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5152 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5153 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5154 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5155 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5156 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5157 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5158 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5159 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5160 | UNREACHABLE(); |
| 5161 | } |
| 5162 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5163 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5164 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5165 | UNREACHABLE(); |
| 5166 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5167 | |
| 5168 | DECLARE_INSTRUCTION(Xor); |
| 5169 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5170 | protected: |
| 5171 | DEFAULT_COPY_CONSTRUCTOR(Xor); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5172 | }; |
| 5173 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5174 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5175 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5176 | HRor(DataType::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5177 | : HBinaryOperation(result_type, value, distance) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5178 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5179 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5180 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5181 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5182 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5183 | 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] | 5184 | typedef typename std::make_unsigned<T>::type V; |
| 5185 | V ux = static_cast<V>(value); |
| 5186 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5187 | return static_cast<T>(ux); |
| 5188 | } else { |
| 5189 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5190 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 5191 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5192 | } |
| 5193 | } |
| 5194 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5195 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5196 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5197 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5198 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5199 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5200 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5201 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5202 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5203 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5204 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5205 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5206 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5207 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5208 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5209 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5210 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5211 | UNREACHABLE(); |
| 5212 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5213 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5214 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5215 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5216 | UNREACHABLE(); |
| 5217 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5218 | |
| 5219 | DECLARE_INSTRUCTION(Ror); |
| 5220 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5221 | protected: |
| 5222 | DEFAULT_COPY_CONSTRUCTOR(Ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5223 | }; |
| 5224 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5225 | // The value of a parameter in this method. Its location depends on |
| 5226 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5227 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5228 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5229 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5230 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5231 | uint8_t index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5232 | DataType::Type parameter_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5233 | bool is_this = false) |
| 5234 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5235 | dex_file_(dex_file), |
| 5236 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5237 | index_(index) { |
| 5238 | SetPackedFlag<kFlagIsThis>(is_this); |
| 5239 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 5240 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5241 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5242 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5243 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5244 | uint8_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5245 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5246 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5247 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 5248 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5249 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5250 | DECLARE_INSTRUCTION(ParameterValue); |
| 5251 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5252 | protected: |
| 5253 | DEFAULT_COPY_CONSTRUCTOR(ParameterValue); |
| 5254 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5255 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5256 | // Whether or not the parameter value corresponds to 'this' argument. |
| 5257 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 5258 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 5259 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 5260 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 5261 | "Too many packed fields."); |
| 5262 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5263 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5264 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5265 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5266 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5267 | const uint8_t index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5268 | }; |
| 5269 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5270 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5271 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5272 | HNot(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5273 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5274 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5275 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5276 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5277 | return true; |
| 5278 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5279 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5280 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5281 | |
| 5282 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5283 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5284 | } |
| 5285 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5286 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5287 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5288 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5289 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5290 | UNREACHABLE(); |
| 5291 | } |
| 5292 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5293 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5294 | UNREACHABLE(); |
| 5295 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5296 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5297 | DECLARE_INSTRUCTION(Not); |
| 5298 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5299 | protected: |
| 5300 | DEFAULT_COPY_CONSTRUCTOR(Not); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5301 | }; |
| 5302 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5303 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5304 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5305 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5306 | : HUnaryOperation(DataType::Type::kBool, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5307 | |
| 5308 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5309 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5310 | return true; |
| 5311 | } |
| 5312 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5313 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5314 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5315 | return !x; |
| 5316 | } |
| 5317 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5318 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5319 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5320 | } |
| 5321 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5322 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5323 | UNREACHABLE(); |
| 5324 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5325 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5326 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5327 | UNREACHABLE(); |
| 5328 | } |
| 5329 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5330 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5331 | UNREACHABLE(); |
| 5332 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5333 | |
| 5334 | DECLARE_INSTRUCTION(BooleanNot); |
| 5335 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5336 | protected: |
| 5337 | DEFAULT_COPY_CONSTRUCTOR(BooleanNot); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5338 | }; |
| 5339 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5340 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5341 | public: |
| 5342 | // Instantiate a type conversion of `input` to `result_type`. |
Vladimir Marko | c8fb211 | 2017-10-03 11:37:52 +0100 | [diff] [blame] | 5343 | HTypeConversion(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5344 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5345 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5346 | // Invariant: We should never generate a conversion to a Boolean value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5347 | DCHECK_NE(DataType::Type::kBool, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5351 | DataType::Type GetInputType() const { return GetInput()->GetType(); } |
| 5352 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5353 | |
| 5354 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5355 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5356 | return true; |
| 5357 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5358 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5359 | // Try to statically evaluate the conversion and return a HConstant |
| 5360 | // containing the result. If the input cannot be converted, return nullptr. |
| 5361 | HConstant* TryStaticEvaluation() const; |
| 5362 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5363 | DECLARE_INSTRUCTION(TypeConversion); |
| 5364 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5365 | protected: |
| 5366 | DEFAULT_COPY_CONSTRUCTOR(TypeConversion); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5367 | }; |
| 5368 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5369 | static constexpr uint32_t kNoRegNumber = -1; |
| 5370 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5371 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5372 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5373 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 5374 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5375 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5376 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5377 | SetRawInputAt(0, value); |
| 5378 | } |
| 5379 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5380 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5381 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5382 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5383 | return true; |
| 5384 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5385 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5386 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5387 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5388 | bool CanThrow() const OVERRIDE { return true; } |
| 5389 | |
| 5390 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5391 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5392 | DECLARE_INSTRUCTION(NullCheck); |
| 5393 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5394 | protected: |
| 5395 | DEFAULT_COPY_CONSTRUCTOR(NullCheck); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5396 | }; |
| 5397 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5398 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5399 | // 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] | 5400 | class FieldInfo : public ValueObject { |
| 5401 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5402 | FieldInfo(ArtField* field, |
| 5403 | MemberOffset field_offset, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5404 | DataType::Type field_type, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5405 | bool is_volatile, |
| 5406 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5407 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5408 | const DexFile& dex_file) |
| 5409 | : field_(field), |
| 5410 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5411 | field_type_(field_type), |
| 5412 | is_volatile_(is_volatile), |
| 5413 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5414 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5415 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5416 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5417 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5418 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5419 | DataType::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5420 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5421 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5422 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5423 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5424 | |
| 5425 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5426 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5427 | const MemberOffset field_offset_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5428 | const DataType::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5429 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5430 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5431 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5432 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5433 | }; |
| 5434 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5435 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5436 | public: |
| 5437 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5438 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5439 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5440 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5441 | bool is_volatile, |
| 5442 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5443 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5444 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5445 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5446 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5447 | field_info_(field, |
| 5448 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5449 | field_type, |
| 5450 | is_volatile, |
| 5451 | field_idx, |
| 5452 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5453 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5454 | SetRawInputAt(0, value); |
| 5455 | } |
| 5456 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5457 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5458 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5459 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5460 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5461 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5462 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5463 | } |
| 5464 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5465 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5466 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5470 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5471 | } |
| 5472 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5473 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5474 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5475 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5476 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5477 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5478 | void SetType(DataType::Type new_type) { |
| 5479 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5480 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5481 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5482 | SetPackedField<TypeField>(new_type); |
| 5483 | } |
| 5484 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5485 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5486 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5487 | protected: |
| 5488 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldGet); |
| 5489 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5490 | private: |
| 5491 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5492 | }; |
| 5493 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5494 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5495 | public: |
| 5496 | HInstanceFieldSet(HInstruction* object, |
| 5497 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5498 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5499 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5500 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5501 | bool is_volatile, |
| 5502 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5503 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5504 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5505 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5506 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5507 | field_info_(field, |
| 5508 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5509 | field_type, |
| 5510 | is_volatile, |
| 5511 | field_idx, |
| 5512 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5513 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5514 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5515 | SetRawInputAt(0, object); |
| 5516 | SetRawInputAt(1, value); |
| 5517 | } |
| 5518 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5519 | bool IsClonable() const OVERRIDE { return true; } |
| 5520 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5521 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5522 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5525 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5526 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5527 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5528 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5529 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5530 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5531 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5532 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5533 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5534 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5535 | protected: |
| 5536 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldSet); |
| 5537 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5538 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5539 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5540 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5541 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5542 | "Too many packed fields."); |
| 5543 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5544 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5545 | }; |
| 5546 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5547 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5548 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5549 | HArrayGet(HInstruction* array, |
| 5550 | HInstruction* index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5551 | DataType::Type type, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5552 | uint32_t dex_pc) |
| 5553 | : HArrayGet(array, |
| 5554 | index, |
| 5555 | type, |
| 5556 | SideEffects::ArrayReadOfType(type), |
| 5557 | dex_pc, |
| 5558 | /* is_string_char_at */ false) {} |
| 5559 | |
| 5560 | HArrayGet(HInstruction* array, |
| 5561 | HInstruction* index, |
| 5562 | DataType::Type type, |
| 5563 | SideEffects side_effects, |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5564 | uint32_t dex_pc, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5565 | bool is_string_char_at) |
| 5566 | : HExpression(type, side_effects, dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5567 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5568 | SetRawInputAt(0, array); |
| 5569 | SetRawInputAt(1, index); |
| 5570 | } |
| 5571 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5572 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5573 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5574 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5575 | return true; |
| 5576 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5577 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5578 | // TODO: We can be smarter here. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5579 | // Currently, unless the array is the result of NewArray, the array access is always |
| 5580 | // preceded by some form of null NullCheck necessary for the bounds check, usually |
| 5581 | // implicit null check on the ArrayLength input to BoundsCheck or Deoptimize for |
| 5582 | // dynamic BCE. There are cases when these could be removed to produce better code. |
| 5583 | // If we ever add optimizations to do so we should allow an implicit check here |
| 5584 | // (as long as the address falls in the first page). |
| 5585 | // |
| 5586 | // As an example of such fancy optimization, we could eliminate BoundsCheck for |
| 5587 | // a = cond ? new int[1] : null; |
| 5588 | // a[0]; // The Phi does not need bounds check for either input. |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5589 | return false; |
| 5590 | } |
| 5591 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5592 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5593 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5594 | if (kIsDebugBuild && result) { |
| 5595 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5596 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5597 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5598 | if (DataType::IsIntOrLongType(GetType())) { |
| 5599 | DCHECK(DataType::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5600 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5601 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| 5602 | DCHECK(DataType::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5603 | } |
| 5604 | } |
| 5605 | return result; |
| 5606 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5607 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5608 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5609 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5610 | HInstruction* GetArray() const { return InputAt(0); } |
| 5611 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5612 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5613 | void SetType(DataType::Type new_type) { |
| 5614 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5615 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5616 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5617 | SetPackedField<TypeField>(new_type); |
| 5618 | } |
| 5619 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5620 | DECLARE_INSTRUCTION(ArrayGet); |
| 5621 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5622 | protected: |
| 5623 | DEFAULT_COPY_CONSTRUCTOR(ArrayGet); |
| 5624 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5625 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5626 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5627 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5628 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5629 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5630 | // a flag, so that code generators don't need to do the locking. |
| 5631 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5632 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5633 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5634 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5635 | }; |
| 5636 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5637 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5638 | public: |
| 5639 | HArraySet(HInstruction* array, |
| 5640 | HInstruction* index, |
| 5641 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5642 | DataType::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5643 | uint32_t dex_pc) |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5644 | : HArraySet(array, |
| 5645 | index, |
| 5646 | value, |
| 5647 | expected_component_type, |
| 5648 | // Make a best guess for side effects now, may be refined during SSA building. |
| 5649 | ComputeSideEffects(GetComponentType(value->GetType(), expected_component_type)), |
| 5650 | dex_pc) {} |
| 5651 | |
| 5652 | HArraySet(HInstruction* array, |
| 5653 | HInstruction* index, |
| 5654 | HInstruction* value, |
| 5655 | DataType::Type expected_component_type, |
| 5656 | SideEffects side_effects, |
| 5657 | uint32_t dex_pc) |
| 5658 | : HTemplateInstruction(side_effects, dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5659 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5660 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5661 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5662 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5663 | SetRawInputAt(0, array); |
| 5664 | SetRawInputAt(1, index); |
| 5665 | SetRawInputAt(2, value); |
| 5666 | } |
| 5667 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5668 | bool IsClonable() const OVERRIDE { return true; } |
| 5669 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5670 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5671 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5672 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5673 | } |
| 5674 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5675 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5676 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5677 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5678 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5679 | // TODO: Same as for ArrayGet. |
| 5680 | return false; |
| 5681 | } |
| 5682 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5683 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5684 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5685 | } |
| 5686 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5687 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5688 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5689 | } |
| 5690 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5691 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5692 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5693 | } |
| 5694 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5695 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5696 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5697 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5698 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5699 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5700 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5701 | HInstruction* GetArray() const { return InputAt(0); } |
| 5702 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5703 | HInstruction* GetValue() const { return InputAt(2); } |
| 5704 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5705 | DataType::Type GetComponentType() const { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5706 | return GetComponentType(GetValue()->GetType(), GetRawExpectedComponentType()); |
| 5707 | } |
| 5708 | |
| 5709 | static DataType::Type GetComponentType(DataType::Type value_type, |
| 5710 | DataType::Type expected_component_type) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5711 | // The Dex format does not type floating point index operations. Since the |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5712 | // `expected_component_type` comes from SSA building and can therefore not |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5713 | // be correct, we also check what is the value type. If it is a floating |
| 5714 | // point type, we must use that type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5715 | return ((value_type == DataType::Type::kFloat32) || (value_type == DataType::Type::kFloat64)) |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5716 | ? value_type |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5717 | : expected_component_type; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5718 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5719 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5720 | DataType::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5721 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5722 | } |
| 5723 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5724 | static SideEffects ComputeSideEffects(DataType::Type type) { |
| 5725 | return SideEffects::ArrayWriteOfType(type).Union(SideEffectsForArchRuntimeCalls(type)); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5726 | } |
| 5727 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5728 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type value_type) { |
| 5729 | return (value_type == DataType::Type::kReference) ? SideEffects::CanTriggerGC() |
| 5730 | : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5731 | } |
| 5732 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5733 | DECLARE_INSTRUCTION(ArraySet); |
| 5734 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5735 | protected: |
| 5736 | DEFAULT_COPY_CONSTRUCTOR(ArraySet); |
| 5737 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5738 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5739 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5740 | static constexpr size_t kFieldExpectedComponentTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5741 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5742 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5743 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5744 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5745 | // Cached information for the reference_type_info_ so that codegen |
| 5746 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5747 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5748 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5749 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5750 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5751 | using ExpectedComponentTypeField = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5752 | BitField<DataType::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5753 | }; |
| 5754 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5755 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5756 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5757 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5758 | : HExpression(DataType::Type::kInt32, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5759 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5760 | // Note that arrays do not change length, so the instruction does not |
| 5761 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5762 | SetRawInputAt(0, array); |
| 5763 | } |
| 5764 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5765 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5766 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5767 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5768 | return true; |
| 5769 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5770 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5771 | return obj == InputAt(0); |
| 5772 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5773 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5774 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5775 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5776 | DECLARE_INSTRUCTION(ArrayLength); |
| 5777 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5778 | protected: |
| 5779 | DEFAULT_COPY_CONSTRUCTOR(ArrayLength); |
| 5780 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5781 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5782 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5783 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5784 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5785 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5786 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5787 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5788 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5789 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5790 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5791 | }; |
| 5792 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5793 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5794 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5795 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5796 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5797 | HBoundsCheck(HInstruction* index, |
| 5798 | HInstruction* length, |
| 5799 | uint32_t dex_pc, |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 5800 | bool is_string_char_at = false) |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5801 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5802 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(index->GetType())); |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 5803 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5804 | SetRawInputAt(0, index); |
| 5805 | SetRawInputAt(1, length); |
| 5806 | } |
| 5807 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5808 | bool IsClonable() const OVERRIDE { return true; } |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5809 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5810 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5811 | return true; |
| 5812 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5813 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5814 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5815 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5816 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5817 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5818 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5819 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5820 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5821 | |
| 5822 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5823 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5824 | protected: |
| 5825 | DEFAULT_COPY_CONSTRUCTOR(BoundsCheck); |
| 5826 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5827 | private: |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5828 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5829 | }; |
| 5830 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5831 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5832 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5833 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5834 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5835 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5836 | bool IsClonable() const OVERRIDE { return true; } |
| 5837 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5838 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5839 | return true; |
| 5840 | } |
| 5841 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5842 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5843 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5844 | |
| 5845 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5846 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5847 | protected: |
| 5848 | DEFAULT_COPY_CONSTRUCTOR(SuspendCheck); |
| 5849 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5850 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5851 | // Only used for code generation, in order to share the same slow path between back edges |
| 5852 | // of a same loop. |
| 5853 | SlowPathCode* slow_path_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5854 | }; |
| 5855 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5856 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5857 | // It ensures that we can generate line number and local variables at this point. |
| 5858 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5859 | public: |
| 5860 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5861 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5862 | |
| 5863 | bool NeedsEnvironment() const OVERRIDE { |
| 5864 | return true; |
| 5865 | } |
| 5866 | |
| 5867 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5868 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5869 | protected: |
| 5870 | DEFAULT_COPY_CONSTRUCTOR(NativeDebugInfo); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5871 | }; |
| 5872 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5873 | /** |
| 5874 | * Instruction to load a Class object. |
| 5875 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5876 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5877 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5878 | // Determines how to load the Class. |
| 5879 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5880 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 5881 | kInvalid = -1, |
| 5882 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5883 | // Use the Class* from the method's own ArtMethod*. |
| 5884 | kReferrersClass, |
| 5885 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5886 | // 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] | 5887 | // Used for boot image classes referenced by boot image code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5888 | kBootImageLinkTimePcRelative, |
| 5889 | |
| 5890 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5891 | // 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] | 5892 | kBootImageAddress, |
| 5893 | |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5894 | // Use a PC-relative load from a boot image ClassTable mmapped into the .bss |
| 5895 | // of the oat file. |
| 5896 | kBootImageClassTable, |
| 5897 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5898 | // Load from an entry in the .bss section using a PC-relative load. |
| 5899 | // Used for classes outside boot image when .bss is accessible with a PC-relative load. |
| 5900 | kBssEntry, |
| 5901 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5902 | // Load from the root table associated with the JIT compiled method. |
| 5903 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5904 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5905 | // Load using a simple runtime call. This is the fall-back load kind when |
| 5906 | // the codegen is unable to use another appropriate kind. |
| 5907 | kRuntimeCall, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5908 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5909 | kLast = kRuntimeCall |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5910 | }; |
| 5911 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5912 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5913 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5914 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5915 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5916 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5917 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5918 | bool needs_access_check) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5919 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5920 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5921 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5922 | dex_file_(dex_file), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5923 | klass_(klass), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5924 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5925 | // Referrers class should not need access check. We never inline unverified |
| 5926 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5927 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5928 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5929 | SetPackedField<LoadKindField>( |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5930 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kRuntimeCall); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5931 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5932 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5933 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5934 | } |
| 5935 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5936 | bool IsClonable() const OVERRIDE { return true; } |
| 5937 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5938 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5939 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5940 | LoadKind GetLoadKind() const { |
| 5941 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5942 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5943 | |
| 5944 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5945 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5946 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5947 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5948 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5949 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5950 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5951 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5952 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5953 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5954 | } |
| 5955 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5956 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5957 | // The entrypoint the code generator is going to call does not do |
| 5958 | // clinit of the class. |
| 5959 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5960 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5961 | } |
| 5962 | |
| 5963 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5964 | return NeedsAccessCheck() || |
| 5965 | MustGenerateClinitCheck() || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5966 | GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5967 | GetLoadKind() == LoadKind::kBssEntry; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5968 | } |
| 5969 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5970 | bool CanThrow() const OVERRIDE { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5971 | return NeedsAccessCheck() || |
| 5972 | MustGenerateClinitCheck() || |
| 5973 | // If the class is in the boot image, the lookup in the runtime call cannot throw. |
| 5974 | // This keeps CanThrow() consistent between non-PIC (using kBootImageAddress) and |
| 5975 | // PIC and subsequently avoids a DCE behavior dependency on the PIC option. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5976 | ((GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5977 | GetLoadKind() == LoadKind::kBssEntry) && |
| 5978 | !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5979 | } |
| 5980 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5981 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5982 | return loaded_class_rti_; |
| 5983 | } |
| 5984 | |
| 5985 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5986 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5987 | DCHECK(rti.IsExact()); |
| 5988 | loaded_class_rti_ = rti; |
| 5989 | } |
| 5990 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5991 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5992 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5993 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5994 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5995 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5996 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5997 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5998 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5999 | return SideEffects::CanTriggerGC(); |
| 6000 | } |
| 6001 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6002 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6003 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6004 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6005 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6006 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6007 | void MarkInBootImage() { |
| 6008 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 6009 | } |
| 6010 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6011 | void AddSpecialInput(HInstruction* special_input); |
| 6012 | |
| 6013 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6014 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6015 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6016 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6017 | } |
| 6018 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6019 | DataType::Type GetType() const OVERRIDE { |
| 6020 | return DataType::Type::kReference; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6021 | } |
| 6022 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6023 | Handle<mirror::Class> GetClass() const { |
| 6024 | return klass_; |
| 6025 | } |
| 6026 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6027 | DECLARE_INSTRUCTION(LoadClass); |
| 6028 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6029 | protected: |
| 6030 | DEFAULT_COPY_CONSTRUCTOR(LoadClass); |
| 6031 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6032 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6033 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6034 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6035 | // Whether this instruction must generate the initialization check. |
| 6036 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6037 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6038 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 6039 | static constexpr size_t kFieldLoadKindSize = |
| 6040 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 6041 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6042 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6043 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 6044 | |
| 6045 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6046 | return load_kind == LoadKind::kReferrersClass || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6047 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6048 | load_kind == LoadKind::kBootImageClassTable || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6049 | load_kind == LoadKind::kBssEntry || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6050 | load_kind == LoadKind::kRuntimeCall; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6051 | } |
| 6052 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6053 | void SetLoadKindInternal(LoadKind load_kind); |
| 6054 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6055 | // The special input is the HCurrentMethod for kRuntimeCall or kReferrersClass. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6056 | // 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] | 6057 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6058 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6059 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6060 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 6061 | // - The compiling method's dex file if the class is defined there too. |
| 6062 | // - The compiling method's dex file if the class is referenced there. |
| 6063 | // - 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] | 6064 | // kBssEntry or kRuntimeCall, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6065 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6066 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6067 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6068 | Handle<mirror::Class> klass_; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6069 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6070 | ReferenceTypeInfo loaded_class_rti_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6071 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6072 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 6073 | |
| 6074 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6075 | inline void HLoadClass::SetLoadKind(LoadKind load_kind) { |
| 6076 | // The load kind should be determined before inserting the instruction to the graph. |
| 6077 | DCHECK(GetBlock() == nullptr); |
| 6078 | DCHECK(GetEnvironment() == nullptr); |
| 6079 | SetPackedField<LoadKindField>(load_kind); |
| 6080 | if (load_kind != LoadKind::kRuntimeCall && load_kind != LoadKind::kReferrersClass) { |
| 6081 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6082 | } |
| 6083 | if (!NeedsEnvironment()) { |
| 6084 | SetSideEffects(SideEffects::None()); |
| 6085 | } |
| 6086 | } |
| 6087 | |
| 6088 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6089 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6090 | // The special input is used for PC-relative loads on some architectures, |
| 6091 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6092 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6093 | GetLoadKind() == LoadKind::kBootImageAddress || |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6094 | GetLoadKind() == LoadKind::kBootImageClassTable || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6095 | GetLoadKind() == LoadKind::kBssEntry) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6096 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6097 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 6098 | special_input->AddUseAt(this, 0); |
| 6099 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6100 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6101 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6102 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6103 | // Determines how to load the String. |
| 6104 | enum class LoadKind { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6105 | // 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] | 6106 | // Used for boot image strings referenced by boot image code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6107 | kBootImageLinkTimePcRelative, |
| 6108 | |
| 6109 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 6110 | // 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] | 6111 | kBootImageAddress, |
| 6112 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6113 | // Use a PC-relative load from a boot image InternTable mmapped into the .bss |
| 6114 | // of the oat file. |
| 6115 | kBootImageInternTable, |
| 6116 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6117 | // Load from an entry in the .bss section using a PC-relative load. |
| 6118 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 6119 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6120 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6121 | // Load from the root table associated with the JIT compiled method. |
| 6122 | kJitTableAddress, |
| 6123 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6124 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6125 | // the codegen is unable to use another appropriate kind. |
| 6126 | kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6127 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6128 | kLast = kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6129 | }; |
| 6130 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6131 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6132 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6133 | const DexFile& dex_file, |
| 6134 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6135 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 6136 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6137 | string_index_(string_index), |
| 6138 | dex_file_(dex_file) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6139 | SetPackedField<LoadKindField>(LoadKind::kRuntimeCall); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6140 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6141 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6142 | bool IsClonable() const OVERRIDE { return true; } |
| 6143 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6144 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6145 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6146 | LoadKind GetLoadKind() const { |
| 6147 | return GetPackedField<LoadKindField>(); |
| 6148 | } |
| 6149 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6150 | const DexFile& GetDexFile() const { |
| 6151 | return dex_file_; |
| 6152 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6153 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6154 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6155 | return string_index_; |
| 6156 | } |
| 6157 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6158 | Handle<mirror::String> GetString() const { |
| 6159 | return string_; |
| 6160 | } |
| 6161 | |
| 6162 | void SetString(Handle<mirror::String> str) { |
| 6163 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6164 | } |
| 6165 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6166 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6167 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6168 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6169 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6170 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6171 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6172 | // Will call the runtime if we need to load the string through |
| 6173 | // the dex cache and the string is not guaranteed to be there yet. |
| 6174 | bool NeedsEnvironment() const OVERRIDE { |
| 6175 | LoadKind load_kind = GetLoadKind(); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6176 | if (load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6177 | load_kind == LoadKind::kBootImageAddress || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6178 | load_kind == LoadKind::kBootImageInternTable || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6179 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6180 | return false; |
| 6181 | } |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6182 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6183 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6184 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6185 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6186 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6187 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6188 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 6189 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6190 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6191 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6192 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6193 | return SideEffects::CanTriggerGC(); |
| 6194 | } |
| 6195 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6196 | void AddSpecialInput(HInstruction* special_input); |
| 6197 | |
| 6198 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6199 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6200 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6201 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6202 | } |
| 6203 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6204 | DataType::Type GetType() const OVERRIDE { |
| 6205 | return DataType::Type::kReference; |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6206 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6207 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6208 | DECLARE_INSTRUCTION(LoadString); |
| 6209 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6210 | protected: |
| 6211 | DEFAULT_COPY_CONSTRUCTOR(LoadString); |
| 6212 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6213 | private: |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6214 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6215 | static constexpr size_t kFieldLoadKindSize = |
| 6216 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 6217 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6218 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6219 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6220 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6221 | void SetLoadKindInternal(LoadKind load_kind); |
| 6222 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6223 | // The special input is the HCurrentMethod for kRuntimeCall. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6224 | // 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] | 6225 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6226 | HUserRecord<HInstruction*> special_input_; |
| 6227 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6228 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6229 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6230 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6231 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6232 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6233 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 6234 | |
| 6235 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6236 | inline void HLoadString::SetLoadKind(LoadKind load_kind) { |
| 6237 | // The load kind should be determined before inserting the instruction to the graph. |
| 6238 | DCHECK(GetBlock() == nullptr); |
| 6239 | DCHECK(GetEnvironment() == nullptr); |
| 6240 | DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); |
| 6241 | SetPackedField<LoadKindField>(load_kind); |
| 6242 | if (load_kind != LoadKind::kRuntimeCall) { |
| 6243 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6244 | } |
| 6245 | if (!NeedsEnvironment()) { |
| 6246 | SetSideEffects(SideEffects::None()); |
| 6247 | } |
| 6248 | } |
| 6249 | |
| 6250 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6251 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6252 | // The special input is used for PC-relative loads on some architectures, |
| 6253 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6254 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6255 | GetLoadKind() == LoadKind::kBootImageAddress || |
| 6256 | GetLoadKind() == LoadKind::kBootImageInternTable || |
| 6257 | GetLoadKind() == LoadKind::kBssEntry) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6258 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 6259 | // so use the GetInputRecords() from the base class to set the input record. |
| 6260 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6261 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6262 | special_input->AddUseAt(this, 0); |
| 6263 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6264 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6265 | /** |
| 6266 | * Performs an initialization check on its Class object input. |
| 6267 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6268 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6269 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 6270 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 6271 | : HExpression( |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6272 | DataType::Type::kReference, |
Mingyao Yang | 217eb06 | 2017-12-11 15:20:07 -0800 | [diff] [blame] | 6273 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6274 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6275 | SetRawInputAt(0, constant); |
| 6276 | } |
| 6277 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6278 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6279 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6280 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6281 | return true; |
| 6282 | } |
| 6283 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6284 | bool NeedsEnvironment() const OVERRIDE { |
| 6285 | // May call runtime to initialize the class. |
| 6286 | return true; |
| 6287 | } |
| 6288 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 6289 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6290 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6291 | HLoadClass* GetLoadClass() const { |
| 6292 | DCHECK(InputAt(0)->IsLoadClass()); |
| 6293 | return InputAt(0)->AsLoadClass(); |
| 6294 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6295 | |
| 6296 | DECLARE_INSTRUCTION(ClinitCheck); |
| 6297 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6298 | |
| 6299 | protected: |
| 6300 | DEFAULT_COPY_CONSTRUCTOR(ClinitCheck); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6301 | }; |
| 6302 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6303 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6304 | public: |
| 6305 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6306 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6307 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6308 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6309 | bool is_volatile, |
| 6310 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6311 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6312 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6313 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 6314 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6315 | field_info_(field, |
| 6316 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6317 | field_type, |
| 6318 | is_volatile, |
| 6319 | field_idx, |
| 6320 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6321 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6322 | SetRawInputAt(0, cls); |
| 6323 | } |
| 6324 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6325 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6326 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 6327 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6328 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6329 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 6330 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6331 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6332 | } |
| 6333 | |
| 6334 | size_t ComputeHashCode() const OVERRIDE { |
| 6335 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6336 | } |
| 6337 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6338 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6339 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6340 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6341 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6342 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6343 | void SetType(DataType::Type new_type) { |
| 6344 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6345 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6346 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6347 | SetPackedField<TypeField>(new_type); |
| 6348 | } |
| 6349 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6350 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 6351 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6352 | protected: |
| 6353 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldGet); |
| 6354 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6355 | private: |
| 6356 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6357 | }; |
| 6358 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6359 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6360 | public: |
| 6361 | HStaticFieldSet(HInstruction* cls, |
| 6362 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6363 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6364 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6365 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6366 | bool is_volatile, |
| 6367 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6368 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6369 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6370 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 6371 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6372 | field_info_(field, |
| 6373 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6374 | field_type, |
| 6375 | is_volatile, |
| 6376 | field_idx, |
| 6377 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6378 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6379 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6380 | SetRawInputAt(0, cls); |
| 6381 | SetRawInputAt(1, value); |
| 6382 | } |
| 6383 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6384 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6385 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6386 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6387 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6388 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6389 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6390 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6391 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6392 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6393 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6394 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6395 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6396 | protected: |
| 6397 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldSet); |
| 6398 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6399 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6400 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6401 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6402 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6403 | "Too many packed fields."); |
| 6404 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6405 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6406 | }; |
| 6407 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6408 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6409 | public: |
| 6410 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6411 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6412 | uint32_t field_index, |
| 6413 | uint32_t dex_pc) |
| 6414 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6415 | field_index_(field_index) { |
| 6416 | SetRawInputAt(0, obj); |
| 6417 | } |
| 6418 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6419 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6420 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6421 | bool CanThrow() const OVERRIDE { return true; } |
| 6422 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6423 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6424 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6425 | |
| 6426 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6427 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6428 | protected: |
| 6429 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldGet); |
| 6430 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6431 | private: |
| 6432 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6433 | }; |
| 6434 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6435 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6436 | public: |
| 6437 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6438 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6439 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6440 | uint32_t field_index, |
| 6441 | uint32_t dex_pc) |
| 6442 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6443 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6444 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6445 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6446 | SetRawInputAt(0, obj); |
| 6447 | SetRawInputAt(1, value); |
| 6448 | } |
| 6449 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6450 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6451 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6452 | bool CanThrow() const OVERRIDE { return true; } |
| 6453 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6454 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6455 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6456 | |
| 6457 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6458 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6459 | protected: |
| 6460 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldSet); |
| 6461 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6462 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6463 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6464 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6465 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6466 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6467 | kFieldFieldType + kFieldFieldTypeSize; |
| 6468 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6469 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6470 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6471 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6472 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6473 | }; |
| 6474 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6475 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6476 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6477 | HUnresolvedStaticFieldGet(DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6478 | uint32_t field_index, |
| 6479 | uint32_t dex_pc) |
| 6480 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6481 | field_index_(field_index) { |
| 6482 | } |
| 6483 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6484 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6485 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6486 | bool CanThrow() const OVERRIDE { return true; } |
| 6487 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6488 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6489 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6490 | |
| 6491 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6492 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6493 | protected: |
| 6494 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldGet); |
| 6495 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6496 | private: |
| 6497 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6498 | }; |
| 6499 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6500 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6501 | public: |
| 6502 | HUnresolvedStaticFieldSet(HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6503 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6504 | uint32_t field_index, |
| 6505 | uint32_t dex_pc) |
| 6506 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6507 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6508 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6509 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6510 | SetRawInputAt(0, value); |
| 6511 | } |
| 6512 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6513 | bool IsClonable() const OVERRIDE { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6514 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6515 | bool CanThrow() const OVERRIDE { return true; } |
| 6516 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6517 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6518 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6519 | |
| 6520 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6521 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6522 | protected: |
| 6523 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldSet); |
| 6524 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6525 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6526 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6527 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6528 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6529 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6530 | kFieldFieldType + kFieldFieldTypeSize; |
| 6531 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6532 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6533 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6534 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6535 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6536 | }; |
| 6537 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6538 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6539 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6540 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6541 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6542 | : HExpression(DataType::Type::kReference, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6543 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6544 | bool CanBeNull() const OVERRIDE { return false; } |
| 6545 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6546 | DECLARE_INSTRUCTION(LoadException); |
| 6547 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6548 | protected: |
| 6549 | DEFAULT_COPY_CONSTRUCTOR(LoadException); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6550 | }; |
| 6551 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6552 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6553 | // 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] | 6554 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6555 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6556 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6557 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6558 | |
| 6559 | DECLARE_INSTRUCTION(ClearException); |
| 6560 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6561 | protected: |
| 6562 | DEFAULT_COPY_CONSTRUCTOR(ClearException); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6563 | }; |
| 6564 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6565 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6566 | public: |
| 6567 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6568 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6569 | SetRawInputAt(0, exception); |
| 6570 | } |
| 6571 | |
| 6572 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6573 | |
| 6574 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6575 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6576 | bool CanThrow() const OVERRIDE { return true; } |
| 6577 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6578 | DECLARE_INSTRUCTION(Throw); |
| 6579 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6580 | protected: |
| 6581 | DEFAULT_COPY_CONSTRUCTOR(Throw); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6582 | }; |
| 6583 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6584 | /** |
| 6585 | * Implementation strategies for the code generator of a HInstanceOf |
| 6586 | * or `HCheckCast`. |
| 6587 | */ |
| 6588 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6589 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6590 | kExactCheck, // Can do a single class compare. |
| 6591 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6592 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6593 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6594 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6595 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6596 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6597 | }; |
| 6598 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6599 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6600 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6601 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6602 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6603 | HInstanceOf(HInstruction* object, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6604 | HLoadClass* target_class, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6605 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6606 | uint32_t dex_pc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6607 | : HExpression(DataType::Type::kBool, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6608 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6609 | dex_pc) { |
| 6610 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6611 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6612 | SetRawInputAt(0, object); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6613 | SetRawInputAt(1, target_class); |
| 6614 | } |
| 6615 | |
| 6616 | HLoadClass* GetTargetClass() const { |
| 6617 | HInstruction* load_class = InputAt(1); |
| 6618 | DCHECK(load_class->IsLoadClass()); |
| 6619 | return load_class->AsLoadClass(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6620 | } |
| 6621 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6622 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6623 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6624 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6625 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6626 | return true; |
| 6627 | } |
| 6628 | |
| 6629 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6630 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6631 | } |
| 6632 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6633 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6634 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6635 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6636 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6637 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6638 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6639 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6640 | // Mips currently does runtime calls for any other checks. |
| 6641 | return check_kind != TypeCheckKind::kExactCheck; |
| 6642 | } |
| 6643 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6644 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6645 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6646 | } |
| 6647 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6648 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6649 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6650 | protected: |
| 6651 | DEFAULT_COPY_CONSTRUCTOR(InstanceOf); |
| 6652 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6653 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6654 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6655 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6656 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6657 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6658 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6659 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6660 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6661 | }; |
| 6662 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6663 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6664 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6665 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6666 | : HExpression(DataType::Type::kReference, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6667 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6668 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6669 | SetPackedFlag<kFlagCanBeNull>(true); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6670 | DCHECK_EQ(input->GetType(), DataType::Type::kReference); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6671 | SetRawInputAt(0, input); |
| 6672 | } |
| 6673 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6674 | bool IsClonable() const OVERRIDE { return true; } |
| 6675 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6676 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6677 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6678 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6679 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6680 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6681 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6682 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6683 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6684 | } |
| 6685 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6686 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6687 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6688 | DECLARE_INSTRUCTION(BoundType); |
| 6689 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6690 | protected: |
| 6691 | DEFAULT_COPY_CONSTRUCTOR(BoundType); |
| 6692 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6693 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6694 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6695 | // is false then CanBeNull() cannot be true). |
| 6696 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6697 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6698 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6699 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6700 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6701 | // 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] | 6702 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6703 | // It is used to bound the type in cases like: |
| 6704 | // if (x instanceof ClassX) { |
| 6705 | // // uper_bound_ will be ClassX |
| 6706 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6707 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6708 | }; |
| 6709 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6710 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6711 | public: |
| 6712 | HCheckCast(HInstruction* object, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6713 | HLoadClass* target_class, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6714 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6715 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6716 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6717 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6718 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6719 | SetRawInputAt(0, object); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6720 | SetRawInputAt(1, target_class); |
| 6721 | } |
| 6722 | |
| 6723 | HLoadClass* GetTargetClass() const { |
| 6724 | HInstruction* load_class = InputAt(1); |
| 6725 | DCHECK(load_class->IsLoadClass()); |
| 6726 | return load_class->AsLoadClass(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6727 | } |
| 6728 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6729 | bool IsClonable() const OVERRIDE { return true; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6730 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6731 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6732 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6733 | return true; |
| 6734 | } |
| 6735 | |
| 6736 | bool NeedsEnvironment() const OVERRIDE { |
| 6737 | // Instruction may throw a CheckCastError. |
| 6738 | return true; |
| 6739 | } |
| 6740 | |
| 6741 | bool CanThrow() const OVERRIDE { return true; } |
| 6742 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6743 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6744 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6745 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6746 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6747 | |
| 6748 | DECLARE_INSTRUCTION(CheckCast); |
| 6749 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6750 | protected: |
| 6751 | DEFAULT_COPY_CONSTRUCTOR(CheckCast); |
| 6752 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6753 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6754 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6755 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6756 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6757 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6758 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6759 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6760 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6761 | }; |
| 6762 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6763 | /** |
| 6764 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6765 | * @details We define the combined barrier types that are actually required |
| 6766 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6767 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6768 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6769 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6770 | * The current recipe is as follows: |
| 6771 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6772 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6773 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6774 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6775 | * class has final fields. |
| 6776 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6777 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6778 | */ |
| 6779 | enum MemBarrierKind { |
| 6780 | kAnyStore, |
| 6781 | kLoadAny, |
| 6782 | kStoreStore, |
| 6783 | kAnyAny, |
| 6784 | kNTStoreStore, |
| 6785 | kLastBarrierKind = kNTStoreStore |
| 6786 | }; |
| 6787 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6788 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6789 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6790 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6791 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6792 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6793 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6794 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6795 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6796 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6797 | bool IsClonable() const OVERRIDE { return true; } |
| 6798 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6799 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6800 | |
| 6801 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6802 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6803 | protected: |
| 6804 | DEFAULT_COPY_CONSTRUCTOR(MemoryBarrier); |
| 6805 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6806 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6807 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6808 | static constexpr size_t kFieldBarrierKindSize = |
| 6809 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6810 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6811 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6812 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6813 | "Too many packed fields."); |
| 6814 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6815 | }; |
| 6816 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6817 | // A constructor fence orders all prior stores to fields that could be accessed via a final field of |
| 6818 | // the specified object(s), with respect to any subsequent store that might "publish" |
| 6819 | // (i.e. make visible) the specified object to another thread. |
| 6820 | // |
| 6821 | // JLS 17.5.1 "Semantics of final fields" states that a freeze action happens |
| 6822 | // for all final fields (that were set) at the end of the invoked constructor. |
| 6823 | // |
| 6824 | // The constructor fence models the freeze actions for the final fields of an object |
| 6825 | // being constructed (semantically at the end of the constructor). Constructor fences |
| 6826 | // have a per-object affinity; two separate objects being constructed get two separate |
| 6827 | // constructor fences. |
| 6828 | // |
| 6829 | // (Note: that if calling a super-constructor or forwarding to another constructor, |
| 6830 | // the freezes would happen at the end of *that* constructor being invoked). |
| 6831 | // |
| 6832 | // The memory model guarantees that when the object being constructed is "published" after |
| 6833 | // constructor completion (i.e. escapes the current thread via a store), then any final field |
| 6834 | // writes must be observable on other threads (once they observe that publication). |
| 6835 | // |
| 6836 | // Further, anything written before the freeze, and read by dereferencing through the final field, |
| 6837 | // must also be visible (so final object field could itself have an object with non-final fields; |
| 6838 | // yet the freeze must also extend to them). |
| 6839 | // |
| 6840 | // Constructor example: |
| 6841 | // |
| 6842 | // class HasFinal { |
| 6843 | // final int field; Optimizing IR for <init>()V: |
| 6844 | // HasFinal() { |
| 6845 | // field = 123; HInstanceFieldSet(this, HasFinal.field, 123) |
| 6846 | // // freeze(this.field); HConstructorFence(this) |
| 6847 | // } HReturn |
| 6848 | // } |
| 6849 | // |
| 6850 | // HConstructorFence can serve double duty as a fence for new-instance/new-array allocations of |
| 6851 | // already-initialized classes; in that case the allocation must act as a "default-initializer" |
| 6852 | // of the object which effectively writes the class pointer "final field". |
| 6853 | // |
| 6854 | // For example, we can model default-initialiation as roughly the equivalent of the following: |
| 6855 | // |
| 6856 | // class Object { |
| 6857 | // private final Class header; |
| 6858 | // } |
| 6859 | // |
| 6860 | // Java code: Optimizing IR: |
| 6861 | // |
| 6862 | // T new_instance<T>() { |
| 6863 | // Object obj = allocate_memory(T.class.size); obj = HInvoke(art_quick_alloc_object, T) |
| 6864 | // obj.header = T.class; // header write is done by above call. |
| 6865 | // // freeze(obj.header) HConstructorFence(obj) |
| 6866 | // return (T)obj; |
| 6867 | // } |
| 6868 | // |
| 6869 | // See also: |
| 6870 | // * CompilerDriver::RequiresConstructorBarrier |
| 6871 | // * QuasiAtomic::ThreadFenceForConstructor |
| 6872 | // |
| 6873 | class HConstructorFence FINAL : public HVariableInputSizeInstruction { |
| 6874 | // A fence has variable inputs because the inputs can be removed |
| 6875 | // after prepare_for_register_allocation phase. |
| 6876 | // (TODO: In the future a fence could freeze multiple objects |
| 6877 | // after merging two fences together.) |
| 6878 | public: |
| 6879 | // `fence_object` is the reference that needs to be protected for correct publication. |
| 6880 | // |
| 6881 | // It makes sense in the following situations: |
| 6882 | // * <init> constructors, it's the "this" parameter (i.e. HParameterValue, s.t. IsThis() == true). |
| 6883 | // * new-instance-like instructions, it's the return value (i.e. HNewInstance). |
| 6884 | // |
| 6885 | // After construction the `fence_object` becomes the 0th input. |
| 6886 | // This is not an input in a real sense, but just a convenient place to stash the information |
| 6887 | // about the associated object. |
| 6888 | HConstructorFence(HInstruction* fence_object, |
| 6889 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 6890 | ArenaAllocator* allocator) |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6891 | // We strongly suspect there is not a more accurate way to describe the fine-grained reordering |
| 6892 | // constraints described in the class header. We claim that these SideEffects constraints |
| 6893 | // enforce a superset of the real constraints. |
| 6894 | // |
| 6895 | // The ordering described above is conservatively modeled with SideEffects as follows: |
| 6896 | // |
| 6897 | // * To prevent reordering of the publication stores: |
| 6898 | // ----> "Reads of objects" is the initial SideEffect. |
| 6899 | // * For every primitive final field store in the constructor: |
| 6900 | // ----> Union that field's type as a read (e.g. "Read of T") into the SideEffect. |
| 6901 | // * If there are any stores to reference final fields in the constructor: |
| 6902 | // ----> Use a more conservative "AllReads" SideEffect because any stores to any references |
| 6903 | // that are reachable from `fence_object` also need to be prevented for reordering |
| 6904 | // (and we do not want to do alias analysis to figure out what those stores are). |
| 6905 | // |
| 6906 | // In the implementation, this initially starts out as an "all reads" side effect; this is an |
| 6907 | // even more conservative approach than the one described above, and prevents all of the |
| 6908 | // above reordering without analyzing any of the instructions in the constructor. |
| 6909 | // |
| 6910 | // If in a later phase we discover that there are no writes to reference final fields, |
| 6911 | // we can refine the side effect to a smaller set of type reads (see above constraints). |
| 6912 | : HVariableInputSizeInstruction(SideEffects::AllReads(), |
| 6913 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 6914 | allocator, |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6915 | /* number_of_inputs */ 1, |
| 6916 | kArenaAllocConstructorFenceInputs) { |
| 6917 | DCHECK(fence_object != nullptr); |
| 6918 | SetRawInputAt(0, fence_object); |
| 6919 | } |
| 6920 | |
| 6921 | // The object associated with this constructor fence. |
| 6922 | // |
| 6923 | // (Note: This will be null after the prepare_for_register_allocation phase, |
| 6924 | // as all constructor fence inputs are removed there). |
| 6925 | HInstruction* GetFenceObject() const { |
| 6926 | return InputAt(0); |
| 6927 | } |
| 6928 | |
| 6929 | // Find all the HConstructorFence uses (`fence_use`) for `this` and: |
| 6930 | // - Delete `fence_use` from `this`'s use list. |
| 6931 | // - Delete `this` from `fence_use`'s inputs list. |
| 6932 | // - If the `fence_use` is dead, remove it from the graph. |
| 6933 | // |
| 6934 | // A fence is considered dead once it no longer has any uses |
| 6935 | // and all of the inputs are dead. |
| 6936 | // |
| 6937 | // This must *not* be called during/after prepare_for_register_allocation, |
| 6938 | // because that removes all the inputs to the fences but the fence is actually |
| 6939 | // still considered live. |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 6940 | // |
| 6941 | // Returns how many HConstructorFence instructions were removed from graph. |
| 6942 | static size_t RemoveConstructorFences(HInstruction* instruction); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6943 | |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 6944 | // Combine all inputs of `this` and `other` instruction and remove |
| 6945 | // `other` from the graph. |
| 6946 | // |
| 6947 | // Inputs are unique after the merge. |
| 6948 | // |
| 6949 | // Requirement: `this` must not be the same as `other. |
| 6950 | void Merge(HConstructorFence* other); |
| 6951 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 6952 | // Check if this constructor fence is protecting |
| 6953 | // an HNewInstance or HNewArray that is also the immediate |
| 6954 | // predecessor of `this`. |
| 6955 | // |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 6956 | // If `ignore_inputs` is true, then the immediate predecessor doesn't need |
| 6957 | // to be one of the inputs of `this`. |
| 6958 | // |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 6959 | // Returns the associated HNewArray or HNewInstance, |
| 6960 | // or null otherwise. |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 6961 | HInstruction* GetAssociatedAllocation(bool ignore_inputs = false); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 6962 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6963 | DECLARE_INSTRUCTION(ConstructorFence); |
| 6964 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6965 | protected: |
| 6966 | DEFAULT_COPY_CONSTRUCTOR(ConstructorFence); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6967 | }; |
| 6968 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6969 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6970 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6971 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6972 | kEnter, |
| 6973 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6974 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6975 | }; |
| 6976 | |
| 6977 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6978 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6979 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6980 | dex_pc) { |
| 6981 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6982 | SetRawInputAt(0, object); |
| 6983 | } |
| 6984 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6985 | // Instruction may go into runtime, so we need an environment. |
| 6986 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6987 | |
| 6988 | bool CanThrow() const OVERRIDE { |
| 6989 | // Verifier guarantees that monitor-exit cannot throw. |
| 6990 | // This is important because it allows the HGraphBuilder to remove |
| 6991 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6992 | return IsEnter(); |
| 6993 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6994 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6995 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6996 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6997 | |
| 6998 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6999 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7000 | protected: |
| 7001 | DEFAULT_COPY_CONSTRUCTOR(MonitorOperation); |
| 7002 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7003 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7004 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 7005 | static constexpr size_t kFieldOperationKindSize = |
| 7006 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 7007 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 7008 | kFieldOperationKind + kFieldOperationKindSize; |
| 7009 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7010 | "Too many packed fields."); |
| 7011 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7012 | }; |
| 7013 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 7014 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7015 | public: |
| 7016 | HSelect(HInstruction* condition, |
| 7017 | HInstruction* true_value, |
| 7018 | HInstruction* false_value, |
| 7019 | uint32_t dex_pc) |
| 7020 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 7021 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 7022 | |
| 7023 | // First input must be `true_value` or `false_value` to allow codegens to |
| 7024 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 7025 | // that architectures which implement HSelect as a conditional move also |
| 7026 | // will not need to invert the condition. |
| 7027 | SetRawInputAt(0, false_value); |
| 7028 | SetRawInputAt(1, true_value); |
| 7029 | SetRawInputAt(2, condition); |
| 7030 | } |
| 7031 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7032 | bool IsClonable() const OVERRIDE { return true; } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7033 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 7034 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 7035 | HInstruction* GetCondition() const { return InputAt(2); } |
| 7036 | |
| 7037 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7038 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 7039 | return true; |
| 7040 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7041 | |
| 7042 | bool CanBeNull() const OVERRIDE { |
| 7043 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 7044 | } |
| 7045 | |
| 7046 | DECLARE_INSTRUCTION(Select); |
| 7047 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7048 | protected: |
| 7049 | DEFAULT_COPY_CONSTRUCTOR(Select); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7050 | }; |
| 7051 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 7052 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7053 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7054 | MoveOperands(Location source, |
| 7055 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7056 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7057 | HInstruction* instruction) |
| 7058 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7059 | |
| 7060 | Location GetSource() const { return source_; } |
| 7061 | Location GetDestination() const { return destination_; } |
| 7062 | |
| 7063 | void SetSource(Location value) { source_ = value; } |
| 7064 | void SetDestination(Location value) { destination_ = value; } |
| 7065 | |
| 7066 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 7067 | // destination (but not the source). |
| 7068 | Location MarkPending() { |
| 7069 | DCHECK(!IsPending()); |
| 7070 | Location dest = destination_; |
| 7071 | destination_ = Location::NoLocation(); |
| 7072 | return dest; |
| 7073 | } |
| 7074 | |
| 7075 | void ClearPending(Location dest) { |
| 7076 | DCHECK(IsPending()); |
| 7077 | destination_ = dest; |
| 7078 | } |
| 7079 | |
| 7080 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7081 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 7082 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7083 | } |
| 7084 | |
| 7085 | // True if this blocks a move from the given location. |
| 7086 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 7087 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7088 | } |
| 7089 | |
| 7090 | // A move is redundant if it's been eliminated, if its source and |
| 7091 | // destination are the same, or if its destination is unneeded. |
| 7092 | bool IsRedundant() const { |
| 7093 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 7094 | } |
| 7095 | |
| 7096 | // We clear both operands to indicate move that's been eliminated. |
| 7097 | void Eliminate() { |
| 7098 | source_ = destination_ = Location::NoLocation(); |
| 7099 | } |
| 7100 | |
| 7101 | bool IsEliminated() const { |
| 7102 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 7103 | return source_.IsInvalid(); |
| 7104 | } |
| 7105 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7106 | DataType::Type GetType() const { return type_; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7107 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7108 | bool Is64BitMove() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7109 | return DataType::Is64BitType(type_); |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7110 | } |
| 7111 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7112 | HInstruction* GetInstruction() const { return instruction_; } |
| 7113 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7114 | private: |
| 7115 | Location source_; |
| 7116 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7117 | // The type this move is for. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7118 | DataType::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7119 | // The instruction this move is assocatied with. Null when this move is |
| 7120 | // for moving an input in the expected locations of user (including a phi user). |
| 7121 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 7122 | // in the same parallel move. |
| 7123 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7124 | }; |
| 7125 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7126 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 7127 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7128 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 7129 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 7130 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7131 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7132 | explicit HParallelMove(ArenaAllocator* allocator, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7133 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7134 | moves_(allocator->Adapter(kArenaAllocMoveOperands)) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7135 | moves_.reserve(kDefaultNumberOfMoves); |
| 7136 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7137 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7138 | void AddMove(Location source, |
| 7139 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7140 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7141 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 7142 | DCHECK(source.IsValid()); |
| 7143 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7144 | if (kIsDebugBuild) { |
| 7145 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7146 | for (const MoveOperands& move : moves_) { |
| 7147 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7148 | // Special case the situation where the move is for the spill slot |
| 7149 | // of the instruction. |
| 7150 | if ((GetPrevious() == instruction) |
| 7151 | || ((GetPrevious() == nullptr) |
| 7152 | && instruction->IsPhi() |
| 7153 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7154 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7155 | << "Doing parallel moves for the same instruction."; |
| 7156 | } else { |
| 7157 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 7158 | } |
| 7159 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 7160 | } |
| 7161 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7162 | for (const MoveOperands& move : moves_) { |
| 7163 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7164 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7165 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7166 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7167 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7168 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7169 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7170 | } |
| 7171 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7172 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7173 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7174 | } |
| 7175 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7176 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7177 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 7178 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7179 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7180 | protected: |
| 7181 | DEFAULT_COPY_CONSTRUCTOR(ParallelMove); |
| 7182 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7183 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7184 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7185 | }; |
| 7186 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7187 | // This instruction computes an intermediate address pointing in the 'middle' of an object. The |
| 7188 | // result pointer cannot be handled by GC, so extra care is taken to make sure that this value is |
| 7189 | // never used across anything that can trigger GC. |
| 7190 | // The result of this instruction is not a pointer in the sense of `DataType::Type::kreference`. |
| 7191 | // So we represent it by the type `DataType::Type::kInt`. |
| 7192 | class HIntermediateAddress FINAL : public HExpression<2> { |
| 7193 | public: |
| 7194 | HIntermediateAddress(HInstruction* base_address, HInstruction* offset, uint32_t dex_pc) |
| 7195 | : HExpression(DataType::Type::kInt32, SideEffects::DependsOnGC(), dex_pc) { |
| 7196 | DCHECK_EQ(DataType::Size(DataType::Type::kInt32), |
| 7197 | DataType::Size(DataType::Type::kReference)) |
| 7198 | << "kPrimInt and kPrimNot have different sizes."; |
| 7199 | SetRawInputAt(0, base_address); |
| 7200 | SetRawInputAt(1, offset); |
| 7201 | } |
| 7202 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7203 | bool IsClonable() const OVERRIDE { return true; } |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7204 | bool CanBeMoved() const OVERRIDE { return true; } |
| 7205 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 7206 | return true; |
| 7207 | } |
| 7208 | bool IsActualObject() const OVERRIDE { return false; } |
| 7209 | |
| 7210 | HInstruction* GetBaseAddress() const { return InputAt(0); } |
| 7211 | HInstruction* GetOffset() const { return InputAt(1); } |
| 7212 | |
| 7213 | DECLARE_INSTRUCTION(IntermediateAddress); |
| 7214 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7215 | protected: |
| 7216 | DEFAULT_COPY_CONSTRUCTOR(IntermediateAddress); |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7217 | }; |
| 7218 | |
| 7219 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7220 | } // namespace art |
| 7221 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 7222 | #include "nodes_vector.h" |
| 7223 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7224 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 7225 | #include "nodes_shared.h" |
| 7226 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7227 | #ifdef ART_ENABLE_CODEGEN_mips |
| 7228 | #include "nodes_mips.h" |
| 7229 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7230 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 7231 | #include "nodes_x86.h" |
| 7232 | #endif |
| 7233 | |
| 7234 | namespace art { |
| 7235 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7236 | class OptimizingCompilerStats; |
| 7237 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7238 | class HGraphVisitor : public ValueObject { |
| 7239 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7240 | explicit HGraphVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7241 | : stats_(stats), |
| 7242 | graph_(graph) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 7243 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7244 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7245 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7246 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 7247 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7248 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7249 | void VisitInsertionOrder(); |
| 7250 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7251 | // Visit the graph following dominator tree reverse post-order. |
| 7252 | void VisitReversePostOrder(); |
| 7253 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 7254 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7255 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7256 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7257 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7258 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 7259 | |
| 7260 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7261 | |
| 7262 | #undef DECLARE_VISIT_INSTRUCTION |
| 7263 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7264 | protected: |
| 7265 | OptimizingCompilerStats* stats_; |
| 7266 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7267 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 7268 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7269 | |
| 7270 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 7271 | }; |
| 7272 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7273 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 7274 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7275 | explicit HGraphDelegateVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7276 | : HGraphVisitor(graph, stats) {} |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7277 | virtual ~HGraphDelegateVisitor() {} |
| 7278 | |
| 7279 | // Visit functions that delegate to to super class. |
| 7280 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 7281 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7282 | |
| 7283 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7284 | |
| 7285 | #undef DECLARE_VISIT_INSTRUCTION |
| 7286 | |
| 7287 | private: |
| 7288 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 7289 | }; |
| 7290 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7291 | // Create a clone of the instruction, insert it into the graph; replace the old one with a new |
| 7292 | // and remove the old instruction. |
| 7293 | HInstruction* ReplaceInstrOrPhiByClone(HInstruction* instr); |
| 7294 | |
| 7295 | // Create a clone for each clonable instructions/phis and replace the original with the clone. |
| 7296 | // |
| 7297 | // Used for testing individual instruction cloner. |
| 7298 | class CloneAndReplaceInstructionVisitor : public HGraphDelegateVisitor { |
| 7299 | public: |
| 7300 | explicit CloneAndReplaceInstructionVisitor(HGraph* graph) |
| 7301 | : HGraphDelegateVisitor(graph), instr_replaced_by_clones_count(0) {} |
| 7302 | |
| 7303 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 7304 | if (instruction->IsClonable()) { |
| 7305 | ReplaceInstrOrPhiByClone(instruction); |
| 7306 | instr_replaced_by_clones_count++; |
| 7307 | } |
| 7308 | } |
| 7309 | |
| 7310 | size_t GetInstrReplacedByClonesCount() const { return instr_replaced_by_clones_count; } |
| 7311 | |
| 7312 | private: |
| 7313 | size_t instr_replaced_by_clones_count; |
| 7314 | |
| 7315 | DISALLOW_COPY_AND_ASSIGN(CloneAndReplaceInstructionVisitor); |
| 7316 | }; |
| 7317 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7318 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7319 | // of an inner loop. The order in which the blocks are iterated is on their |
| 7320 | // block id. |
| 7321 | class HBlocksInLoopIterator : public ValueObject { |
| 7322 | public: |
| 7323 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 7324 | : blocks_in_loop_(info.GetBlocks()), |
| 7325 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 7326 | index_(0) { |
| 7327 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 7328 | Advance(); |
| 7329 | } |
| 7330 | } |
| 7331 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7332 | bool Done() const { return index_ == blocks_.size(); } |
| 7333 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7334 | void Advance() { |
| 7335 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7336 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7337 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 7338 | break; |
| 7339 | } |
| 7340 | } |
| 7341 | } |
| 7342 | |
| 7343 | private: |
| 7344 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7345 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7346 | size_t index_; |
| 7347 | |
| 7348 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 7349 | }; |
| 7350 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7351 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7352 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 7353 | // post order. |
| 7354 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 7355 | public: |
| 7356 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 7357 | : blocks_in_loop_(info.GetBlocks()), |
| 7358 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 7359 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7360 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7361 | Advance(); |
| 7362 | } |
| 7363 | } |
| 7364 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7365 | bool Done() const { return index_ == blocks_.size(); } |
| 7366 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7367 | void Advance() { |
| 7368 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7369 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 7370 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7371 | break; |
| 7372 | } |
| 7373 | } |
| 7374 | } |
| 7375 | |
| 7376 | private: |
| 7377 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7378 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7379 | size_t index_; |
| 7380 | |
| 7381 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 7382 | }; |
| 7383 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7384 | // Returns int64_t value of a properly typed constant. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7385 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7386 | if (constant->IsIntConstant()) { |
| 7387 | return constant->AsIntConstant()->GetValue(); |
| 7388 | } else if (constant->IsLongConstant()) { |
| 7389 | return constant->AsLongConstant()->GetValue(); |
| 7390 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 7391 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7392 | return 0; |
| 7393 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7394 | } |
| 7395 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7396 | // Returns true iff instruction is an integral constant (and sets value on success). |
| 7397 | inline bool IsInt64AndGet(HInstruction* instruction, /*out*/ int64_t* value) { |
| 7398 | if (instruction->IsIntConstant()) { |
| 7399 | *value = instruction->AsIntConstant()->GetValue(); |
| 7400 | return true; |
| 7401 | } else if (instruction->IsLongConstant()) { |
| 7402 | *value = instruction->AsLongConstant()->GetValue(); |
| 7403 | return true; |
| 7404 | } else if (instruction->IsNullConstant()) { |
| 7405 | *value = 0; |
| 7406 | return true; |
| 7407 | } |
| 7408 | return false; |
| 7409 | } |
| 7410 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 7411 | // Returns true iff instruction is the given integral constant. |
| 7412 | inline bool IsInt64Value(HInstruction* instruction, int64_t value) { |
| 7413 | int64_t val = 0; |
| 7414 | return IsInt64AndGet(instruction, &val) && val == value; |
| 7415 | } |
| 7416 | |
| 7417 | // Returns true iff instruction is a zero bit pattern. |
| 7418 | inline bool IsZeroBitPattern(HInstruction* instruction) { |
| 7419 | return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern(); |
| 7420 | } |
| 7421 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7422 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 7423 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 7424 | inline const H##type* HInstruction::As##type() const { \ |
| 7425 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 7426 | } \ |
| 7427 | inline H##type* HInstruction::As##type() { \ |
| 7428 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 7429 | } |
| 7430 | |
| 7431 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7432 | #undef INSTRUCTION_TYPE_CHECK |
| 7433 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 7434 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 7435 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 7436 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 7437 | size_t number_of_new_blocks, |
| 7438 | size_t after) { |
| 7439 | DCHECK_LT(after, blocks->size()); |
| 7440 | size_t old_size = blocks->size(); |
| 7441 | size_t new_size = old_size + number_of_new_blocks; |
| 7442 | blocks->resize(new_size); |
| 7443 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 7444 | } |
| 7445 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7446 | /* |
| 7447 | * Hunt "under the hood" of array lengths (leading to array references), |
| 7448 | * null checks (also leading to array references), and new arrays |
| 7449 | * (leading to the actual length). This makes it more likely related |
| 7450 | * instructions become actually comparable. |
| 7451 | */ |
| 7452 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 7453 | while (instruction->IsArrayLength() || |
| 7454 | instruction->IsNullCheck() || |
| 7455 | instruction->IsNewArray()) { |
| 7456 | instruction = instruction->IsNewArray() |
| 7457 | ? instruction->AsNewArray()->GetLength() |
| 7458 | : instruction->InputAt(0); |
| 7459 | } |
| 7460 | return instruction; |
| 7461 | } |
| 7462 | |
Artem Serov | 21c7e6f | 2017-07-27 16:04:42 +0100 | [diff] [blame] | 7463 | void RemoveEnvironmentUses(HInstruction* instruction); |
| 7464 | bool HasEnvironmentUsedByOthers(HInstruction* instruction); |
| 7465 | void ResetEnvironmentInputRecords(HInstruction* instruction); |
| 7466 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7467 | } // namespace art |
| 7468 | |
| 7469 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |