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 | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 31 | #include "dex_file.h" |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 32 | #include "dex_file_types.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 33 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 34 | #include "handle.h" |
| 35 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 36 | #include "invoke_type.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 37 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 38 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 39 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 40 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 41 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 42 | #include "primitive.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 43 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 44 | |
| 45 | namespace art { |
| 46 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 47 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 48 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 49 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 50 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 51 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 52 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 53 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 54 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 55 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 56 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 57 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 58 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 59 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 60 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 61 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 62 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 63 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 64 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 65 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 66 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 67 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 68 | namespace mirror { |
| 69 | class DexCache; |
| 70 | } // namespace mirror |
| 71 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 72 | static const int kDefaultNumberOfBlocks = 8; |
| 73 | static const int kDefaultNumberOfSuccessors = 2; |
| 74 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 75 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 76 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 77 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 78 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 79 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 80 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 81 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 82 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 83 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 84 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 85 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 86 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 87 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 88 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 89 | static constexpr uint32_t kNoDexPc = -1; |
| 90 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 91 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 92 | // For the purposes of the compiler, the dex files must actually be the same object |
| 93 | // if we want to safely treat them as the same. This is especially important for JIT |
| 94 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 95 | // times and provide different class resolution but no two class loaders should ever |
| 96 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 97 | // all sorts of weird failures. |
| 98 | return &lhs == &rhs; |
| 99 | } |
| 100 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 101 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 102 | // All types. |
| 103 | kCondEQ, // == |
| 104 | kCondNE, // != |
| 105 | // Signed integers and floating-point numbers. |
| 106 | kCondLT, // < |
| 107 | kCondLE, // <= |
| 108 | kCondGT, // > |
| 109 | kCondGE, // >= |
| 110 | // Unsigned integers. |
| 111 | kCondB, // < |
| 112 | kCondBE, // <= |
| 113 | kCondA, // > |
| 114 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 115 | // First and last aliases. |
| 116 | kCondFirst = kCondEQ, |
| 117 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 120 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 121 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 122 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 123 | kAnalysisFailThrowCatchLoop, |
| 124 | kAnalysisFailAmbiguousArrayOp, |
| 125 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 128 | template <typename T> |
| 129 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 130 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 131 | } |
| 132 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 133 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 134 | public: |
| 135 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 136 | |
| 137 | void AddInstruction(HInstruction* instruction); |
| 138 | void RemoveInstruction(HInstruction* instruction); |
| 139 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 140 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 141 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 142 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 143 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 144 | // Return true if this list contains `instruction`. |
| 145 | bool Contains(HInstruction* instruction) const; |
| 146 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 147 | // Return true if `instruction1` is found before `instruction2` in |
| 148 | // this instruction list and false otherwise. Abort if none |
| 149 | // of these instructions is found. |
| 150 | bool FoundBefore(const HInstruction* instruction1, |
| 151 | const HInstruction* instruction2) const; |
| 152 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 153 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 154 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 155 | |
| 156 | // Update the block of all instructions to be `block`. |
| 157 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 158 | |
| 159 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 160 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 161 | void Add(const HInstructionList& instruction_list); |
| 162 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 163 | // Return the number of instructions in the list. This is an expensive operation. |
| 164 | size_t CountSize() const; |
| 165 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 166 | private: |
| 167 | HInstruction* first_instruction_; |
| 168 | HInstruction* last_instruction_; |
| 169 | |
| 170 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 171 | friend class HGraph; |
| 172 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 173 | friend class HInstructionIterator; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 174 | friend class HInstructionIteratorHandleChanges; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 175 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 176 | |
| 177 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 178 | }; |
| 179 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 180 | class ReferenceTypeInfo : ValueObject { |
| 181 | public: |
| 182 | typedef Handle<mirror::Class> TypeHandle; |
| 183 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 184 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 185 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 186 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 187 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 188 | } |
| 189 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 190 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 191 | return ReferenceTypeInfo(type_handle, is_exact); |
| 192 | } |
| 193 | |
| 194 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 195 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 196 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 197 | return handle.GetReference() != nullptr; |
| 198 | } |
| 199 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 200 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 201 | return IsValidHandle(type_handle_); |
| 202 | } |
| 203 | |
| 204 | bool IsExact() const { return is_exact_; } |
| 205 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 206 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 207 | DCHECK(IsValid()); |
| 208 | return GetTypeHandle()->IsObjectClass(); |
| 209 | } |
| 210 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 211 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 212 | DCHECK(IsValid()); |
| 213 | return GetTypeHandle()->IsStringClass(); |
| 214 | } |
| 215 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 216 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 217 | DCHECK(IsValid()); |
| 218 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 219 | } |
| 220 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 221 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 222 | DCHECK(IsValid()); |
| 223 | return GetTypeHandle()->IsInterface(); |
| 224 | } |
| 225 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 226 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 227 | DCHECK(IsValid()); |
| 228 | return GetTypeHandle()->IsArrayClass(); |
| 229 | } |
| 230 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 231 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 232 | DCHECK(IsValid()); |
| 233 | return GetTypeHandle()->IsPrimitiveArray(); |
| 234 | } |
| 235 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 236 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 237 | DCHECK(IsValid()); |
| 238 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 239 | } |
| 240 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 241 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 242 | DCHECK(IsValid()); |
| 243 | if (!IsExact()) return false; |
| 244 | if (!IsArrayClass()) return false; |
| 245 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 246 | } |
| 247 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 248 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 249 | DCHECK(IsValid()); |
| 250 | if (!IsExact()) return false; |
| 251 | if (!IsArrayClass()) return false; |
| 252 | if (!rti.IsArrayClass()) return false; |
| 253 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 254 | rti.GetTypeHandle()->GetComponentType()); |
| 255 | } |
| 256 | |
| 257 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 258 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 259 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 260 | DCHECK(IsValid()); |
| 261 | DCHECK(rti.IsValid()); |
| 262 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 263 | } |
| 264 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 265 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 266 | DCHECK(IsValid()); |
| 267 | DCHECK(rti.IsValid()); |
| 268 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 269 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 270 | } |
| 271 | |
| 272 | // Returns true if the type information provide the same amount of details. |
| 273 | // Note that it does not mean that the instructions have the same actual type |
| 274 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 275 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 276 | if (!IsValid() && !rti.IsValid()) { |
| 277 | // Invalid types are equal. |
| 278 | return true; |
| 279 | } |
| 280 | if (!IsValid() || !rti.IsValid()) { |
| 281 | // One is valid, the other not. |
| 282 | return false; |
| 283 | } |
| 284 | return IsExact() == rti.IsExact() |
| 285 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 286 | } |
| 287 | |
| 288 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 289 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 290 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 291 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 292 | |
| 293 | // The class of the object. |
| 294 | TypeHandle type_handle_; |
| 295 | // Whether or not the type is exact or a superclass of the actual type. |
| 296 | // Whether or not we have any information about this type. |
| 297 | bool is_exact_; |
| 298 | }; |
| 299 | |
| 300 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 301 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 302 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 303 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 304 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 305 | HGraph(ArenaAllocator* arena, |
| 306 | const DexFile& dex_file, |
| 307 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 308 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 309 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 310 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 311 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 312 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 313 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 314 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 315 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 316 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 317 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 318 | entry_block_(nullptr), |
| 319 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 320 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 321 | number_of_vregs_(0), |
| 322 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 323 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 324 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 325 | has_try_catch_(false), |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 326 | has_loops_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 327 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 328 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 329 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 330 | dex_file_(dex_file), |
| 331 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 332 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 333 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 334 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 335 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 336 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 337 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 338 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 339 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 340 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 341 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 342 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 343 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 344 | osr_(osr), |
| 345 | cha_single_implementation_list_(arena->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 346 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 347 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 348 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 349 | // 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] | 350 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 351 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 352 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 353 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 354 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 355 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 356 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 357 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 358 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 359 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 360 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 361 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 362 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 363 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 364 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 365 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 366 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 367 | void ComputeDominanceInformation(); |
| 368 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 369 | void ClearLoopInformation(); |
| 370 | void FindBackEdges(ArenaBitVector* visited); |
| 371 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 372 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 373 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 374 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 375 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 376 | // 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] | 377 | // 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] | 378 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 379 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 380 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 381 | // order and loop information. |
| 382 | void ComputeTryBlockInformation(); |
| 383 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 384 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 385 | // Returns the instruction to replace the invoke expression or null if the |
| 386 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 387 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 388 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 389 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 390 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 391 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 392 | // should be the new back edge. |
| 393 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 394 | HBasicBlock* reference, |
| 395 | bool replace_if_back_edge); |
| 396 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 397 | // Need to add a couple of blocks to test if the loop body is entered and |
| 398 | // put deoptimization instructions, etc. |
| 399 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 400 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 401 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 402 | // other blocks and has no instructions or phis. |
| 403 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 404 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 405 | // Splits the edge between `block` and `successor` while preserving the |
| 406 | // indices in the predecessor/successor lists. If there are multiple edges |
| 407 | // between the blocks, the lowest indices are used. |
| 408 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 409 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 410 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 411 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 412 | void SimplifyLoop(HBasicBlock* header); |
| 413 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 414 | int32_t GetNextInstructionId() { |
| 415 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 416 | return current_instruction_id_++; |
| 417 | } |
| 418 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 419 | int32_t GetCurrentInstructionId() const { |
| 420 | return current_instruction_id_; |
| 421 | } |
| 422 | |
| 423 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 424 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 425 | current_instruction_id_ = id; |
| 426 | } |
| 427 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 428 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 429 | return maximum_number_of_out_vregs_; |
| 430 | } |
| 431 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 432 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 433 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 434 | } |
| 435 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 436 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 437 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 438 | } |
| 439 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 440 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 441 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 442 | } |
| 443 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 444 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 445 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 446 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 447 | } |
| 448 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 449 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 450 | number_of_vregs_ = number_of_vregs; |
| 451 | } |
| 452 | |
| 453 | uint16_t GetNumberOfVRegs() const { |
| 454 | return number_of_vregs_; |
| 455 | } |
| 456 | |
| 457 | void SetNumberOfInVRegs(uint16_t value) { |
| 458 | number_of_in_vregs_ = value; |
| 459 | } |
| 460 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 461 | uint16_t GetNumberOfInVRegs() const { |
| 462 | return number_of_in_vregs_; |
| 463 | } |
| 464 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 465 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 466 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 467 | return number_of_vregs_ - number_of_in_vregs_; |
| 468 | } |
| 469 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 470 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 471 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 472 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 473 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 474 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 475 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 476 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 477 | } |
| 478 | |
| 479 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 480 | return ReverseRange(GetReversePostOrder()); |
| 481 | } |
| 482 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 483 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 484 | return linear_order_; |
| 485 | } |
| 486 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 487 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 488 | return ReverseRange(GetLinearOrder()); |
| 489 | } |
| 490 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 491 | bool HasBoundsChecks() const { |
| 492 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 495 | void SetHasBoundsChecks(bool value) { |
| 496 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 499 | bool ShouldGenerateConstructorBarrier() const { |
| 500 | return should_generate_constructor_barrier_; |
| 501 | } |
| 502 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 503 | bool IsDebuggable() const { return debuggable_; } |
| 504 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 505 | // 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] | 506 | // already, it is created and inserted into the graph. This method is only for |
| 507 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 508 | HConstant* GetConstant(Primitive::Type type, int64_t value, uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 509 | |
| 510 | // TODO: This is problematic for the consistency of reference type propagation |
| 511 | // because it can be created anytime after the pass and thus it will be left |
| 512 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 513 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 514 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 515 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 516 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 517 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 518 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 519 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 520 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 521 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 522 | 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] | 523 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 524 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 525 | 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] | 526 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 527 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 528 | HCurrentMethod* GetCurrentMethod(); |
| 529 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 530 | const DexFile& GetDexFile() const { |
| 531 | return dex_file_; |
| 532 | } |
| 533 | |
| 534 | uint32_t GetMethodIdx() const { |
| 535 | return method_idx_; |
| 536 | } |
| 537 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 538 | InvokeType GetInvokeType() const { |
| 539 | return invoke_type_; |
| 540 | } |
| 541 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 542 | InstructionSet GetInstructionSet() const { |
| 543 | return instruction_set_; |
| 544 | } |
| 545 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 546 | bool IsCompilingOsr() const { return osr_; } |
| 547 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 548 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 549 | return cha_single_implementation_list_; |
| 550 | } |
| 551 | |
| 552 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 553 | cha_single_implementation_list_.insert(method); |
| 554 | } |
| 555 | |
| 556 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 557 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 558 | } |
| 559 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 560 | bool HasTryCatch() const { return has_try_catch_; } |
| 561 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 562 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 563 | bool HasLoops() const { return has_loops_; } |
| 564 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 565 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 566 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 567 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 568 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 569 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 570 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 571 | |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 572 | // Returns an instruction with the opposite Boolean value from 'cond'. |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 573 | // The instruction has been inserted into the graph, either as a constant, or |
| 574 | // before cursor. |
| 575 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 576 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 577 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 578 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 579 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 580 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 581 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 582 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 583 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 584 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 585 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 586 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 587 | template <class InstructionType, typename ValueType> |
| 588 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 589 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 590 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 591 | // Try to find an existing constant of the given value. |
| 592 | InstructionType* constant = nullptr; |
| 593 | auto cached_constant = cache->find(value); |
| 594 | if (cached_constant != cache->end()) { |
| 595 | constant = cached_constant->second; |
| 596 | } |
| 597 | |
| 598 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 599 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 600 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 601 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 602 | cache->Overwrite(value, constant); |
| 603 | InsertConstant(constant); |
| 604 | } |
| 605 | return constant; |
| 606 | } |
| 607 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 608 | void InsertConstant(HConstant* instruction); |
| 609 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 610 | // Cache a float constant into the graph. This method should only be |
| 611 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 612 | void CacheFloatConstant(HFloatConstant* constant); |
| 613 | |
| 614 | // See CacheFloatConstant comment. |
| 615 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 616 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 617 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 618 | |
| 619 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 620 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 621 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 622 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 623 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 624 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 625 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 626 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 627 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 628 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 629 | HBasicBlock* entry_block_; |
| 630 | HBasicBlock* exit_block_; |
| 631 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 632 | // 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] | 633 | uint16_t maximum_number_of_out_vregs_; |
| 634 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 635 | // The number of virtual registers in this method. Contains the parameters. |
| 636 | uint16_t number_of_vregs_; |
| 637 | |
| 638 | // The number of virtual registers used by parameters of this method. |
| 639 | uint16_t number_of_in_vregs_; |
| 640 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 641 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 642 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 643 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 644 | // Flag whether there are bounds checks in the graph. We can skip |
| 645 | // BCE if it's false. It's only best effort to keep it up to date in |
| 646 | // the presence of code elimination so there might be false positives. |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 647 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 648 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 649 | // Flag whether there are try/catch blocks in the graph. We will skip |
| 650 | // try/catch-related passes if it's false. It's only best effort to keep |
| 651 | // it up to date in the presence of code elimination so there might be |
| 652 | // false positives. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 653 | bool has_try_catch_; |
| 654 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 655 | // Flag whether there are any loops in the graph. We can skip loop |
| 656 | // optimization if it's false. It's only best effort to keep it up |
| 657 | // to date in the presence of code elimination so there might be false |
| 658 | // positives. |
| 659 | bool has_loops_; |
| 660 | |
| 661 | // Flag whether there are any irreducible loops in the graph. It's only |
| 662 | // best effort to keep it up to date in the presence of code elimination |
| 663 | // so there might be false positives. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 664 | bool has_irreducible_loops_; |
| 665 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 666 | // Indicates whether the graph should be compiled in a way that |
| 667 | // ensures full debuggability. If false, we can apply more |
| 668 | // aggressive optimizations that may limit the level of debugging. |
| 669 | const bool debuggable_; |
| 670 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 671 | // 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] | 672 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 673 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 674 | // The dex file from which the method is from. |
| 675 | const DexFile& dex_file_; |
| 676 | |
| 677 | // The method index in the dex file. |
| 678 | const uint32_t method_idx_; |
| 679 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 680 | // If inlined, this encodes how the callee is being invoked. |
| 681 | const InvokeType invoke_type_; |
| 682 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 683 | // Whether the graph has been transformed to SSA form. Only used |
| 684 | // in debug mode to ensure we are not using properties only valid |
| 685 | // for non-SSA form (like the number of temporaries). |
| 686 | bool in_ssa_form_; |
| 687 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 688 | const bool should_generate_constructor_barrier_; |
| 689 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 690 | // Number of CHA guards in the graph. Used to short-circuit the |
| 691 | // CHA guard optimization pass when there is no CHA guard left. |
| 692 | uint32_t number_of_cha_guards_; |
| 693 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 694 | const InstructionSet instruction_set_; |
| 695 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 696 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 697 | HNullConstant* cached_null_constant_; |
| 698 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 699 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 700 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 701 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 702 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 703 | HCurrentMethod* cached_current_method_; |
| 704 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 705 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 706 | // for example for methods whose declaring class could not be resolved |
| 707 | // (such as when the superclass could not be found). |
| 708 | ArtMethod* art_method_; |
| 709 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 710 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 711 | // collection pointer to passes which may create NullConstant. |
| 712 | ReferenceTypeInfo inexact_object_rti_; |
| 713 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 714 | // Whether we are compiling this graph for on stack replacement: this will |
| 715 | // make all loops seen as irreducible and emit special stack maps to mark |
| 716 | // compiled code entries which the interpreter can directly jump to. |
| 717 | const bool osr_; |
| 718 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 719 | // List of methods that are assumed to have single implementation. |
| 720 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 721 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 722 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 723 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 724 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 725 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 726 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 727 | }; |
| 728 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 729 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 730 | public: |
| 731 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 732 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 733 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 734 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 735 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 736 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 737 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 738 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 739 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 740 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 741 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 742 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 743 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 744 | |
| 745 | void Dump(std::ostream& os); |
| 746 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 747 | HBasicBlock* GetHeader() const { |
| 748 | return header_; |
| 749 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 750 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 751 | void SetHeader(HBasicBlock* block) { |
| 752 | header_ = block; |
| 753 | } |
| 754 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 755 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 756 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 757 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 758 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 759 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 760 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 763 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 764 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 765 | } |
| 766 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 767 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 768 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 769 | } |
| 770 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 771 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 772 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 773 | } |
| 774 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 775 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 776 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 777 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 778 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 779 | } |
| 780 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 781 | // Returns the lifetime position of the back edge that has the |
| 782 | // greatest lifetime position. |
| 783 | size_t GetLifetimeEnd() const; |
| 784 | |
| 785 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 786 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 787 | } |
| 788 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 789 | // Finds blocks that are part of this loop. |
| 790 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 791 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 792 | // Returns whether this loop information contains `block`. |
| 793 | // Note that this loop information *must* be populated before entering this function. |
| 794 | bool Contains(const HBasicBlock& block) const; |
| 795 | |
| 796 | // Returns whether this loop information is an inner loop of `other`. |
| 797 | // Note that `other` *must* be populated before entering this function. |
| 798 | bool IsIn(const HLoopInformation& other) const; |
| 799 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 800 | // Returns true if instruction is not defined within this loop. |
| 801 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 802 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 803 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 804 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 805 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 806 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 807 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 808 | void ClearAllBlocks() { |
| 809 | blocks_.ClearAllBits(); |
| 810 | } |
| 811 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 812 | bool HasBackEdgeNotDominatedByHeader() const; |
| 813 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 814 | bool IsPopulated() const { |
| 815 | return blocks_.GetHighestBitSet() != -1; |
| 816 | } |
| 817 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 818 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 819 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 820 | bool HasExitEdge() const; |
| 821 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 822 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 823 | // Internal recursive implementation of `Populate`. |
| 824 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 825 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 826 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 827 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 828 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 829 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 830 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 831 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 832 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 833 | |
| 834 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 835 | }; |
| 836 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 837 | // Stores try/catch information for basic blocks. |
| 838 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 839 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 840 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 841 | public: |
| 842 | // Try block information constructor. |
| 843 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 844 | : try_entry_(&try_entry), |
| 845 | catch_dex_file_(nullptr), |
| 846 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 847 | DCHECK(try_entry_ != nullptr); |
| 848 | } |
| 849 | |
| 850 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 851 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 852 | : try_entry_(nullptr), |
| 853 | catch_dex_file_(&dex_file), |
| 854 | catch_type_index_(catch_type_index) {} |
| 855 | |
| 856 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 857 | |
| 858 | const HTryBoundary& GetTryEntry() const { |
| 859 | DCHECK(IsTryBlock()); |
| 860 | return *try_entry_; |
| 861 | } |
| 862 | |
| 863 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 864 | |
| 865 | bool IsCatchAllTypeIndex() const { |
| 866 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 867 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 868 | } |
| 869 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 870 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 871 | DCHECK(IsCatchBlock()); |
| 872 | return catch_type_index_; |
| 873 | } |
| 874 | |
| 875 | const DexFile& GetCatchDexFile() const { |
| 876 | DCHECK(IsCatchBlock()); |
| 877 | return *catch_dex_file_; |
| 878 | } |
| 879 | |
| 880 | private: |
| 881 | // One of possibly several TryBoundary instructions entering the block's try. |
| 882 | // Only set for try blocks. |
| 883 | const HTryBoundary* try_entry_; |
| 884 | |
| 885 | // Exception type information. Only set for catch blocks. |
| 886 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 887 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 888 | }; |
| 889 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 890 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 891 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 892 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 893 | // A block in a method. Contains the list of instructions represented |
| 894 | // as a double linked list. Each block knows its predecessors and |
| 895 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 896 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 897 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 898 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 899 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 900 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 901 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 902 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 903 | loop_information_(nullptr), |
| 904 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 905 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 906 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 907 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 908 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 909 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 910 | try_catch_information_(nullptr) { |
| 911 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 912 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 913 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 914 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 915 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 916 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 917 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 918 | } |
| 919 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 920 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 921 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 922 | } |
| 923 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 924 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 925 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 926 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 927 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 928 | return ContainsElement(successors_, block, start_from); |
| 929 | } |
| 930 | |
| 931 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 932 | return dominated_blocks_; |
| 933 | } |
| 934 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 935 | bool IsEntryBlock() const { |
| 936 | return graph_->GetEntryBlock() == this; |
| 937 | } |
| 938 | |
| 939 | bool IsExitBlock() const { |
| 940 | return graph_->GetExitBlock() == this; |
| 941 | } |
| 942 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 943 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 944 | bool IsSingleTryBoundary() const; |
| 945 | |
| 946 | // Returns true if this block emits nothing but a jump. |
| 947 | bool IsSingleJump() const { |
| 948 | HLoopInformation* loop_info = GetLoopInformation(); |
| 949 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 950 | // Back edges generate a suspend check. |
| 951 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 952 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 953 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 954 | void AddBackEdge(HBasicBlock* back_edge) { |
| 955 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 956 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 957 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 958 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 959 | loop_information_->AddBackEdge(back_edge); |
| 960 | } |
| 961 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 962 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 963 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 964 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 965 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 966 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 967 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 968 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 969 | HBasicBlock* GetDominator() const { return dominator_; } |
| 970 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 971 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 972 | |
| 973 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 974 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 975 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 976 | |
| 977 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 978 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 979 | } |
| 980 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 981 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 982 | |
| 983 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 984 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 987 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 988 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 989 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 990 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 991 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 992 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 993 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 994 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 995 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 996 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 997 | successors_.push_back(block); |
| 998 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1001 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1002 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1003 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1004 | new_block->predecessors_.push_back(this); |
| 1005 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1008 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1009 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1010 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1011 | new_block->successors_.push_back(this); |
| 1012 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1015 | // Insert `this` between `predecessor` and `successor. This method |
| 1016 | // preserves the indicies, and will update the first edge found between |
| 1017 | // `predecessor` and `successor`. |
| 1018 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1019 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1020 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1021 | successor->predecessors_[predecessor_index] = this; |
| 1022 | predecessor->successors_[successor_index] = this; |
| 1023 | successors_.push_back(successor); |
| 1024 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1025 | } |
| 1026 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1027 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1028 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1029 | } |
| 1030 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1031 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1032 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1035 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1036 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1040 | predecessors_.push_back(block); |
| 1041 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1042 | } |
| 1043 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1044 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1045 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1046 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1047 | } |
| 1048 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1049 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1050 | DCHECK_EQ(successors_.size(), 2u); |
| 1051 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1052 | } |
| 1053 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1054 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1055 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1056 | } |
| 1057 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1058 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1059 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1060 | } |
| 1061 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1062 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1063 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1064 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1068 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1069 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1073 | // predecessors is at index `idx`. |
| 1074 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1075 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1076 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1077 | } |
| 1078 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1079 | // Create a new block between this block and its predecessors. The new block |
| 1080 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1081 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1082 | // loop and try/catch information are not updated. |
| 1083 | HBasicBlock* CreateImmediateDominator(); |
| 1084 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1085 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1086 | // created, latter block. Note that this method will add the block to the |
| 1087 | // graph, create a Goto at the end of the former block and will create an edge |
| 1088 | // 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] | 1089 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1090 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1091 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1092 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1093 | // created block. Note that this method just updates raw block information, |
| 1094 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1095 | // update the graph, reverse post order, loop information, nor make sure the |
| 1096 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1097 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1098 | |
| 1099 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1100 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1101 | |
| 1102 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1103 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1104 | // that this method does not update the graph, reverse post order, loop |
| 1105 | // information, nor make sure the blocks are consistent (for example ending |
| 1106 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1107 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1108 | |
| 1109 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1110 | // of `this` are moved to `other`. |
| 1111 | // Note that this method does not update the graph, reverse post order, loop |
| 1112 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1113 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1114 | void ReplaceWith(HBasicBlock* other); |
| 1115 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1116 | // Merges the instructions of `other` at the end of `this`. |
| 1117 | void MergeInstructionsWith(HBasicBlock* other); |
| 1118 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1119 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1120 | // order, links to predecessors, successors, dominators and deletes the block |
| 1121 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1122 | // predecessor of `other` and vice versa. |
| 1123 | void MergeWith(HBasicBlock* other); |
| 1124 | |
| 1125 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1126 | // removes it from all loops it is included in and eventually from the graph. |
| 1127 | // The block must not dominate any other block. Predecessors and successors |
| 1128 | // are safely updated. |
| 1129 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1130 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1131 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1132 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1133 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1134 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1135 | // Replace instruction `initial` with `replacement` within this block. |
| 1136 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1137 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1138 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1139 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1140 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1141 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1142 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1143 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1144 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1145 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1146 | |
| 1147 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1148 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1149 | } |
| 1150 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1151 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1152 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1153 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1154 | } |
| 1155 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1156 | bool IsFirstPredecessorBackEdge() const { |
| 1157 | DCHECK(IsLoopHeader()); |
| 1158 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1159 | } |
| 1160 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1161 | HLoopInformation* GetLoopInformation() const { |
| 1162 | return loop_information_; |
| 1163 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1164 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1165 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1166 | // 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] | 1167 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1168 | void SetInLoop(HLoopInformation* info) { |
| 1169 | if (IsLoopHeader()) { |
| 1170 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1171 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1172 | loop_information_ = info; |
| 1173 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1174 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1175 | // Note that a non loop header having a loop information means this loop information |
| 1176 | // has already been populated |
| 1177 | loop_information_ = info; |
| 1178 | } else { |
| 1179 | // Block is part of an inner loop. Do not update the loop information. |
| 1180 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1181 | // at this point, because this method is being called while populating `info`. |
| 1182 | } |
| 1183 | } |
| 1184 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1185 | // Raw update of the loop information. |
| 1186 | void SetLoopInformation(HLoopInformation* info) { |
| 1187 | loop_information_ = info; |
| 1188 | } |
| 1189 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1190 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1191 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1192 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1193 | |
| 1194 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1195 | try_catch_information_ = try_catch_information; |
| 1196 | } |
| 1197 | |
| 1198 | bool IsTryBlock() const { |
| 1199 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1200 | } |
| 1201 | |
| 1202 | bool IsCatchBlock() const { |
| 1203 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1204 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1205 | |
| 1206 | // Returns the try entry that this block's successors should have. They will |
| 1207 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1208 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1209 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1210 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1211 | bool HasThrowingInstructions() const; |
| 1212 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1213 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1214 | bool Dominates(HBasicBlock* block) const; |
| 1215 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1216 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1217 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1218 | |
| 1219 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1220 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1221 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1222 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1223 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1224 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1225 | bool HasSinglePhi() const; |
| 1226 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1227 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1228 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1229 | ArenaVector<HBasicBlock*> predecessors_; |
| 1230 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1231 | HInstructionList instructions_; |
| 1232 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1233 | HLoopInformation* loop_information_; |
| 1234 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1235 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1236 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1237 | // The dex program counter of the first instruction of this block. |
| 1238 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1239 | size_t lifetime_start_; |
| 1240 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1241 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1242 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1243 | friend class HGraph; |
| 1244 | friend class HInstruction; |
| 1245 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1246 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1247 | }; |
| 1248 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1249 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1250 | // from the innermost to the outermost. |
| 1251 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1252 | public: |
| 1253 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1254 | : current_(block.GetLoopInformation()) {} |
| 1255 | |
| 1256 | bool Done() const { return current_ == nullptr; } |
| 1257 | |
| 1258 | void Advance() { |
| 1259 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1260 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | HLoopInformation* Current() const { |
| 1264 | DCHECK(!Done()); |
| 1265 | return current_; |
| 1266 | } |
| 1267 | |
| 1268 | private: |
| 1269 | HLoopInformation* current_; |
| 1270 | |
| 1271 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1272 | }; |
| 1273 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1274 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1275 | M(Above, Condition) \ |
| 1276 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1277 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1278 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1279 | M(ArrayGet, Instruction) \ |
| 1280 | M(ArrayLength, Instruction) \ |
| 1281 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1282 | M(Below, Condition) \ |
| 1283 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1284 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1285 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1286 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1287 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1288 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1289 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1290 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1291 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1292 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1293 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1294 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1295 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1296 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1297 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1298 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1299 | M(Exit, Instruction) \ |
| 1300 | M(FloatConstant, Constant) \ |
| 1301 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1302 | M(GreaterThan, Condition) \ |
| 1303 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1304 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1305 | M(InstanceFieldGet, Instruction) \ |
| 1306 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1307 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1308 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1309 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1310 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1311 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1312 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1313 | M(InvokePolymorphic, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1314 | M(LessThan, Condition) \ |
| 1315 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1316 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1317 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1318 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1319 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1320 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1321 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1322 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1323 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1324 | M(Neg, UnaryOperation) \ |
| 1325 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1326 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1327 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1328 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1329 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1330 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1331 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1332 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1333 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1334 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1335 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1336 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1337 | M(Return, Instruction) \ |
| 1338 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1339 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1340 | M(Shl, BinaryOperation) \ |
| 1341 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1342 | M(StaticFieldGet, Instruction) \ |
| 1343 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1344 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1345 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1346 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1347 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1348 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1349 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1350 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1351 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1352 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1353 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1354 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1355 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1356 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1357 | /* |
| 1358 | * Instructions, shared across several (not all) architectures. |
| 1359 | */ |
| 1360 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1361 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1362 | #else |
| 1363 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1364 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1365 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1366 | M(MultiplyAccumulate, Instruction) \ |
| 1367 | M(IntermediateAddress, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1368 | #endif |
| 1369 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1370 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1371 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1372 | #else |
| 1373 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1374 | M(ArmDexCacheArraysBase, Instruction) |
| 1375 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1376 | |
| 1377 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1378 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1379 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1380 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1381 | #else |
| 1382 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1383 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1384 | M(MipsDexCacheArraysBase, Instruction) \ |
| 1385 | M(MipsPackedSwitch, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1386 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1387 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1388 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1389 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1390 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1391 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1392 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1393 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1394 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1395 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1396 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1397 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1398 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1399 | |
| 1400 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1401 | |
| 1402 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1403 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1404 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1405 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1406 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1407 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1408 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1409 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1410 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1411 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1412 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1413 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1414 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1415 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1416 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1417 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1418 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1419 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1420 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1421 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1422 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1423 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1424 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1425 | #undef FORWARD_DECLARATION |
| 1426 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1427 | #define DECLARE_INSTRUCTION(type) \ |
| 1428 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1429 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1430 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1431 | return other->Is##type(); \ |
| 1432 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1433 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1434 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1435 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1436 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1437 | const H##type* As##type() const { return this; } \ |
| 1438 | H##type* As##type() { return this; } |
| 1439 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1440 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1441 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1442 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1443 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1444 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1445 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1446 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1447 | // Hook for the IntrusiveForwardList<>. |
| 1448 | // TODO: Hide this better. |
| 1449 | IntrusiveForwardListHook hook; |
| 1450 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1451 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1452 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1453 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1454 | |
| 1455 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1456 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1457 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1458 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1459 | |
| 1460 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1461 | }; |
| 1462 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1463 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1464 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1465 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1466 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1467 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1468 | // by the used instructions. |
| 1469 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1470 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1471 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1472 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1473 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1474 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1475 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1476 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1477 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1478 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1479 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1483 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1484 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1485 | |
| 1486 | private: |
| 1487 | // Instruction used by the user. |
| 1488 | HInstruction* instruction_; |
| 1489 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1490 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1491 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1492 | }; |
| 1493 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1494 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1495 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1496 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1497 | struct HInputExtractor { |
| 1498 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1499 | return record.GetInstruction(); |
| 1500 | } |
| 1501 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1502 | return record.GetInstruction(); |
| 1503 | } |
| 1504 | }; |
| 1505 | |
| 1506 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1507 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1508 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1509 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1510 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1511 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1512 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1513 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1514 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1515 | * modify the value of a reference field read [although it may modify the |
| 1516 | * reference fetch prior to reading the field, which is represented by its own |
| 1517 | * write/read dependence]). The analysis makes conservative points-to |
| 1518 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1519 | * the same, and any reference read depends on any reference read without |
| 1520 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1521 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1522 | * The internal representation uses 38-bit and is described in the table below. |
| 1523 | * The first line indicates the side effect, and for field/array accesses the |
| 1524 | * second line indicates the type of the access (in the order of the |
| 1525 | * Primitive::Type enum). |
| 1526 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1527 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1528 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1529 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1530 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1531 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1532 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1533 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1534 | * |
| 1535 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1536 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1537 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1538 | class SideEffects : public ValueObject { |
| 1539 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1540 | SideEffects() : flags_(0) {} |
| 1541 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1542 | static SideEffects None() { |
| 1543 | return SideEffects(0); |
| 1544 | } |
| 1545 | |
| 1546 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1547 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1548 | } |
| 1549 | |
| 1550 | static SideEffects AllChanges() { |
| 1551 | return SideEffects(kAllChangeBits); |
| 1552 | } |
| 1553 | |
| 1554 | static SideEffects AllDependencies() { |
| 1555 | return SideEffects(kAllDependOnBits); |
| 1556 | } |
| 1557 | |
| 1558 | static SideEffects AllExceptGCDependency() { |
| 1559 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1560 | } |
| 1561 | |
| 1562 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1563 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1564 | } |
| 1565 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1566 | static SideEffects AllWrites() { |
| 1567 | return SideEffects(kAllWrites); |
| 1568 | } |
| 1569 | |
| 1570 | static SideEffects AllReads() { |
| 1571 | return SideEffects(kAllReads); |
| 1572 | } |
| 1573 | |
| 1574 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1575 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1576 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1577 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1578 | } |
| 1579 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1580 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1581 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1582 | } |
| 1583 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1584 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1585 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1586 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1587 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1591 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1594 | static SideEffects CanTriggerGC() { |
| 1595 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1596 | } |
| 1597 | |
| 1598 | static SideEffects DependsOnGC() { |
| 1599 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1600 | } |
| 1601 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1602 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1603 | SideEffects Union(SideEffects other) const { |
| 1604 | return SideEffects(flags_ | other.flags_); |
| 1605 | } |
| 1606 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1607 | SideEffects Exclusion(SideEffects other) const { |
| 1608 | return SideEffects(flags_ & ~other.flags_); |
| 1609 | } |
| 1610 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1611 | void Add(SideEffects other) { |
| 1612 | flags_ |= other.flags_; |
| 1613 | } |
| 1614 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1615 | bool Includes(SideEffects other) const { |
| 1616 | return (other.flags_ & flags_) == other.flags_; |
| 1617 | } |
| 1618 | |
| 1619 | bool HasSideEffects() const { |
| 1620 | return (flags_ & kAllChangeBits); |
| 1621 | } |
| 1622 | |
| 1623 | bool HasDependencies() const { |
| 1624 | return (flags_ & kAllDependOnBits); |
| 1625 | } |
| 1626 | |
| 1627 | // Returns true if there are no side effects or dependencies. |
| 1628 | bool DoesNothing() const { |
| 1629 | return flags_ == 0; |
| 1630 | } |
| 1631 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1632 | // Returns true if something is written. |
| 1633 | bool DoesAnyWrite() const { |
| 1634 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1635 | } |
| 1636 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1637 | // Returns true if something is read. |
| 1638 | bool DoesAnyRead() const { |
| 1639 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1640 | } |
| 1641 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1642 | // Returns true if potentially everything is written and read |
| 1643 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1644 | bool DoesAllReadWrite() const { |
| 1645 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1646 | } |
| 1647 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1648 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1649 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1652 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1653 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1654 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1655 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1659 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1660 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1661 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1662 | for (int s = kLastBit; s >= 0; s--) { |
| 1663 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1664 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1665 | // This is a bit for the GC side effect. |
| 1666 | if (current_bit_is_set) { |
| 1667 | flags += "GC"; |
| 1668 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1669 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1670 | } else { |
| 1671 | // This is a bit for the array/field analysis. |
| 1672 | // The underscore character stands for the 'can trigger GC' bit. |
| 1673 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1674 | if (current_bit_is_set) { |
| 1675 | flags += kDebug[s]; |
| 1676 | } |
| 1677 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1678 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1679 | flags += "|"; |
| 1680 | } |
| 1681 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1682 | } |
| 1683 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1684 | } |
| 1685 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1686 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1687 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1688 | private: |
| 1689 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1690 | |
| 1691 | static constexpr int kFieldWriteOffset = 0; |
| 1692 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1693 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1694 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1695 | |
| 1696 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1697 | |
| 1698 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1699 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1700 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1701 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1702 | |
| 1703 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1704 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1705 | |
| 1706 | // Aliases. |
| 1707 | |
| 1708 | static_assert(kChangeBits == kDependOnBits, |
| 1709 | "the 'change' bits should match the 'depend on' bits."); |
| 1710 | |
| 1711 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1712 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1713 | static constexpr uint64_t kAllWrites = |
| 1714 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1715 | static constexpr uint64_t kAllReads = |
| 1716 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1717 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1718 | // Translates type to bit flag. |
| 1719 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1720 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1721 | const uint64_t one = 1; |
| 1722 | const int shift = type; // 0-based consecutive enum |
| 1723 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1724 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1725 | return one << (type + offset); |
| 1726 | } |
| 1727 | |
| 1728 | // Private constructor on direct flags value. |
| 1729 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1730 | |
| 1731 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1732 | }; |
| 1733 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1734 | // 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] | 1735 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1736 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1737 | HEnvironment(ArenaAllocator* arena, |
| 1738 | size_t number_of_vregs, |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1739 | ArtMethod* method, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1740 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1741 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1742 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1743 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1744 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1745 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1746 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1747 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1748 | } |
| 1749 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1750 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1751 | : HEnvironment(arena, |
| 1752 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1753 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1754 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1755 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1756 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1757 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1758 | if (parent_ != nullptr) { |
| 1759 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1760 | } else { |
| 1761 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1762 | parent_->CopyFrom(parent); |
| 1763 | if (parent->GetParent() != nullptr) { |
| 1764 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1765 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1766 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1769 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1770 | void CopyFrom(HEnvironment* environment); |
| 1771 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1772 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1773 | // input to the loop phi instead. This is for inserting instructions that |
| 1774 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1775 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1776 | |
| 1777 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1778 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1782 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1785 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1786 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1787 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1788 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1789 | HEnvironment* GetParent() const { return parent_; } |
| 1790 | |
| 1791 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1792 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1796 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | uint32_t GetDexPc() const { |
| 1800 | return dex_pc_; |
| 1801 | } |
| 1802 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1803 | ArtMethod* GetMethod() const { |
| 1804 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1805 | } |
| 1806 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1807 | HInstruction* GetHolder() const { |
| 1808 | return holder_; |
| 1809 | } |
| 1810 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1811 | |
| 1812 | bool IsFromInlinedInvoke() const { |
| 1813 | return GetParent() != nullptr; |
| 1814 | } |
| 1815 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1816 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1817 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1818 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1819 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1820 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1821 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1822 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1823 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1824 | HInstruction* const holder_; |
| 1825 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1826 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1827 | |
| 1828 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1829 | }; |
| 1830 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1831 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1832 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1833 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1834 | : previous_(nullptr), |
| 1835 | next_(nullptr), |
| 1836 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1837 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1838 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1839 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1840 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1841 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1842 | locations_(nullptr), |
| 1843 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1844 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1845 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1846 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1847 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1848 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1849 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1850 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1851 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1852 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1853 | enum InstructionKind { |
| 1854 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1855 | }; |
| 1856 | #undef DECLARE_KIND |
| 1857 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1858 | HInstruction* GetNext() const { return next_; } |
| 1859 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1860 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1861 | HInstruction* GetNextDisregardingMoves() const; |
| 1862 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1863 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1864 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1865 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1866 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1867 | bool IsInBlock() const { return block_ != nullptr; } |
| 1868 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1869 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1870 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1871 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1872 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1873 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1874 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1875 | |
| 1876 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1877 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1878 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1879 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1880 | } |
| 1881 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1882 | HInputsRef GetInputs() { |
| 1883 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1884 | } |
| 1885 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1886 | HConstInputsRef GetInputs() const { |
| 1887 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1891 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1892 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 1893 | bool HasInput(HInstruction* input) const { |
| 1894 | for (const HInstruction* i : GetInputs()) { |
| 1895 | if (i == input) { |
| 1896 | return true; |
| 1897 | } |
| 1898 | } |
| 1899 | return false; |
| 1900 | } |
| 1901 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1902 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1903 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1904 | } |
| 1905 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1906 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1907 | virtual const char* DebugName() const = 0; |
| 1908 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1909 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1910 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1911 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1912 | |
| 1913 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1914 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1915 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1916 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 1917 | // Can the instruction throw? |
| 1918 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 1919 | // 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] | 1920 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1921 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1922 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1923 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1924 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1925 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1926 | // Does not apply for all instructions, but having this at top level greatly |
| 1927 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1928 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1929 | virtual bool CanBeNull() const { |
| 1930 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1931 | return true; |
| 1932 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1933 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1934 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1935 | return false; |
| 1936 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1937 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1938 | virtual bool IsActualObject() const { |
| 1939 | return GetType() == Primitive::kPrimNot; |
| 1940 | } |
| 1941 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1942 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1943 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1944 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1945 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1946 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1947 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1948 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1949 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1950 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1951 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1952 | // Note: fixup_end remains valid across push_front(). |
| 1953 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1954 | HUseListNode<HInstruction*>* new_node = |
| 1955 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1956 | uses_.push_front(*new_node); |
| 1957 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1960 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1961 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1962 | // Note: env_fixup_end remains valid across push_front(). |
| 1963 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 1964 | HUseListNode<HEnvironment*>* new_node = |
| 1965 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 1966 | env_uses_.push_front(*new_node); |
| 1967 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1968 | } |
| 1969 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1970 | void RemoveAsUserOfInput(size_t input) { |
| 1971 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1972 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1973 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1974 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1975 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1976 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1977 | void RemoveAsUserOfAllInputs() { |
| 1978 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 1979 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1980 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1981 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 1982 | } |
| 1983 | } |
| 1984 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1985 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1986 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1987 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1988 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 1989 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 1990 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1991 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1992 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1993 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1994 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 1995 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1996 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 1997 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1998 | !CanThrow() && |
| 1999 | !IsSuspendCheck() && |
| 2000 | !IsControlFlow() && |
| 2001 | !IsNativeDebugInfo() && |
| 2002 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2003 | // If we added an explicit barrier then we should keep it. |
| 2004 | !IsMemoryBarrier(); |
| 2005 | } |
| 2006 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2007 | bool IsDeadAndRemovable() const { |
| 2008 | return IsRemovable() && !HasUses(); |
| 2009 | } |
| 2010 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2011 | // Does this instruction strictly dominate `other_instruction`? |
| 2012 | // Returns false if this instruction and `other_instruction` are the same. |
| 2013 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2014 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2015 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2016 | int GetId() const { return id_; } |
| 2017 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2018 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2019 | int GetSsaIndex() const { return ssa_index_; } |
| 2020 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2021 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2022 | |
| 2023 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2024 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2025 | // Set the `environment_` field. Raw because this method does not |
| 2026 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2027 | void SetRawEnvironment(HEnvironment* environment) { |
| 2028 | DCHECK(environment_ == nullptr); |
| 2029 | DCHECK_EQ(environment->GetHolder(), this); |
| 2030 | environment_ = environment; |
| 2031 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2032 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2033 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2034 | DCHECK(environment_ != nullptr); |
| 2035 | DCHECK_EQ(environment->GetHolder(), this); |
| 2036 | DCHECK(environment->GetParent() == nullptr); |
| 2037 | environment->parent_ = environment_; |
| 2038 | environment_ = environment; |
| 2039 | } |
| 2040 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2041 | void RemoveEnvironment(); |
| 2042 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2043 | // Set the environment of this instruction, copying it from `environment`. While |
| 2044 | // copying, the uses lists are being updated. |
| 2045 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2046 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2047 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2048 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2049 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2050 | if (environment->GetParent() != nullptr) { |
| 2051 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2052 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2053 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2054 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2055 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2056 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2057 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2058 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2059 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2060 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2061 | if (environment->GetParent() != nullptr) { |
| 2062 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2063 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2066 | // Returns the number of entries in the environment. Typically, that is the |
| 2067 | // number of dex registers in a method. It could be more in case of inlining. |
| 2068 | size_t EnvironmentSize() const; |
| 2069 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2070 | LocationSummary* GetLocations() const { return locations_; } |
| 2071 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2072 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2073 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2074 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2075 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2076 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2077 | // uses of this instruction by `other` are *not* updated. |
| 2078 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2079 | ReplaceWith(other); |
| 2080 | other->ReplaceInput(this, use_index); |
| 2081 | } |
| 2082 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2083 | // Move `this` instruction before `cursor` |
| 2084 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2085 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2086 | // Move `this` before its first user and out of any loops. If there is no |
| 2087 | // out-of-loop user that dominates all other users, move the instruction |
| 2088 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2089 | // |
| 2090 | // This can be used only on non-throwing instructions with no side effects that |
| 2091 | // have at least one use but no environment uses. |
| 2092 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2093 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2094 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2095 | bool Is##type() const; \ |
| 2096 | const H##type* As##type() const; \ |
| 2097 | H##type* As##type(); |
| 2098 | |
| 2099 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2100 | #undef INSTRUCTION_TYPE_CHECK |
| 2101 | |
| 2102 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2103 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2104 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2105 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2106 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2107 | #undef INSTRUCTION_TYPE_CHECK |
| 2108 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2109 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2110 | // TODO: this method is used by LICM and GVN with possibly different |
| 2111 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2112 | virtual bool CanBeMoved() const { return false; } |
| 2113 | |
| 2114 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2115 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2116 | return false; |
| 2117 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2118 | |
| 2119 | // Returns whether any data encoded in the two instructions is equal. |
| 2120 | // This method does not look at the inputs. Both instructions must be |
| 2121 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2122 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2123 | return false; |
| 2124 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2125 | |
| 2126 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2127 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2128 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2129 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2130 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2131 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2132 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2133 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2134 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2135 | InstructionKind GetKind() const PURE; |
| 2136 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2137 | |
| 2138 | virtual size_t ComputeHashCode() const { |
| 2139 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2140 | for (const HInstruction* input : GetInputs()) { |
| 2141 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2142 | } |
| 2143 | return result; |
| 2144 | } |
| 2145 | |
| 2146 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2147 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2148 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2149 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2150 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2151 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2152 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2153 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2154 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2155 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2156 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2157 | |
| 2158 | // Returns whether the code generation of the instruction will require to have access |
| 2159 | // to the current method. Such instructions are: |
| 2160 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2161 | // 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] | 2162 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2163 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2164 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2165 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2168 | // Returns whether the code generation of the instruction will require to have access |
| 2169 | // to the dex cache of the current method's declaring class via the current method. |
| 2170 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2171 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2172 | // Does this instruction have any use in an environment before |
| 2173 | // control flow hits 'other'? |
| 2174 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2175 | |
| 2176 | // Remove all references to environment uses of this instruction. |
| 2177 | // The caller must ensure that this is safe to do. |
| 2178 | void RemoveEnvironmentUsers(); |
| 2179 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2180 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2181 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2182 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2183 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2184 | // If set, the machine code for this instruction is assumed to be generated by |
| 2185 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2186 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2187 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2188 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2189 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2190 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2191 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2192 | return GetInputRecords()[i]; |
| 2193 | } |
| 2194 | |
| 2195 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2196 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2197 | input_records[index] = input; |
| 2198 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2199 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2200 | uint32_t GetPackedFields() const { |
| 2201 | return packed_fields_; |
| 2202 | } |
| 2203 | |
| 2204 | template <size_t flag> |
| 2205 | bool GetPackedFlag() const { |
| 2206 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2207 | } |
| 2208 | |
| 2209 | template <size_t flag> |
| 2210 | void SetPackedFlag(bool value = true) { |
| 2211 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2212 | } |
| 2213 | |
| 2214 | template <typename BitFieldType> |
| 2215 | typename BitFieldType::value_type GetPackedField() const { |
| 2216 | return BitFieldType::Decode(packed_fields_); |
| 2217 | } |
| 2218 | |
| 2219 | template <typename BitFieldType> |
| 2220 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2221 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2222 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2223 | } |
| 2224 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2225 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2226 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2227 | auto before_use_node = uses_.before_begin(); |
| 2228 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2229 | HInstruction* user = use_node->GetUser(); |
| 2230 | size_t input_index = use_node->GetIndex(); |
| 2231 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2232 | before_use_node = use_node; |
| 2233 | } |
| 2234 | } |
| 2235 | |
| 2236 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2237 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2238 | if (next != uses_.end()) { |
| 2239 | HInstruction* next_user = next->GetUser(); |
| 2240 | size_t next_index = next->GetIndex(); |
| 2241 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2242 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2243 | } |
| 2244 | } |
| 2245 | |
| 2246 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2247 | auto before_env_use_node = env_uses_.before_begin(); |
| 2248 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2249 | HEnvironment* user = env_use_node->GetUser(); |
| 2250 | size_t input_index = env_use_node->GetIndex(); |
| 2251 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2252 | before_env_use_node = env_use_node; |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2257 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2258 | if (next != env_uses_.end()) { |
| 2259 | HEnvironment* next_user = next->GetUser(); |
| 2260 | size_t next_index = next->GetIndex(); |
| 2261 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2262 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2263 | } |
| 2264 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2265 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2266 | HInstruction* previous_; |
| 2267 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2268 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2269 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2270 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2271 | // An instruction gets an id when it is added to the graph. |
| 2272 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2273 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2274 | int id_; |
| 2275 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2276 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2277 | int ssa_index_; |
| 2278 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2279 | // Packed fields. |
| 2280 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2281 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2282 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2283 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2284 | |
| 2285 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2286 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2287 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2288 | // The environment associated with this instruction. Not null if the instruction |
| 2289 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2290 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2291 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2292 | // Set by the code generator. |
| 2293 | LocationSummary* locations_; |
| 2294 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2295 | // Set by the liveness analysis. |
| 2296 | LiveInterval* live_interval_; |
| 2297 | |
| 2298 | // Set by the liveness analysis, this is the position in a linear |
| 2299 | // order of blocks where this instruction's live interval start. |
| 2300 | size_t lifetime_position_; |
| 2301 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2302 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2303 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2304 | // The reference handle part of the reference type info. |
| 2305 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2306 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2307 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2308 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2309 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2310 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2311 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2312 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2313 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2314 | |
| 2315 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2316 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2317 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2318 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2319 | // Iterates over the instructions, while preserving the next instruction |
| 2320 | // in case the current instruction gets removed from the list by the user |
| 2321 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2322 | class HInstructionIterator : public ValueObject { |
| 2323 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2324 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2325 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2326 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2329 | bool Done() const { return instruction_ == nullptr; } |
| 2330 | HInstruction* Current() const { return instruction_; } |
| 2331 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2332 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2333 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | private: |
| 2337 | HInstruction* instruction_; |
| 2338 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2339 | |
| 2340 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2341 | }; |
| 2342 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2343 | // Iterates over the instructions without saving the next instruction, |
| 2344 | // therefore handling changes in the graph potentially made by the user |
| 2345 | // of this iterator. |
| 2346 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2347 | public: |
| 2348 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2349 | : instruction_(instructions.first_instruction_) { |
| 2350 | } |
| 2351 | |
| 2352 | bool Done() const { return instruction_ == nullptr; } |
| 2353 | HInstruction* Current() const { return instruction_; } |
| 2354 | void Advance() { |
| 2355 | instruction_ = instruction_->GetNext(); |
| 2356 | } |
| 2357 | |
| 2358 | private: |
| 2359 | HInstruction* instruction_; |
| 2360 | |
| 2361 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2362 | }; |
| 2363 | |
| 2364 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2365 | class HBackwardInstructionIterator : public ValueObject { |
| 2366 | public: |
| 2367 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2368 | : instruction_(instructions.last_instruction_) { |
| 2369 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2370 | } |
| 2371 | |
| 2372 | bool Done() const { return instruction_ == nullptr; } |
| 2373 | HInstruction* Current() const { return instruction_; } |
| 2374 | void Advance() { |
| 2375 | instruction_ = next_; |
| 2376 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2377 | } |
| 2378 | |
| 2379 | private: |
| 2380 | HInstruction* instruction_; |
| 2381 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2382 | |
| 2383 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2384 | }; |
| 2385 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2386 | class HVariableInputSizeInstruction : public HInstruction { |
| 2387 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2388 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2389 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 2390 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2391 | } |
| 2392 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2393 | void AddInput(HInstruction* input); |
| 2394 | void InsertInputAt(size_t index, HInstruction* input); |
| 2395 | void RemoveInputAt(size_t index); |
| 2396 | |
| 2397 | protected: |
| 2398 | HVariableInputSizeInstruction(SideEffects side_effects, |
| 2399 | uint32_t dex_pc, |
| 2400 | ArenaAllocator* arena, |
| 2401 | size_t number_of_inputs, |
| 2402 | ArenaAllocKind kind) |
| 2403 | : HInstruction(side_effects, dex_pc), |
| 2404 | inputs_(number_of_inputs, arena->Adapter(kind)) {} |
| 2405 | |
| 2406 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
| 2407 | |
| 2408 | private: |
| 2409 | DISALLOW_COPY_AND_ASSIGN(HVariableInputSizeInstruction); |
| 2410 | }; |
| 2411 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2412 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2413 | class HTemplateInstruction: public HInstruction { |
| 2414 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2415 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2416 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2417 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2418 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2419 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2420 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2421 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2422 | } |
| 2423 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2424 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2425 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2426 | |
| 2427 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2428 | }; |
| 2429 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2430 | // HTemplateInstruction specialization for N=0. |
| 2431 | template<> |
| 2432 | class HTemplateInstruction<0>: public HInstruction { |
| 2433 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2434 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2435 | : HInstruction(side_effects, dex_pc) {} |
| 2436 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2437 | virtual ~HTemplateInstruction() {} |
| 2438 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2439 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2440 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2441 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | private: |
| 2445 | friend class SsaBuilder; |
| 2446 | }; |
| 2447 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2448 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2449 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2450 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2451 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2452 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2453 | this->template SetPackedField<TypeField>(type); |
| 2454 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2455 | virtual ~HExpression() {} |
| 2456 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2457 | Primitive::Type GetType() const OVERRIDE { |
| 2458 | return TypeField::Decode(this->GetPackedFields()); |
| 2459 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2460 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2461 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2462 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2463 | static constexpr size_t kFieldTypeSize = |
| 2464 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2465 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2466 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2467 | "Too many packed fields."); |
| 2468 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2469 | }; |
| 2470 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2471 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2472 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2473 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2474 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2475 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2476 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2477 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2478 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2479 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2480 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2481 | |
| 2482 | private: |
| 2483 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2484 | }; |
| 2485 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2486 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2487 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2488 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2489 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2490 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2491 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2492 | SetRawInputAt(0, value); |
| 2493 | } |
| 2494 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2495 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2496 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2497 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2498 | |
| 2499 | private: |
| 2500 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2501 | }; |
| 2502 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2503 | class HPhi FINAL : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2504 | public: |
| 2505 | HPhi(ArenaAllocator* arena, |
| 2506 | uint32_t reg_number, |
| 2507 | size_t number_of_inputs, |
| 2508 | Primitive::Type type, |
| 2509 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2510 | : HVariableInputSizeInstruction( |
| 2511 | SideEffects::None(), |
| 2512 | dex_pc, |
| 2513 | arena, |
| 2514 | number_of_inputs, |
| 2515 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2516 | reg_number_(reg_number) { |
| 2517 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2518 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2519 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2520 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2521 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2522 | SetPackedFlag<kFlagIsLive>(true); |
| 2523 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2524 | } |
| 2525 | |
| 2526 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2527 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2528 | return Primitive::PrimitiveKind(type); |
| 2529 | } |
| 2530 | |
| 2531 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2532 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2533 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2534 | void SetType(Primitive::Type new_type) { |
| 2535 | // Make sure that only valid type changes occur. The following are allowed: |
| 2536 | // (1) int -> float/ref (primitive type propagation), |
| 2537 | // (2) long -> double (primitive type propagation). |
| 2538 | DCHECK(GetType() == new_type || |
| 2539 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2540 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2541 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2542 | SetPackedField<TypeField>(new_type); |
| 2543 | } |
| 2544 | |
| 2545 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2546 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2547 | |
| 2548 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2549 | |
| 2550 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2551 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2552 | bool IsDead() const { return !IsLive(); } |
| 2553 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2554 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2555 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2556 | return other != nullptr |
| 2557 | && other->IsPhi() |
| 2558 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2559 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2560 | } |
| 2561 | |
| 2562 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2563 | // An equivalent phi is a phi having the same dex register and type. |
| 2564 | // It assumes that phis with the same dex register are adjacent. |
| 2565 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2566 | HInstruction* next = GetNext(); |
| 2567 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2568 | if (next->GetType() == GetType()) { |
| 2569 | return next->AsPhi(); |
| 2570 | } |
| 2571 | next = next->GetNext(); |
| 2572 | } |
| 2573 | return nullptr; |
| 2574 | } |
| 2575 | |
| 2576 | DECLARE_INSTRUCTION(Phi); |
| 2577 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2578 | private: |
| 2579 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2580 | static constexpr size_t kFieldTypeSize = |
| 2581 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2582 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2583 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2584 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2585 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2586 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2587 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2588 | const uint32_t reg_number_; |
| 2589 | |
| 2590 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2591 | }; |
| 2592 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2593 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2594 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2595 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2596 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2597 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2598 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2599 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2600 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2601 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2602 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2603 | |
| 2604 | private: |
| 2605 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2606 | }; |
| 2607 | |
| 2608 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2609 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2610 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2611 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2612 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2613 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2614 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2615 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2616 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2619 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2620 | |
| 2621 | private: |
| 2622 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2623 | }; |
| 2624 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2625 | class HConstant : public HExpression<0> { |
| 2626 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2627 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2628 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2629 | |
| 2630 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2631 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2632 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2633 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2634 | // Is this constant 0 in the arithmetic sense? |
| 2635 | virtual bool IsArithmeticZero() const { return false; } |
| 2636 | // Is this constant a 0-bit pattern? |
| 2637 | virtual bool IsZeroBitPattern() const { return false; } |
| 2638 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2639 | virtual bool IsOne() const { return false; } |
| 2640 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2641 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2642 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2643 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2644 | |
| 2645 | private: |
| 2646 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2647 | }; |
| 2648 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2649 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2650 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2651 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2652 | return true; |
| 2653 | } |
| 2654 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2655 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2656 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2657 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2658 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2659 | // The null constant representation is a 0-bit pattern. |
| 2660 | virtual bool IsZeroBitPattern() const { return true; } |
| 2661 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2662 | DECLARE_INSTRUCTION(NullConstant); |
| 2663 | |
| 2664 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2665 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2666 | |
| 2667 | friend class HGraph; |
| 2668 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2669 | }; |
| 2670 | |
| 2671 | // Constants of the type int. Those can be from Dex instructions, or |
| 2672 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2673 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2674 | public: |
| 2675 | int32_t GetValue() const { return value_; } |
| 2676 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2677 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2678 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2679 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2680 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2681 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2682 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2683 | return other->AsIntConstant()->value_ == value_; |
| 2684 | } |
| 2685 | |
| 2686 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2687 | |
| 2688 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2689 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2690 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2691 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2692 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2693 | // Integer constants are used to encode Boolean values as well, |
| 2694 | // where 1 means true and 0 means false. |
| 2695 | bool IsTrue() const { return GetValue() == 1; } |
| 2696 | bool IsFalse() const { return GetValue() == 0; } |
| 2697 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2698 | DECLARE_INSTRUCTION(IntConstant); |
| 2699 | |
| 2700 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2701 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2702 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2703 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2704 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2705 | |
| 2706 | const int32_t value_; |
| 2707 | |
| 2708 | friend class HGraph; |
| 2709 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2710 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2711 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2712 | }; |
| 2713 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2714 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2715 | public: |
| 2716 | int64_t GetValue() const { return value_; } |
| 2717 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2718 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2719 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2720 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2721 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2722 | return other->AsLongConstant()->value_ == value_; |
| 2723 | } |
| 2724 | |
| 2725 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2726 | |
| 2727 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2728 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2729 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2730 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2731 | |
| 2732 | DECLARE_INSTRUCTION(LongConstant); |
| 2733 | |
| 2734 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2735 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2736 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2737 | |
| 2738 | const int64_t value_; |
| 2739 | |
| 2740 | friend class HGraph; |
| 2741 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2742 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2743 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2744 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2745 | public: |
| 2746 | float GetValue() const { return value_; } |
| 2747 | |
| 2748 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2749 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2750 | } |
| 2751 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2752 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2753 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2754 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2755 | } |
| 2756 | |
| 2757 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2758 | |
| 2759 | bool IsMinusOne() const OVERRIDE { |
| 2760 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2761 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2762 | bool IsArithmeticZero() const OVERRIDE { |
| 2763 | return std::fpclassify(value_) == FP_ZERO; |
| 2764 | } |
| 2765 | bool IsArithmeticPositiveZero() const { |
| 2766 | return IsArithmeticZero() && !std::signbit(value_); |
| 2767 | } |
| 2768 | bool IsArithmeticNegativeZero() const { |
| 2769 | return IsArithmeticZero() && std::signbit(value_); |
| 2770 | } |
| 2771 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2772 | 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] | 2773 | } |
| 2774 | bool IsOne() const OVERRIDE { |
| 2775 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2776 | } |
| 2777 | bool IsNaN() const { |
| 2778 | return std::isnan(value_); |
| 2779 | } |
| 2780 | |
| 2781 | DECLARE_INSTRUCTION(FloatConstant); |
| 2782 | |
| 2783 | private: |
| 2784 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2785 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2786 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2787 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2788 | |
| 2789 | const float value_; |
| 2790 | |
| 2791 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2792 | friend class SsaBuilder; |
| 2793 | friend class HGraph; |
| 2794 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2795 | }; |
| 2796 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2797 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2798 | public: |
| 2799 | double GetValue() const { return value_; } |
| 2800 | |
| 2801 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2802 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2803 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2804 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2805 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2806 | } |
| 2807 | |
| 2808 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2809 | |
| 2810 | bool IsMinusOne() const OVERRIDE { |
| 2811 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2812 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2813 | bool IsArithmeticZero() const OVERRIDE { |
| 2814 | return std::fpclassify(value_) == FP_ZERO; |
| 2815 | } |
| 2816 | bool IsArithmeticPositiveZero() const { |
| 2817 | return IsArithmeticZero() && !std::signbit(value_); |
| 2818 | } |
| 2819 | bool IsArithmeticNegativeZero() const { |
| 2820 | return IsArithmeticZero() && std::signbit(value_); |
| 2821 | } |
| 2822 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2823 | 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] | 2824 | } |
| 2825 | bool IsOne() const OVERRIDE { |
| 2826 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2827 | } |
| 2828 | bool IsNaN() const { |
| 2829 | return std::isnan(value_); |
| 2830 | } |
| 2831 | |
| 2832 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2833 | |
| 2834 | private: |
| 2835 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2836 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2837 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2838 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2839 | |
| 2840 | const double value_; |
| 2841 | |
| 2842 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2843 | friend class SsaBuilder; |
| 2844 | friend class HGraph; |
| 2845 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2846 | }; |
| 2847 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2848 | // Conditional branch. A block ending with an HIf instruction must have |
| 2849 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2850 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2851 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2852 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2853 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2854 | SetRawInputAt(0, input); |
| 2855 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2856 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2857 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2858 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2859 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2860 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2864 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2865 | } |
| 2866 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2867 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2868 | |
| 2869 | private: |
| 2870 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2871 | }; |
| 2872 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2873 | |
| 2874 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2875 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2876 | // non-exceptional control flow. |
| 2877 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2878 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2879 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2880 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2881 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2882 | kEntry, |
| 2883 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2884 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2885 | }; |
| 2886 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2887 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2888 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2889 | SetPackedField<BoundaryKindField>(kind); |
| 2890 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2891 | |
| 2892 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2893 | |
| 2894 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2895 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2896 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2897 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2898 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2899 | } |
| 2900 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2901 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2902 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2903 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2904 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2905 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | // If not present already, adds `handler` to its block's list of exception |
| 2909 | // handlers. |
| 2910 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2911 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2912 | GetBlock()->AddSuccessor(handler); |
| 2913 | } |
| 2914 | } |
| 2915 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2916 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2917 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2918 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2919 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2920 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2921 | DECLARE_INSTRUCTION(TryBoundary); |
| 2922 | |
| 2923 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2924 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2925 | static constexpr size_t kFieldBoundaryKindSize = |
| 2926 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2927 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2928 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2929 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2930 | "Too many packed fields."); |
| 2931 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2932 | |
| 2933 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2934 | }; |
| 2935 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2936 | // Deoptimize to interpreter, upon checking a condition. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2937 | class HDeoptimize FINAL : public HTemplateInstruction<1> { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2938 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2939 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2940 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2941 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2942 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2943 | SetRawInputAt(0, cond); |
| 2944 | } |
| 2945 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2946 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2947 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2948 | return true; |
| 2949 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2950 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2951 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2952 | |
| 2953 | DECLARE_INSTRUCTION(Deoptimize); |
| 2954 | |
| 2955 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2956 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2957 | }; |
| 2958 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2959 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 2960 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 2961 | // if it's true, starts to do deoptimization. |
| 2962 | // It has a 4-byte slot on stack. |
| 2963 | // TODO: allocate a register for this flag. |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2964 | class HShouldDeoptimizeFlag FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2965 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2966 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 2967 | // with regard to other passes. |
| 2968 | HShouldDeoptimizeFlag(ArenaAllocator* arena, uint32_t dex_pc) |
| 2969 | : HVariableInputSizeInstruction(SideEffects::None(), dex_pc, arena, 0, kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2970 | } |
| 2971 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2972 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimInt; } |
| 2973 | |
| 2974 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 2975 | // further guard elimination/motion since a guard might have been used for justification |
| 2976 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 2977 | // to avoid other optimizations trying to move it. |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2978 | bool CanBeMoved() const OVERRIDE { return false; } |
| 2979 | |
| 2980 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 2981 | |
| 2982 | private: |
| 2983 | DISALLOW_COPY_AND_ASSIGN(HShouldDeoptimizeFlag); |
| 2984 | }; |
| 2985 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2986 | // Represents the ArtMethod that was passed as a first argument to |
| 2987 | // the method. It is used by instructions that depend on it, like |
| 2988 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2989 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2990 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2991 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2992 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2993 | |
| 2994 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2995 | |
| 2996 | private: |
| 2997 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2998 | }; |
| 2999 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3000 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3001 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3002 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3003 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3004 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3005 | kVTable, |
| 3006 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3007 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3008 | }; |
| 3009 | HClassTableGet(HInstruction* cls, |
| 3010 | Primitive::Type type, |
| 3011 | TableKind kind, |
| 3012 | size_t index, |
| 3013 | uint32_t dex_pc) |
| 3014 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3015 | index_(index) { |
| 3016 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3017 | SetRawInputAt(0, cls); |
| 3018 | } |
| 3019 | |
| 3020 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3021 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3022 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3023 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3024 | } |
| 3025 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3026 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3027 | size_t GetIndex() const { return index_; } |
| 3028 | |
| 3029 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3030 | |
| 3031 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3032 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 3033 | static constexpr size_t kFieldTableKindSize = |
| 3034 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3035 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3036 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3037 | "Too many packed fields."); |
| 3038 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3039 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3040 | // The index of the ArtMethod in the table. |
| 3041 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3042 | |
| 3043 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 3044 | }; |
| 3045 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3046 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3047 | // have one successor for each entry in the switch table, and the final successor |
| 3048 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3049 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3050 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3051 | HPackedSwitch(int32_t start_value, |
| 3052 | uint32_t num_entries, |
| 3053 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3054 | uint32_t dex_pc = kNoDexPc) |
| 3055 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 3056 | start_value_(start_value), |
| 3057 | num_entries_(num_entries) { |
| 3058 | SetRawInputAt(0, input); |
| 3059 | } |
| 3060 | |
| 3061 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3062 | |
| 3063 | int32_t GetStartValue() const { return start_value_; } |
| 3064 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3065 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3066 | |
| 3067 | HBasicBlock* GetDefaultBlock() const { |
| 3068 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3069 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3070 | } |
| 3071 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3072 | |
| 3073 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3074 | const int32_t start_value_; |
| 3075 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3076 | |
| 3077 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 3078 | }; |
| 3079 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3080 | class HUnaryOperation : public HExpression<1> { |
| 3081 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3082 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3083 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3084 | SetRawInputAt(0, input); |
| 3085 | } |
| 3086 | |
| 3087 | HInstruction* GetInput() const { return InputAt(0); } |
| 3088 | Primitive::Type GetResultType() const { return GetType(); } |
| 3089 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3090 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3091 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3092 | return true; |
| 3093 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3094 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3095 | // Try to statically evaluate `this` and return a HConstant |
| 3096 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3097 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3098 | HConstant* TryStaticEvaluation() const; |
| 3099 | |
| 3100 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3101 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3102 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3103 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3104 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3105 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3106 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3107 | |
| 3108 | private: |
| 3109 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 3110 | }; |
| 3111 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3112 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3113 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3114 | HBinaryOperation(Primitive::Type result_type, |
| 3115 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3116 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3117 | SideEffects side_effects = SideEffects::None(), |
| 3118 | uint32_t dex_pc = kNoDexPc) |
| 3119 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3120 | SetRawInputAt(0, left); |
| 3121 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3122 | } |
| 3123 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3124 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3125 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3126 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3127 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3128 | virtual bool IsCommutative() const { return false; } |
| 3129 | |
| 3130 | // Put constant on the right. |
| 3131 | // Returns whether order is changed. |
| 3132 | bool OrderInputsWithConstantOnTheRight() { |
| 3133 | HInstruction* left = InputAt(0); |
| 3134 | HInstruction* right = InputAt(1); |
| 3135 | if (left->IsConstant() && !right->IsConstant()) { |
| 3136 | ReplaceInput(right, 0); |
| 3137 | ReplaceInput(left, 1); |
| 3138 | return true; |
| 3139 | } |
| 3140 | return false; |
| 3141 | } |
| 3142 | |
| 3143 | // Order inputs by instruction id, but favor constant on the right side. |
| 3144 | // This helps GVN for commutative ops. |
| 3145 | void OrderInputs() { |
| 3146 | DCHECK(IsCommutative()); |
| 3147 | HInstruction* left = InputAt(0); |
| 3148 | HInstruction* right = InputAt(1); |
| 3149 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3150 | return; |
| 3151 | } |
| 3152 | if (OrderInputsWithConstantOnTheRight()) { |
| 3153 | return; |
| 3154 | } |
| 3155 | // Order according to instruction id. |
| 3156 | if (left->GetId() > right->GetId()) { |
| 3157 | ReplaceInput(right, 0); |
| 3158 | ReplaceInput(left, 1); |
| 3159 | } |
| 3160 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3161 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3162 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3163 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3164 | return true; |
| 3165 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3166 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3167 | // Try to statically evaluate `this` and return a HConstant |
| 3168 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3169 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3170 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3171 | |
| 3172 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3173 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3174 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3175 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3176 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3177 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3178 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3179 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3180 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3181 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3182 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3183 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3184 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3185 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3186 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3187 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3188 | // 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] | 3189 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3190 | HConstant* GetConstantRight() const; |
| 3191 | |
| 3192 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3193 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3194 | HInstruction* GetLeastConstantLeft() const; |
| 3195 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3196 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3197 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3198 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3199 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3200 | }; |
| 3201 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3202 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3203 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3204 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3205 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3206 | kGtBias, // return 1 for NaN comparisons |
| 3207 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3208 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3209 | }; |
| 3210 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3211 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3212 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3213 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3214 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3215 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3216 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3217 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3218 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3219 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3220 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3221 | // `instruction`, and disregard moves in between. |
| 3222 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3223 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3224 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3225 | |
| 3226 | virtual IfCondition GetCondition() const = 0; |
| 3227 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3228 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3229 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3230 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3231 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3232 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3233 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3234 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3235 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3236 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3237 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3238 | } |
| 3239 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3240 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3241 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3242 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3243 | if (if_cond == kCondNE) { |
| 3244 | return true; |
| 3245 | } else if (if_cond == kCondEQ) { |
| 3246 | return false; |
| 3247 | } |
| 3248 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3252 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3253 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3254 | if (if_cond == kCondEQ) { |
| 3255 | return true; |
| 3256 | } else if (if_cond == kCondNE) { |
| 3257 | return false; |
| 3258 | } |
| 3259 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3260 | } |
| 3261 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3262 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3263 | // Needed if we merge a HCompare into a HCondition. |
| 3264 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3265 | static constexpr size_t kFieldComparisonBiasSize = |
| 3266 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3267 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3268 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3269 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3270 | using ComparisonBiasField = |
| 3271 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3272 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3273 | template <typename T> |
| 3274 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3275 | |
| 3276 | template <typename T> |
| 3277 | int32_t CompareFP(T x, T y) const { |
| 3278 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3279 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3280 | // Handle the bias. |
| 3281 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3282 | } |
| 3283 | |
| 3284 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3285 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3286 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3287 | } |
| 3288 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3289 | private: |
| 3290 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3291 | }; |
| 3292 | |
| 3293 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3294 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3295 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3296 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3297 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3298 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3299 | bool IsCommutative() const OVERRIDE { return true; } |
| 3300 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3301 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3302 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3303 | return MakeConstantCondition(true, GetDexPc()); |
| 3304 | } |
| 3305 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3306 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3307 | } |
| 3308 | // In the following Evaluate methods, a HCompare instruction has |
| 3309 | // been merged into this HEqual instruction; evaluate it as |
| 3310 | // `Compare(x, y) == 0`. |
| 3311 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3312 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3313 | GetDexPc()); |
| 3314 | } |
| 3315 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3316 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3317 | } |
| 3318 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3319 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3320 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3321 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3322 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3323 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3324 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3325 | return kCondEQ; |
| 3326 | } |
| 3327 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3328 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3329 | return kCondNE; |
| 3330 | } |
| 3331 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3332 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3333 | template <typename T> static bool Compute(T x, T y) { return x == y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3334 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3335 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3336 | }; |
| 3337 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3338 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3339 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3340 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3341 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3342 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3343 | bool IsCommutative() const OVERRIDE { return true; } |
| 3344 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3345 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3346 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3347 | return MakeConstantCondition(false, GetDexPc()); |
| 3348 | } |
| 3349 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3350 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3351 | } |
| 3352 | // In the following Evaluate methods, a HCompare instruction has |
| 3353 | // been merged into this HNotEqual instruction; evaluate it as |
| 3354 | // `Compare(x, y) != 0`. |
| 3355 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3356 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3357 | } |
| 3358 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3359 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3360 | } |
| 3361 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3362 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3363 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3364 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3365 | DECLARE_INSTRUCTION(NotEqual); |
| 3366 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3367 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3368 | return kCondNE; |
| 3369 | } |
| 3370 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3371 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3372 | return kCondEQ; |
| 3373 | } |
| 3374 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3375 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3376 | template <typename T> static bool Compute(T x, T y) { return x != y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3377 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3378 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3379 | }; |
| 3380 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3381 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3382 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3383 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3384 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3385 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3386 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3387 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3388 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3389 | // In the following Evaluate methods, a HCompare instruction has |
| 3390 | // been merged into this HLessThan instruction; evaluate it as |
| 3391 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3392 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3393 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3394 | } |
| 3395 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3396 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3397 | } |
| 3398 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3399 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3400 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3401 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3402 | DECLARE_INSTRUCTION(LessThan); |
| 3403 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3404 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3405 | return kCondLT; |
| 3406 | } |
| 3407 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3408 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3409 | return kCondGE; |
| 3410 | } |
| 3411 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3412 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3413 | template <typename T> static bool Compute(T x, T y) { return x < y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3414 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3415 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3416 | }; |
| 3417 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3418 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3419 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3420 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3421 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3422 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3423 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3424 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3425 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3426 | // In the following Evaluate methods, a HCompare instruction has |
| 3427 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3428 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3429 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3430 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3431 | } |
| 3432 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3433 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3434 | } |
| 3435 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3436 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3437 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3438 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3439 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3440 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3441 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3442 | return kCondLE; |
| 3443 | } |
| 3444 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3445 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3446 | return kCondGT; |
| 3447 | } |
| 3448 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3449 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3450 | template <typename T> static bool Compute(T x, T y) { return x <= y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3451 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3452 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3453 | }; |
| 3454 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3455 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3456 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3457 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3458 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3459 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3460 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3461 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3462 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3463 | // In the following Evaluate methods, a HCompare instruction has |
| 3464 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3465 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3466 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3467 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3468 | } |
| 3469 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3470 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3471 | } |
| 3472 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3473 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3474 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3475 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3476 | DECLARE_INSTRUCTION(GreaterThan); |
| 3477 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3478 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3479 | return kCondGT; |
| 3480 | } |
| 3481 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3482 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3483 | return kCondLE; |
| 3484 | } |
| 3485 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3486 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3487 | template <typename T> static bool Compute(T x, T y) { return x > y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3488 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3489 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3490 | }; |
| 3491 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3492 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3493 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3494 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3495 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3496 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3497 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3498 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3499 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3500 | // In the following Evaluate methods, a HCompare instruction has |
| 3501 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3502 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3503 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3504 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3505 | } |
| 3506 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3507 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3508 | } |
| 3509 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3510 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3511 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3512 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3513 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3514 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3515 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3516 | return kCondGE; |
| 3517 | } |
| 3518 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3519 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3520 | return kCondLT; |
| 3521 | } |
| 3522 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3523 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3524 | template <typename T> static bool Compute(T x, T y) { return x >= y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3525 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3526 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3527 | }; |
| 3528 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3529 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3530 | public: |
| 3531 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3532 | : HCondition(first, second, dex_pc) {} |
| 3533 | |
| 3534 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3535 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3536 | } |
| 3537 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3538 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3539 | } |
| 3540 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3541 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3542 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3543 | UNREACHABLE(); |
| 3544 | } |
| 3545 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3546 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3547 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3548 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | DECLARE_INSTRUCTION(Below); |
| 3552 | |
| 3553 | IfCondition GetCondition() const OVERRIDE { |
| 3554 | return kCondB; |
| 3555 | } |
| 3556 | |
| 3557 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3558 | return kCondAE; |
| 3559 | } |
| 3560 | |
| 3561 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3562 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3563 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3564 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3565 | |
| 3566 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3567 | }; |
| 3568 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3569 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3570 | public: |
| 3571 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3572 | : HCondition(first, second, dex_pc) {} |
| 3573 | |
| 3574 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3575 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3576 | } |
| 3577 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3578 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3579 | } |
| 3580 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3581 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3582 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3583 | UNREACHABLE(); |
| 3584 | } |
| 3585 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3586 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3587 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3588 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3592 | |
| 3593 | IfCondition GetCondition() const OVERRIDE { |
| 3594 | return kCondBE; |
| 3595 | } |
| 3596 | |
| 3597 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3598 | return kCondA; |
| 3599 | } |
| 3600 | |
| 3601 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3602 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3603 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3604 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3605 | |
| 3606 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3607 | }; |
| 3608 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3609 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3610 | public: |
| 3611 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3612 | : HCondition(first, second, dex_pc) {} |
| 3613 | |
| 3614 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3615 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3616 | } |
| 3617 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3618 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3619 | } |
| 3620 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3621 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3622 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3623 | UNREACHABLE(); |
| 3624 | } |
| 3625 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3626 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3627 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3628 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | DECLARE_INSTRUCTION(Above); |
| 3632 | |
| 3633 | IfCondition GetCondition() const OVERRIDE { |
| 3634 | return kCondA; |
| 3635 | } |
| 3636 | |
| 3637 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3638 | return kCondBE; |
| 3639 | } |
| 3640 | |
| 3641 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3642 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3643 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3644 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3645 | |
| 3646 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3647 | }; |
| 3648 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3649 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3650 | public: |
| 3651 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3652 | : HCondition(first, second, dex_pc) {} |
| 3653 | |
| 3654 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3655 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3656 | } |
| 3657 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3658 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3659 | } |
| 3660 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3661 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3662 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3663 | UNREACHABLE(); |
| 3664 | } |
| 3665 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3666 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3667 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3668 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3672 | |
| 3673 | IfCondition GetCondition() const OVERRIDE { |
| 3674 | return kCondAE; |
| 3675 | } |
| 3676 | |
| 3677 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3678 | return kCondB; |
| 3679 | } |
| 3680 | |
| 3681 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3682 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3683 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3684 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3685 | |
| 3686 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3687 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3688 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3689 | // Instruction to check how two inputs compare to each other. |
| 3690 | // 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] | 3691 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3692 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3693 | // Note that `comparison_type` is the type of comparison performed |
| 3694 | // between the comparison's inputs, not the type of the instantiated |
| 3695 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3696 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3697 | HInstruction* first, |
| 3698 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3699 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3700 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3701 | : HBinaryOperation(Primitive::kPrimInt, |
| 3702 | first, |
| 3703 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3704 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3705 | dex_pc) { |
| 3706 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3707 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3708 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3709 | } |
| 3710 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3711 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3712 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3713 | |
| 3714 | template <typename T> |
| 3715 | int32_t ComputeFP(T x, T y) const { |
| 3716 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3717 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3718 | // Handle the bias. |
| 3719 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3720 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3721 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3722 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3723 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3724 | // reach this code path when processing a freshly built HIR |
| 3725 | // graph. However HCompare integer instructions can be synthesized |
| 3726 | // by the instruction simplifier to implement IntegerCompare and |
| 3727 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3728 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3729 | } |
| 3730 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3731 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3732 | } |
| 3733 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3734 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3735 | } |
| 3736 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3737 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3738 | } |
| 3739 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3740 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3741 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3742 | } |
| 3743 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3744 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3745 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3746 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3747 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3748 | bool IsGtBias() const { |
| 3749 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3750 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3751 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3752 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3753 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3754 | // Comparisons do not require a runtime call in any back end. |
| 3755 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3756 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3757 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3758 | DECLARE_INSTRUCTION(Compare); |
| 3759 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3760 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3761 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3762 | static constexpr size_t kFieldComparisonBiasSize = |
| 3763 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3764 | static constexpr size_t kNumberOfComparePackedBits = |
| 3765 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3766 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3767 | using ComparisonBiasField = |
| 3768 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3769 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3770 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3771 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3772 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3773 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3774 | } |
| 3775 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3776 | private: |
| 3777 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3778 | }; |
| 3779 | |
Nicolas Geoffray | 2b615ba | 2017-01-06 14:40:07 +0000 | [diff] [blame] | 3780 | class HNewInstance FINAL : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3781 | public: |
| 3782 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3783 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3784 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3785 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3786 | bool finalizable, |
| 3787 | QuickEntrypointEnum entrypoint) |
| 3788 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3789 | type_index_(type_index), |
| 3790 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3791 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3792 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3793 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3794 | } |
| 3795 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3796 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3797 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3798 | |
| 3799 | // Calls runtime so needs an environment. |
| 3800 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3801 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3802 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3803 | bool CanThrow() const OVERRIDE { return true; } |
| 3804 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 3805 | bool NeedsChecks() const { |
| 3806 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 3807 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3808 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3809 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3810 | |
| 3811 | bool CanBeNull() const OVERRIDE { return false; } |
| 3812 | |
| 3813 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3814 | |
| 3815 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3816 | entrypoint_ = entrypoint; |
| 3817 | } |
| 3818 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 3819 | HLoadClass* GetLoadClass() const { |
| 3820 | HInstruction* input = InputAt(0); |
| 3821 | if (input->IsClinitCheck()) { |
| 3822 | input = input->InputAt(0); |
| 3823 | } |
| 3824 | DCHECK(input->IsLoadClass()); |
| 3825 | return input->AsLoadClass(); |
| 3826 | } |
| 3827 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3828 | bool IsStringAlloc() const; |
| 3829 | |
| 3830 | DECLARE_INSTRUCTION(NewInstance); |
| 3831 | |
| 3832 | private: |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 3833 | static constexpr size_t kFlagFinalizable = kNumberOfExpressionPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3834 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3835 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3836 | "Too many packed fields."); |
| 3837 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3838 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3839 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3840 | QuickEntrypointEnum entrypoint_; |
| 3841 | |
| 3842 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3843 | }; |
| 3844 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3845 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3846 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3847 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3848 | }; |
| 3849 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3850 | enum IntrinsicSideEffects { |
| 3851 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3852 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3853 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3854 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3855 | }; |
| 3856 | |
| 3857 | enum IntrinsicExceptions { |
| 3858 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3859 | kCanThrow // Intrinsic may throw exceptions. |
| 3860 | }; |
| 3861 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3862 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3863 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3864 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3865 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3866 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3867 | SetRawInputAt(index, argument); |
| 3868 | } |
| 3869 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3870 | // Return the number of arguments. This number can be lower than |
| 3871 | // the number of inputs returned by InputCount(), as some invoke |
| 3872 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3873 | // inputs at the end of their list of inputs. |
| 3874 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3875 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3876 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3877 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3878 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3879 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3880 | InvokeType GetInvokeType() const { |
| 3881 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3882 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3883 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3884 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3885 | return intrinsic_; |
| 3886 | } |
| 3887 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3888 | void SetIntrinsic(Intrinsics intrinsic, |
| 3889 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3890 | IntrinsicSideEffects side_effects, |
| 3891 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3892 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3893 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3894 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3895 | } |
| 3896 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 3897 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 3898 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3899 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3900 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 3901 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3902 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3903 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3904 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3905 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3906 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3907 | uint32_t* GetIntrinsicOptimizations() { |
| 3908 | return &intrinsic_optimizations_; |
| 3909 | } |
| 3910 | |
| 3911 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3912 | return &intrinsic_optimizations_; |
| 3913 | } |
| 3914 | |
| 3915 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3916 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3917 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
| 3918 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3919 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3920 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3921 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3922 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 3923 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3924 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3925 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3926 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3927 | static constexpr size_t kFieldReturnTypeSize = |
| 3928 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3929 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3930 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3931 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3932 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3933 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3934 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3935 | HInvoke(ArenaAllocator* arena, |
| 3936 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3937 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3938 | Primitive::Type return_type, |
| 3939 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3940 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3941 | ArtMethod* resolved_method, |
| 3942 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3943 | : HVariableInputSizeInstruction( |
| 3944 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 3945 | dex_pc, |
| 3946 | arena, |
| 3947 | number_of_arguments + number_of_other_inputs, |
| 3948 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3949 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3950 | resolved_method_(resolved_method), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3951 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3952 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3953 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3954 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3955 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3956 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3957 | } |
| 3958 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3959 | uint32_t number_of_arguments_; |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3960 | ArtMethod* const resolved_method_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3961 | const uint32_t dex_method_index_; |
| 3962 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3963 | |
| 3964 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3965 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3966 | |
| 3967 | private: |
| 3968 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3969 | }; |
| 3970 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3971 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3972 | public: |
| 3973 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3974 | uint32_t number_of_arguments, |
| 3975 | Primitive::Type return_type, |
| 3976 | uint32_t dex_pc, |
| 3977 | uint32_t dex_method_index, |
| 3978 | InvokeType invoke_type) |
| 3979 | : HInvoke(arena, |
| 3980 | number_of_arguments, |
| 3981 | 0u /* number_of_other_inputs */, |
| 3982 | return_type, |
| 3983 | dex_pc, |
| 3984 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3985 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3986 | invoke_type) { |
| 3987 | } |
| 3988 | |
| 3989 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3990 | |
| 3991 | private: |
| 3992 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3993 | }; |
| 3994 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3995 | class HInvokePolymorphic FINAL : public HInvoke { |
| 3996 | public: |
| 3997 | HInvokePolymorphic(ArenaAllocator* arena, |
| 3998 | uint32_t number_of_arguments, |
| 3999 | Primitive::Type return_type, |
| 4000 | uint32_t dex_pc, |
| 4001 | uint32_t dex_method_index) |
| 4002 | : HInvoke(arena, |
| 4003 | number_of_arguments, |
| 4004 | 0u /* number_of_other_inputs */, |
| 4005 | return_type, |
| 4006 | dex_pc, |
| 4007 | dex_method_index, |
| 4008 | nullptr, |
| 4009 | kVirtual) {} |
| 4010 | |
| 4011 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4012 | |
| 4013 | private: |
| 4014 | DISALLOW_COPY_AND_ASSIGN(HInvokePolymorphic); |
| 4015 | }; |
| 4016 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4017 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4018 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4019 | // Requirements of this method call regarding the class |
| 4020 | // initialization (clinit) check of its declaring class. |
| 4021 | enum class ClinitCheckRequirement { |
| 4022 | kNone, // Class already initialized. |
| 4023 | kExplicit, // Static call having explicit clinit check as last input. |
| 4024 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4025 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4026 | }; |
| 4027 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4028 | // Determines how to load the target ArtMethod*. |
| 4029 | enum class MethodLoadKind { |
| 4030 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4031 | kStringInit, |
| 4032 | |
| 4033 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4034 | kRecursive, |
| 4035 | |
| 4036 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4037 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 4038 | kDirectAddress, |
| 4039 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4040 | // Load from resolved methods array in the dex cache using a PC-relative load. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4041 | // Used when we need to use the dex cache, for example for invoke-static that |
| 4042 | // may cause class initialization (the entry may point to a resolution method), |
| 4043 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 4044 | kDexCachePcRelative, |
| 4045 | |
| 4046 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 4047 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 4048 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 4049 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4050 | kDexCacheViaMethod, |
| 4051 | }; |
| 4052 | |
| 4053 | // Determines the location of the code pointer. |
| 4054 | enum class CodePtrLocation { |
| 4055 | // Recursive call, use local PC-relative call instruction. |
| 4056 | kCallSelf, |
| 4057 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4058 | // Use code pointer from the ArtMethod*. |
| 4059 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4060 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4061 | kCallArtMethod, |
| 4062 | }; |
| 4063 | |
| 4064 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4065 | MethodLoadKind method_load_kind; |
| 4066 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4067 | // The method load data holds |
| 4068 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4069 | // Note that there are multiple string init methods, each having its own offset. |
| 4070 | // - the method address for kDirectAddress |
| 4071 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4072 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4073 | }; |
| 4074 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4075 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 4076 | uint32_t number_of_arguments, |
| 4077 | Primitive::Type return_type, |
| 4078 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4079 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4080 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4081 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4082 | InvokeType invoke_type, |
| 4083 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4084 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4085 | : HInvoke(arena, |
| 4086 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4087 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4088 | // potentially one other if the clinit check is explicit, and potentially |
| 4089 | // one other if the method is a string factory. |
| 4090 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4091 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4092 | return_type, |
| 4093 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4094 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4095 | resolved_method, |
| 4096 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4097 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4098 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4099 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4100 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4101 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4102 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4103 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4104 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4105 | |
| 4106 | // Using the current method is the default and once we find a better |
| 4107 | // method load kind, we should not go back to using the current method. |
| 4108 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4109 | |
| 4110 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4111 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4112 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4113 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4114 | dispatch_info_ = dispatch_info; |
| 4115 | } |
| 4116 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4117 | void AddSpecialInput(HInstruction* input) { |
| 4118 | // We allow only one special input. |
| 4119 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4120 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4121 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4122 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4123 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4124 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4125 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4126 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4127 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4128 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4129 | DCHECK(!input_records.empty()); |
| 4130 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4131 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4132 | // Note: `last_input` may be null during arguments setup. |
| 4133 | if (last_input != nullptr) { |
| 4134 | // `last_input` is the last input of a static invoke marked as having |
| 4135 | // an explicit clinit check. It must either be: |
| 4136 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4137 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4138 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4139 | } |
| 4140 | } |
| 4141 | return input_records; |
| 4142 | } |
| 4143 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4144 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4145 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4146 | // TODO: for intrinsics we can generate implicit null checks. |
| 4147 | return false; |
| 4148 | } |
| 4149 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4150 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4151 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4152 | } |
| 4153 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4154 | // Get the index of the special input, if any. |
| 4155 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4156 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4157 | // method pointer; otherwise there may be one platform-specific special input, |
| 4158 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4159 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4160 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4161 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4162 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4163 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4164 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4165 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4166 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4167 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4168 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4169 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 4170 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4171 | bool HasCurrentMethodInput() const { |
| 4172 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4173 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4174 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4175 | return true; |
| 4176 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4177 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4178 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4179 | return false; |
| 4180 | } |
| 4181 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4182 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4183 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4184 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4185 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | uint64_t GetMethodAddress() const { |
| 4189 | DCHECK(HasMethodAddress()); |
| 4190 | return dispatch_info_.method_load_data; |
| 4191 | } |
| 4192 | |
| 4193 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4194 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4195 | return dispatch_info_.method_load_data; |
| 4196 | } |
| 4197 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4198 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4199 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4200 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4201 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4202 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4203 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4204 | // Is this instruction a call to a static method? |
| 4205 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4206 | return GetInvokeType() == kStatic; |
| 4207 | } |
| 4208 | |
| 4209 | MethodReference GetTargetMethod() const { |
| 4210 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4211 | } |
| 4212 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4213 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4214 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4215 | // instruction; only relevant for static calls with explicit clinit check. |
| 4216 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4217 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4218 | size_t last_input_index = inputs_.size() - 1u; |
| 4219 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4220 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4221 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4222 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4223 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4224 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4225 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | // 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] | 4229 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4230 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4231 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | // Is this a call to a static method whose declaring class has an |
| 4235 | // implicit intialization check requirement? |
| 4236 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4237 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4238 | } |
| 4239 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4240 | // Does this method load kind need the current method as an input? |
| 4241 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4242 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4243 | } |
| 4244 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4245 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4246 | |
| 4247 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4248 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4249 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4250 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4251 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4252 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4253 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4254 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4255 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4256 | kFieldClinitCheckRequirement, |
| 4257 | kFieldClinitCheckRequirementSize>; |
| 4258 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4259 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4260 | MethodReference target_method_; |
| 4261 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4262 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4263 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4264 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4265 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4266 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4267 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4268 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4269 | public: |
| 4270 | HInvokeVirtual(ArenaAllocator* arena, |
| 4271 | uint32_t number_of_arguments, |
| 4272 | Primitive::Type return_type, |
| 4273 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4274 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4275 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4276 | uint32_t vtable_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4277 | : HInvoke(arena, |
| 4278 | number_of_arguments, |
| 4279 | 0u, |
| 4280 | return_type, |
| 4281 | dex_pc, |
| 4282 | dex_method_index, |
| 4283 | resolved_method, |
| 4284 | kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4285 | vtable_index_(vtable_index) {} |
| 4286 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4287 | bool CanBeNull() const OVERRIDE { |
| 4288 | switch (GetIntrinsic()) { |
| 4289 | case Intrinsics::kThreadCurrentThread: |
| 4290 | case Intrinsics::kStringBufferAppend: |
| 4291 | case Intrinsics::kStringBufferToString: |
| 4292 | case Intrinsics::kStringBuilderAppend: |
| 4293 | case Intrinsics::kStringBuilderToString: |
| 4294 | return false; |
| 4295 | default: |
| 4296 | return HInvoke::CanBeNull(); |
| 4297 | } |
| 4298 | } |
| 4299 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4300 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4301 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4302 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4303 | } |
| 4304 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4305 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4306 | |
| 4307 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4308 | |
| 4309 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4310 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4311 | const uint32_t vtable_index_; |
| 4312 | |
| 4313 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4314 | }; |
| 4315 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4316 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4317 | public: |
| 4318 | HInvokeInterface(ArenaAllocator* arena, |
| 4319 | uint32_t number_of_arguments, |
| 4320 | Primitive::Type return_type, |
| 4321 | uint32_t dex_pc, |
| 4322 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4323 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4324 | uint32_t imt_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4325 | : HInvoke(arena, |
| 4326 | number_of_arguments, |
| 4327 | 0u, |
| 4328 | return_type, |
| 4329 | dex_pc, |
| 4330 | dex_method_index, |
| 4331 | resolved_method, |
| 4332 | kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4333 | imt_index_(imt_index) {} |
| 4334 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4335 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4336 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4337 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4338 | } |
| 4339 | |
Nicolas Geoffray | fbdfa6d | 2017-02-03 10:43:13 +0000 | [diff] [blame] | 4340 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 4341 | // The assembly stub currently needs it. |
| 4342 | return true; |
| 4343 | } |
| 4344 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4345 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4346 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4347 | |
| 4348 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4349 | |
| 4350 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4351 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4352 | const uint32_t imt_index_; |
| 4353 | |
| 4354 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4355 | }; |
| 4356 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4357 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4358 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4359 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4360 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4361 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4362 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4363 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4364 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4365 | |
| 4366 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4367 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4368 | } |
| 4369 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4370 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4371 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4372 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4373 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4374 | } |
| 4375 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4376 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4377 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4378 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4379 | DECLARE_INSTRUCTION(Neg); |
| 4380 | |
| 4381 | private: |
| 4382 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4383 | }; |
| 4384 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4385 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4386 | public: |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4387 | HNewArray(HInstruction* cls, HInstruction* length, uint32_t dex_pc) |
| 4388 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc) { |
| 4389 | SetRawInputAt(0, cls); |
| 4390 | SetRawInputAt(1, length); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4391 | } |
| 4392 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4393 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4394 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4395 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4396 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4397 | bool CanThrow() const OVERRIDE { return true; } |
| 4398 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4399 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4400 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4401 | HLoadClass* GetLoadClass() const { |
| 4402 | DCHECK(InputAt(0)->IsLoadClass()); |
| 4403 | return InputAt(0)->AsLoadClass(); |
| 4404 | } |
| 4405 | |
| 4406 | HInstruction* GetLength() const { |
| 4407 | return InputAt(1); |
| 4408 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4409 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4410 | DECLARE_INSTRUCTION(NewArray); |
| 4411 | |
| 4412 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4413 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4414 | }; |
| 4415 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4416 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4417 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4418 | HAdd(Primitive::Type result_type, |
| 4419 | HInstruction* left, |
| 4420 | HInstruction* right, |
| 4421 | uint32_t dex_pc = kNoDexPc) |
| 4422 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4423 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4424 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4425 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4426 | 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] | 4427 | |
| 4428 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4429 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4430 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4431 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4432 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4433 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4434 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4435 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4436 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4437 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4438 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4439 | } |
| 4440 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4441 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4442 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4443 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4444 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4445 | DECLARE_INSTRUCTION(Add); |
| 4446 | |
| 4447 | private: |
| 4448 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4449 | }; |
| 4450 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4451 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4452 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4453 | HSub(Primitive::Type result_type, |
| 4454 | HInstruction* left, |
| 4455 | HInstruction* right, |
| 4456 | uint32_t dex_pc = kNoDexPc) |
| 4457 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4458 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4459 | 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] | 4460 | |
| 4461 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4462 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4463 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4464 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4465 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4466 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4467 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4468 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4469 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4470 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4471 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4472 | } |
| 4473 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4474 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4475 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4476 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4477 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4478 | DECLARE_INSTRUCTION(Sub); |
| 4479 | |
| 4480 | private: |
| 4481 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4482 | }; |
| 4483 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4484 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4485 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4486 | HMul(Primitive::Type result_type, |
| 4487 | HInstruction* left, |
| 4488 | HInstruction* right, |
| 4489 | uint32_t dex_pc = kNoDexPc) |
| 4490 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4491 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4492 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4493 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4494 | 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] | 4495 | |
| 4496 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4497 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4498 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4499 | } |
| 4500 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4501 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4502 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4503 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4504 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4505 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4506 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4507 | } |
| 4508 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4509 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4510 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4511 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4512 | |
| 4513 | DECLARE_INSTRUCTION(Mul); |
| 4514 | |
| 4515 | private: |
| 4516 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4517 | }; |
| 4518 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4519 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4520 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4521 | HDiv(Primitive::Type result_type, |
| 4522 | HInstruction* left, |
| 4523 | HInstruction* right, |
| 4524 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4525 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4526 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4527 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4528 | T ComputeIntegral(T x, T y) const { |
| 4529 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4530 | // Our graph structure ensures we never have 0 for `y` during |
| 4531 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4532 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4533 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4534 | return (y == -1) ? -x : x / y; |
| 4535 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4536 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4537 | template <typename T> |
| 4538 | T ComputeFP(T x, T y) const { |
| 4539 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4540 | return x / y; |
| 4541 | } |
| 4542 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4543 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4544 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4545 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4546 | } |
| 4547 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4548 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4549 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4550 | } |
| 4551 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4552 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4553 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4554 | } |
| 4555 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4556 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4557 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4558 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4559 | |
| 4560 | DECLARE_INSTRUCTION(Div); |
| 4561 | |
| 4562 | private: |
| 4563 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4564 | }; |
| 4565 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4566 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4567 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4568 | HRem(Primitive::Type result_type, |
| 4569 | HInstruction* left, |
| 4570 | HInstruction* right, |
| 4571 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4572 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4573 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4574 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4575 | T ComputeIntegral(T x, T y) const { |
| 4576 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4577 | // Our graph structure ensures we never have 0 for `y` during |
| 4578 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4579 | DCHECK_NE(y, 0); |
| 4580 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4581 | return (y == -1) ? 0 : x % y; |
| 4582 | } |
| 4583 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4584 | template <typename T> |
| 4585 | T ComputeFP(T x, T y) const { |
| 4586 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4587 | return std::fmod(x, y); |
| 4588 | } |
| 4589 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4590 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4591 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4592 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4593 | } |
| 4594 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4595 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4596 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4597 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4598 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4599 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4600 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4601 | } |
| 4602 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4603 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4604 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4605 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4606 | |
| 4607 | DECLARE_INSTRUCTION(Rem); |
| 4608 | |
| 4609 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4610 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4611 | }; |
| 4612 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4613 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4614 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4615 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4616 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4617 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4618 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4619 | SetRawInputAt(0, value); |
| 4620 | } |
| 4621 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4622 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4623 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4624 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4625 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4626 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4627 | return true; |
| 4628 | } |
| 4629 | |
| 4630 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4631 | bool CanThrow() const OVERRIDE { return true; } |
| 4632 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4633 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4634 | |
| 4635 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4636 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4637 | }; |
| 4638 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4639 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4640 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4641 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4642 | HInstruction* value, |
| 4643 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4644 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4645 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4646 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4647 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4648 | } |
| 4649 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4650 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4651 | 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] | 4652 | return value << (distance & max_shift_distance); |
| 4653 | } |
| 4654 | |
| 4655 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4656 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4657 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4658 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4659 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4660 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4661 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4662 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4663 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4664 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4665 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4666 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4667 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4668 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4669 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4670 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4671 | UNREACHABLE(); |
| 4672 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4673 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4674 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4675 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4676 | UNREACHABLE(); |
| 4677 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4678 | |
| 4679 | DECLARE_INSTRUCTION(Shl); |
| 4680 | |
| 4681 | private: |
| 4682 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4683 | }; |
| 4684 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4685 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4686 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4687 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4688 | HInstruction* value, |
| 4689 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4690 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4691 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4692 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4693 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4694 | } |
| 4695 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4696 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4697 | 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] | 4698 | return value >> (distance & max_shift_distance); |
| 4699 | } |
| 4700 | |
| 4701 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4702 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4703 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4704 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4705 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4706 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4707 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4708 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4709 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4710 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4711 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4712 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4713 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4714 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4715 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4716 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4717 | UNREACHABLE(); |
| 4718 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4719 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4720 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4721 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4722 | UNREACHABLE(); |
| 4723 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4724 | |
| 4725 | DECLARE_INSTRUCTION(Shr); |
| 4726 | |
| 4727 | private: |
| 4728 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4729 | }; |
| 4730 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4731 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4732 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4733 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4734 | HInstruction* value, |
| 4735 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4736 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4737 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4738 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4739 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4740 | } |
| 4741 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4742 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4743 | 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] | 4744 | typedef typename std::make_unsigned<T>::type V; |
| 4745 | V ux = static_cast<V>(value); |
| 4746 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4747 | } |
| 4748 | |
| 4749 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4750 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4751 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4752 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4753 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4754 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4755 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4756 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4757 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4758 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4759 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4760 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4761 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4762 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4763 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4764 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4765 | UNREACHABLE(); |
| 4766 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4767 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4768 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4769 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4770 | UNREACHABLE(); |
| 4771 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4772 | |
| 4773 | DECLARE_INSTRUCTION(UShr); |
| 4774 | |
| 4775 | private: |
| 4776 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4777 | }; |
| 4778 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4779 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4780 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4781 | HAnd(Primitive::Type result_type, |
| 4782 | HInstruction* left, |
| 4783 | HInstruction* right, |
| 4784 | uint32_t dex_pc = kNoDexPc) |
| 4785 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4786 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4787 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4788 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4789 | 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] | 4790 | |
| 4791 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4792 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4793 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4794 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4795 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4796 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4797 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4798 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4799 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4800 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4801 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4802 | UNREACHABLE(); |
| 4803 | } |
| 4804 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4805 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4806 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4807 | UNREACHABLE(); |
| 4808 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4809 | |
| 4810 | DECLARE_INSTRUCTION(And); |
| 4811 | |
| 4812 | private: |
| 4813 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4814 | }; |
| 4815 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4816 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4817 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4818 | HOr(Primitive::Type result_type, |
| 4819 | HInstruction* left, |
| 4820 | HInstruction* right, |
| 4821 | uint32_t dex_pc = kNoDexPc) |
| 4822 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4823 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4824 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4825 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4826 | 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] | 4827 | |
| 4828 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4829 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4830 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4831 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4832 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4833 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4834 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4835 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4836 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4837 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4838 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4839 | UNREACHABLE(); |
| 4840 | } |
| 4841 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4842 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4843 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4844 | UNREACHABLE(); |
| 4845 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4846 | |
| 4847 | DECLARE_INSTRUCTION(Or); |
| 4848 | |
| 4849 | private: |
| 4850 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4851 | }; |
| 4852 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4853 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4854 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4855 | HXor(Primitive::Type result_type, |
| 4856 | HInstruction* left, |
| 4857 | HInstruction* right, |
| 4858 | uint32_t dex_pc = kNoDexPc) |
| 4859 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4860 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4861 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4862 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4863 | 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] | 4864 | |
| 4865 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4866 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4867 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4868 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4869 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4870 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4871 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4872 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4873 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4874 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4875 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4876 | UNREACHABLE(); |
| 4877 | } |
| 4878 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4879 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4880 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4881 | UNREACHABLE(); |
| 4882 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4883 | |
| 4884 | DECLARE_INSTRUCTION(Xor); |
| 4885 | |
| 4886 | private: |
| 4887 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4888 | }; |
| 4889 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4890 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4891 | public: |
| 4892 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4893 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4894 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4895 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4896 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4897 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4898 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4899 | 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] | 4900 | typedef typename std::make_unsigned<T>::type V; |
| 4901 | V ux = static_cast<V>(value); |
| 4902 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4903 | return static_cast<T>(ux); |
| 4904 | } else { |
| 4905 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4906 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4907 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4908 | } |
| 4909 | } |
| 4910 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4911 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4912 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4913 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4914 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4915 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4916 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4917 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4918 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4919 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4920 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4921 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4922 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4923 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4924 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4925 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4926 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4927 | UNREACHABLE(); |
| 4928 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4929 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4930 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4931 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4932 | UNREACHABLE(); |
| 4933 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4934 | |
| 4935 | DECLARE_INSTRUCTION(Ror); |
| 4936 | |
| 4937 | private: |
| 4938 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4939 | }; |
| 4940 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4941 | // The value of a parameter in this method. Its location depends on |
| 4942 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4943 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4944 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4945 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4946 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4947 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4948 | Primitive::Type parameter_type, |
| 4949 | bool is_this = false) |
| 4950 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4951 | dex_file_(dex_file), |
| 4952 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4953 | index_(index) { |
| 4954 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4955 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4956 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4957 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4958 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4959 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4960 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4961 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4962 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4963 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4964 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4965 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4966 | DECLARE_INSTRUCTION(ParameterValue); |
| 4967 | |
| 4968 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4969 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4970 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4971 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4972 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4973 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4974 | "Too many packed fields."); |
| 4975 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4976 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4977 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4978 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4979 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4980 | const uint8_t index_; |
| 4981 | |
| 4982 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4983 | }; |
| 4984 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4985 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4986 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4987 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4988 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4989 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4990 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4991 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4992 | return true; |
| 4993 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4994 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4995 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4996 | |
| 4997 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4998 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4999 | } |
| 5000 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5001 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5002 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5003 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5004 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5005 | UNREACHABLE(); |
| 5006 | } |
| 5007 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5008 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5009 | UNREACHABLE(); |
| 5010 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5011 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5012 | DECLARE_INSTRUCTION(Not); |
| 5013 | |
| 5014 | private: |
| 5015 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 5016 | }; |
| 5017 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5018 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5019 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5020 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5021 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5022 | |
| 5023 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5024 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5025 | return true; |
| 5026 | } |
| 5027 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5028 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5029 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5030 | return !x; |
| 5031 | } |
| 5032 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5033 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5034 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5035 | } |
| 5036 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5037 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5038 | UNREACHABLE(); |
| 5039 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5040 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5041 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5042 | UNREACHABLE(); |
| 5043 | } |
| 5044 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5045 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5046 | UNREACHABLE(); |
| 5047 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5048 | |
| 5049 | DECLARE_INSTRUCTION(BooleanNot); |
| 5050 | |
| 5051 | private: |
| 5052 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 5053 | }; |
| 5054 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5055 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5056 | public: |
| 5057 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 5058 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5059 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5060 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5061 | // Invariant: We should never generate a conversion to a Boolean value. |
| 5062 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | HInstruction* GetInput() const { return InputAt(0); } |
| 5066 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 5067 | Primitive::Type GetResultType() const { return GetType(); } |
| 5068 | |
| 5069 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5070 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5071 | return true; |
| 5072 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5073 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5074 | // Try to statically evaluate the conversion and return a HConstant |
| 5075 | // containing the result. If the input cannot be converted, return nullptr. |
| 5076 | HConstant* TryStaticEvaluation() const; |
| 5077 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5078 | DECLARE_INSTRUCTION(TypeConversion); |
| 5079 | |
| 5080 | private: |
| 5081 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 5082 | }; |
| 5083 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5084 | static constexpr uint32_t kNoRegNumber = -1; |
| 5085 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5086 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5087 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5088 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 5089 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5090 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5091 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5092 | SetRawInputAt(0, value); |
| 5093 | } |
| 5094 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5095 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5096 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5097 | return true; |
| 5098 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5099 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5100 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5101 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5102 | bool CanThrow() const OVERRIDE { return true; } |
| 5103 | |
| 5104 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5105 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5106 | |
| 5107 | DECLARE_INSTRUCTION(NullCheck); |
| 5108 | |
| 5109 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5110 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 5111 | }; |
| 5112 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5113 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5114 | // 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] | 5115 | class FieldInfo : public ValueObject { |
| 5116 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5117 | FieldInfo(ArtField* field, |
| 5118 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5119 | Primitive::Type field_type, |
| 5120 | bool is_volatile, |
| 5121 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5122 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5123 | const DexFile& dex_file) |
| 5124 | : field_(field), |
| 5125 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5126 | field_type_(field_type), |
| 5127 | is_volatile_(is_volatile), |
| 5128 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5129 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5130 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5131 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5132 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5133 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5134 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5135 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5136 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5137 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5138 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5139 | |
| 5140 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5141 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5142 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5143 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5144 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5145 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5146 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5147 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5148 | }; |
| 5149 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5150 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5151 | public: |
| 5152 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5153 | ArtField* field, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5154 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5155 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5156 | bool is_volatile, |
| 5157 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5158 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5159 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5160 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5161 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5162 | field_info_(field, |
| 5163 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5164 | field_type, |
| 5165 | is_volatile, |
| 5166 | field_idx, |
| 5167 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5168 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5169 | SetRawInputAt(0, value); |
| 5170 | } |
| 5171 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5172 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5173 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5174 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5175 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5176 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5177 | } |
| 5178 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5179 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5180 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5184 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5185 | } |
| 5186 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5187 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5188 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5189 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5190 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5191 | |
| 5192 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5193 | |
| 5194 | private: |
| 5195 | const FieldInfo field_info_; |
| 5196 | |
| 5197 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5198 | }; |
| 5199 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5200 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5201 | public: |
| 5202 | HInstanceFieldSet(HInstruction* object, |
| 5203 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5204 | ArtField* field, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5205 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5206 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5207 | bool is_volatile, |
| 5208 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5209 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5210 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5211 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5212 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5213 | field_info_(field, |
| 5214 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5215 | field_type, |
| 5216 | is_volatile, |
| 5217 | field_idx, |
| 5218 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5219 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5220 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5221 | SetRawInputAt(0, object); |
| 5222 | SetRawInputAt(1, value); |
| 5223 | } |
| 5224 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5225 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5226 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5227 | } |
| 5228 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5229 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5230 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5231 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5232 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5233 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5234 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5235 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5236 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5237 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5238 | |
| 5239 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5240 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5241 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5242 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5243 | "Too many packed fields."); |
| 5244 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5245 | const FieldInfo field_info_; |
| 5246 | |
| 5247 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5248 | }; |
| 5249 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5250 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5251 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5252 | HArrayGet(HInstruction* array, |
| 5253 | HInstruction* index, |
| 5254 | Primitive::Type type, |
| 5255 | uint32_t dex_pc, |
| 5256 | bool is_string_char_at = false) |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5257 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5258 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5259 | SetRawInputAt(0, array); |
| 5260 | SetRawInputAt(1, index); |
| 5261 | } |
| 5262 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5263 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5264 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5265 | return true; |
| 5266 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5267 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5268 | // TODO: We can be smarter here. |
| 5269 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5270 | // which generates the implicit null check. There are cases when these can be removed |
| 5271 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5272 | // implicit check here (as long as the address falls in the first page). |
| 5273 | return false; |
| 5274 | } |
| 5275 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5276 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5277 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5278 | if (kIsDebugBuild && result) { |
| 5279 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5280 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5281 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5282 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5283 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5284 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5285 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5286 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5287 | } |
| 5288 | } |
| 5289 | return result; |
| 5290 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5291 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5292 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5293 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5294 | HInstruction* GetArray() const { return InputAt(0); } |
| 5295 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5296 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5297 | DECLARE_INSTRUCTION(ArrayGet); |
| 5298 | |
| 5299 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5300 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5301 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5302 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5303 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5304 | // a flag, so that code generators don't need to do the locking. |
| 5305 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5306 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5307 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5308 | "Too many packed fields."); |
| 5309 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5310 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5311 | }; |
| 5312 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5313 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5314 | public: |
| 5315 | HArraySet(HInstruction* array, |
| 5316 | HInstruction* index, |
| 5317 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5318 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5319 | uint32_t dex_pc) |
| 5320 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5321 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5322 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5323 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5324 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5325 | SetRawInputAt(0, array); |
| 5326 | SetRawInputAt(1, index); |
| 5327 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5328 | // Make a best guess now, may be refined during SSA building. |
| 5329 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5330 | } |
| 5331 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5332 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5333 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5334 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5335 | } |
| 5336 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5337 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5338 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5339 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5340 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5341 | // TODO: Same as for ArrayGet. |
| 5342 | return false; |
| 5343 | } |
| 5344 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5345 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5346 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5347 | } |
| 5348 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5349 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5350 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5351 | } |
| 5352 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5353 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5354 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5355 | } |
| 5356 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5357 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5358 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5359 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5360 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5361 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5362 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5363 | HInstruction* GetArray() const { return InputAt(0); } |
| 5364 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5365 | HInstruction* GetValue() const { return InputAt(2); } |
| 5366 | |
| 5367 | Primitive::Type GetComponentType() const { |
| 5368 | // The Dex format does not type floating point index operations. Since the |
| 5369 | // `expected_component_type_` is set during building and can therefore not |
| 5370 | // be correct, we also check what is the value type. If it is a floating |
| 5371 | // point type, we must use that type. |
| 5372 | Primitive::Type value_type = GetValue()->GetType(); |
| 5373 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5374 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5375 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5376 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5377 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5378 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5379 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5380 | } |
| 5381 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5382 | void ComputeSideEffects() { |
| 5383 | Primitive::Type type = GetComponentType(); |
| 5384 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5385 | SideEffectsForArchRuntimeCalls(type))); |
| 5386 | } |
| 5387 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5388 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5389 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5390 | } |
| 5391 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5392 | DECLARE_INSTRUCTION(ArraySet); |
| 5393 | |
| 5394 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5395 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5396 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5397 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5398 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5399 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5400 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5401 | // Cached information for the reference_type_info_ so that codegen |
| 5402 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5403 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5404 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5405 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5406 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5407 | using ExpectedComponentTypeField = |
| 5408 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5409 | |
| 5410 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5411 | }; |
| 5412 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5413 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5414 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5415 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5416 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5417 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5418 | // Note that arrays do not change length, so the instruction does not |
| 5419 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5420 | SetRawInputAt(0, array); |
| 5421 | } |
| 5422 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5423 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5424 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5425 | return true; |
| 5426 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5427 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5428 | return obj == InputAt(0); |
| 5429 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5430 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5431 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5432 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5433 | DECLARE_INSTRUCTION(ArrayLength); |
| 5434 | |
| 5435 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5436 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5437 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5438 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5439 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5440 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5441 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5442 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5443 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5444 | "Too many packed fields."); |
| 5445 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5446 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5447 | }; |
| 5448 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5449 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5450 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5451 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5452 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5453 | HBoundsCheck(HInstruction* index, |
| 5454 | HInstruction* length, |
| 5455 | uint32_t dex_pc, |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5456 | bool string_char_at = false) |
| 5457 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5458 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5459 | SetPackedFlag<kFlagIsStringCharAt>(string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5460 | SetRawInputAt(0, index); |
| 5461 | SetRawInputAt(1, length); |
| 5462 | } |
| 5463 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5464 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5465 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5466 | return true; |
| 5467 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5468 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5469 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5470 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5471 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5472 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5473 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5474 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5475 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5476 | |
| 5477 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5478 | |
| 5479 | private: |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5480 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5481 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5482 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5483 | }; |
| 5484 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5485 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5486 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5487 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5488 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5489 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5490 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5491 | return true; |
| 5492 | } |
| 5493 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5494 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5495 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5496 | |
| 5497 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5498 | |
| 5499 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5500 | // Only used for code generation, in order to share the same slow path between back edges |
| 5501 | // of a same loop. |
| 5502 | SlowPathCode* slow_path_; |
| 5503 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5504 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5505 | }; |
| 5506 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5507 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5508 | // It ensures that we can generate line number and local variables at this point. |
| 5509 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5510 | public: |
| 5511 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5512 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5513 | |
| 5514 | bool NeedsEnvironment() const OVERRIDE { |
| 5515 | return true; |
| 5516 | } |
| 5517 | |
| 5518 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5519 | |
| 5520 | private: |
| 5521 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5522 | }; |
| 5523 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5524 | /** |
| 5525 | * Instruction to load a Class object. |
| 5526 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5527 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5528 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5529 | // Determines how to load the Class. |
| 5530 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5531 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 5532 | kInvalid = -1, |
| 5533 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5534 | // Use the Class* from the method's own ArtMethod*. |
| 5535 | kReferrersClass, |
| 5536 | |
| 5537 | // Use boot image Class* address that will be known at link time. |
| 5538 | // Used for boot image classes referenced by boot image code in non-PIC mode. |
| 5539 | kBootImageLinkTimeAddress, |
| 5540 | |
| 5541 | // Use PC-relative boot image Class* address that will be known at link time. |
| 5542 | // Used for boot image classes referenced by boot image code in PIC mode. |
| 5543 | kBootImageLinkTimePcRelative, |
| 5544 | |
| 5545 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5546 | // Used for boot image classes referenced by apps in AOT- and JIT-compiled code. |
| 5547 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5548 | // GetIncludePatchInformation(). |
| 5549 | kBootImageAddress, |
| 5550 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5551 | // Load from an entry in the .bss section using a PC-relative load. |
| 5552 | // Used for classes outside boot image when .bss is accessible with a PC-relative load. |
| 5553 | kBssEntry, |
| 5554 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5555 | // Load from the root table associated with the JIT compiled method. |
| 5556 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5557 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5558 | // Load from resolved types array accessed through the class loaded from |
| 5559 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5560 | // all other types are unavailable. |
| 5561 | kDexCacheViaMethod, |
| 5562 | |
| 5563 | kLast = kDexCacheViaMethod |
| 5564 | }; |
| 5565 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5566 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5567 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5568 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5569 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5570 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5571 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5572 | bool needs_access_check) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5573 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5574 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5575 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5576 | dex_file_(dex_file), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5577 | klass_(klass), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5578 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5579 | // Referrers class should not need access check. We never inline unverified |
| 5580 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5581 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5582 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5583 | SetPackedField<LoadKindField>( |
| 5584 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kDexCacheViaMethod); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5585 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5586 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5587 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5588 | } |
| 5589 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5590 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5591 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5592 | LoadKind GetLoadKind() const { |
| 5593 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5594 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5595 | |
| 5596 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5597 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5598 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5599 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5600 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5601 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5602 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5603 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5604 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5605 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5606 | } |
| 5607 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5608 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5609 | // The entrypoint the code generator is going to call does not do |
| 5610 | // clinit of the class. |
| 5611 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5612 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5613 | } |
| 5614 | |
| 5615 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5616 | return NeedsAccessCheck() || |
| 5617 | MustGenerateClinitCheck() || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5618 | GetLoadKind() == LoadKind::kDexCacheViaMethod || |
| 5619 | GetLoadKind() == LoadKind::kBssEntry; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5620 | } |
| 5621 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5622 | bool CanThrow() const OVERRIDE { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5623 | return NeedsAccessCheck() || |
| 5624 | MustGenerateClinitCheck() || |
| 5625 | // If the class is in the boot image, the lookup in the runtime call cannot throw. |
| 5626 | // This keeps CanThrow() consistent between non-PIC (using kBootImageAddress) and |
| 5627 | // PIC and subsequently avoids a DCE behavior dependency on the PIC option. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5628 | ((GetLoadKind() == LoadKind::kDexCacheViaMethod || |
| 5629 | GetLoadKind() == LoadKind::kBssEntry) && |
| 5630 | !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5631 | } |
| 5632 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5633 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5634 | return loaded_class_rti_; |
| 5635 | } |
| 5636 | |
| 5637 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5638 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5639 | DCHECK(rti.IsExact()); |
| 5640 | loaded_class_rti_ = rti; |
| 5641 | } |
| 5642 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5643 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5644 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5645 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5646 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5647 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5648 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5649 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5650 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5651 | return SideEffects::CanTriggerGC(); |
| 5652 | } |
| 5653 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5654 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5655 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5656 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5657 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5658 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5659 | void MarkInBootImage() { |
| 5660 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 5661 | } |
| 5662 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5663 | void AddSpecialInput(HInstruction* special_input); |
| 5664 | |
| 5665 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5666 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5667 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5668 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 5669 | } |
| 5670 | |
| 5671 | Primitive::Type GetType() const OVERRIDE { |
| 5672 | return Primitive::kPrimNot; |
| 5673 | } |
| 5674 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5675 | Handle<mirror::Class> GetClass() const { |
| 5676 | return klass_; |
| 5677 | } |
| 5678 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5679 | DECLARE_INSTRUCTION(LoadClass); |
| 5680 | |
| 5681 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5682 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5683 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5684 | // Whether this instruction must generate the initialization check. |
| 5685 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5686 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5687 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 5688 | static constexpr size_t kFieldLoadKindSize = |
| 5689 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5690 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5691 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5692 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 5693 | |
| 5694 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5695 | return load_kind == LoadKind::kReferrersClass || |
| 5696 | load_kind == LoadKind::kBootImageLinkTimeAddress || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5697 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5698 | load_kind == LoadKind::kBssEntry || |
| 5699 | load_kind == LoadKind::kDexCacheViaMethod; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5700 | } |
| 5701 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5702 | void SetLoadKindInternal(LoadKind load_kind); |
| 5703 | |
| 5704 | // The special input is the HCurrentMethod for kDexCacheViaMethod or kReferrersClass. |
| 5705 | // 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] | 5706 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5707 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5708 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5709 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 5710 | // - The compiling method's dex file if the class is defined there too. |
| 5711 | // - The compiling method's dex file if the class is referenced there. |
| 5712 | // - The dex file where the class is defined. When the load kind can only be |
| 5713 | // kBssEntry or kDexCacheViaMethod, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5714 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5715 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5716 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5717 | Handle<mirror::Class> klass_; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5718 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5719 | ReferenceTypeInfo loaded_class_rti_; |
| 5720 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5721 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5722 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5723 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 5724 | |
| 5725 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5726 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5727 | // The special input is used for PC-relative loads on some architectures, |
| 5728 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5729 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5730 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5731 | GetLoadKind() == LoadKind::kBootImageAddress || |
| 5732 | GetLoadKind() == LoadKind::kBssEntry) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5733 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5734 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 5735 | special_input->AddUseAt(this, 0); |
| 5736 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5737 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5738 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5739 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5740 | // Determines how to load the String. |
| 5741 | enum class LoadKind { |
| 5742 | // Use boot image String* address that will be known at link time. |
| 5743 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5744 | kBootImageLinkTimeAddress, |
| 5745 | |
| 5746 | // Use PC-relative boot image String* address that will be known at link time. |
| 5747 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5748 | kBootImageLinkTimePcRelative, |
| 5749 | |
| 5750 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5751 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5752 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5753 | // GetIncludePatchInformation(). |
| 5754 | kBootImageAddress, |
| 5755 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5756 | // Load from an entry in the .bss section using a PC-relative load. |
| 5757 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 5758 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5759 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5760 | // Load from the root table associated with the JIT compiled method. |
| 5761 | kJitTableAddress, |
| 5762 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5763 | // Load from resolved strings array accessed through the class loaded from |
| 5764 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5765 | // all other types are unavailable. |
| 5766 | kDexCacheViaMethod, |
| 5767 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5768 | kLast = kDexCacheViaMethod, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5769 | }; |
| 5770 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5771 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5772 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5773 | const DexFile& dex_file, |
| 5774 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5775 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5776 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5777 | string_index_(string_index), |
| 5778 | dex_file_(dex_file) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5779 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5780 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5781 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5782 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5783 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5784 | LoadKind GetLoadKind() const { |
| 5785 | return GetPackedField<LoadKindField>(); |
| 5786 | } |
| 5787 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5788 | const DexFile& GetDexFile() const { |
| 5789 | return dex_file_; |
| 5790 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5791 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5792 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5793 | return string_index_; |
| 5794 | } |
| 5795 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5796 | Handle<mirror::String> GetString() const { |
| 5797 | return string_; |
| 5798 | } |
| 5799 | |
| 5800 | void SetString(Handle<mirror::String> str) { |
| 5801 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5802 | } |
| 5803 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5804 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5805 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5806 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5807 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5808 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5809 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5810 | // Will call the runtime if we need to load the string through |
| 5811 | // the dex cache and the string is not guaranteed to be there yet. |
| 5812 | bool NeedsEnvironment() const OVERRIDE { |
| 5813 | LoadKind load_kind = GetLoadKind(); |
| 5814 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5815 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5816 | load_kind == LoadKind::kBootImageAddress || |
| 5817 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5818 | return false; |
| 5819 | } |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 5820 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5821 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5822 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5823 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5824 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5825 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5826 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5827 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5828 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5829 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5830 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5831 | return SideEffects::CanTriggerGC(); |
| 5832 | } |
| 5833 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5834 | void AddSpecialInput(HInstruction* special_input); |
| 5835 | |
| 5836 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5837 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5838 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5839 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5840 | } |
| 5841 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5842 | Primitive::Type GetType() const OVERRIDE { |
| 5843 | return Primitive::kPrimNot; |
| 5844 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5845 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5846 | DECLARE_INSTRUCTION(LoadString); |
| 5847 | |
| 5848 | private: |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 5849 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5850 | static constexpr size_t kFieldLoadKindSize = |
| 5851 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5852 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5853 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5854 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5855 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5856 | void SetLoadKindInternal(LoadKind load_kind); |
| 5857 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5858 | // The special input is the HCurrentMethod for kDexCacheViaMethod. |
| 5859 | // 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] | 5860 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5861 | HUserRecord<HInstruction*> special_input_; |
| 5862 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5863 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5864 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5865 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5866 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5867 | |
| 5868 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5869 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5870 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5871 | |
| 5872 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5873 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5874 | // The special input is used for PC-relative loads on some architectures, |
| 5875 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5876 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5877 | GetLoadKind() == LoadKind::kBssEntry || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5878 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5879 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5880 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5881 | // so use the GetInputRecords() from the base class to set the input record. |
| 5882 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5883 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5884 | special_input->AddUseAt(this, 0); |
| 5885 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5886 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5887 | /** |
| 5888 | * Performs an initialization check on its Class object input. |
| 5889 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5890 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5891 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5892 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5893 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5894 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5895 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5896 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5897 | SetRawInputAt(0, constant); |
| 5898 | } |
| 5899 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5900 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5901 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5902 | return true; |
| 5903 | } |
| 5904 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5905 | bool NeedsEnvironment() const OVERRIDE { |
| 5906 | // May call runtime to initialize the class. |
| 5907 | return true; |
| 5908 | } |
| 5909 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5910 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5911 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5912 | HLoadClass* GetLoadClass() const { |
| 5913 | DCHECK(InputAt(0)->IsLoadClass()); |
| 5914 | return InputAt(0)->AsLoadClass(); |
| 5915 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5916 | |
| 5917 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5918 | |
| 5919 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5920 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5921 | }; |
| 5922 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5923 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5924 | public: |
| 5925 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5926 | ArtField* field, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5927 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5928 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5929 | bool is_volatile, |
| 5930 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5931 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5932 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5933 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5934 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5935 | field_info_(field, |
| 5936 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5937 | field_type, |
| 5938 | is_volatile, |
| 5939 | field_idx, |
| 5940 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5941 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5942 | SetRawInputAt(0, cls); |
| 5943 | } |
| 5944 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5945 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5946 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5947 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5948 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5949 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5950 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | size_t ComputeHashCode() const OVERRIDE { |
| 5954 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5955 | } |
| 5956 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5957 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5958 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5959 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5960 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5961 | |
| 5962 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5963 | |
| 5964 | private: |
| 5965 | const FieldInfo field_info_; |
| 5966 | |
| 5967 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5968 | }; |
| 5969 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5970 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5971 | public: |
| 5972 | HStaticFieldSet(HInstruction* cls, |
| 5973 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5974 | ArtField* field, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5975 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5976 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5977 | bool is_volatile, |
| 5978 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5979 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5980 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5981 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5982 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5983 | field_info_(field, |
| 5984 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5985 | field_type, |
| 5986 | is_volatile, |
| 5987 | field_idx, |
| 5988 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5989 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5990 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5991 | SetRawInputAt(0, cls); |
| 5992 | SetRawInputAt(1, value); |
| 5993 | } |
| 5994 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5995 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5996 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5997 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5998 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5999 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6000 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6001 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6002 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6003 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6004 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6005 | |
| 6006 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6007 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6008 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6009 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6010 | "Too many packed fields."); |
| 6011 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6012 | const FieldInfo field_info_; |
| 6013 | |
| 6014 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 6015 | }; |
| 6016 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6017 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6018 | public: |
| 6019 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 6020 | Primitive::Type field_type, |
| 6021 | uint32_t field_index, |
| 6022 | uint32_t dex_pc) |
| 6023 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6024 | field_index_(field_index) { |
| 6025 | SetRawInputAt(0, obj); |
| 6026 | } |
| 6027 | |
| 6028 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6029 | bool CanThrow() const OVERRIDE { return true; } |
| 6030 | |
| 6031 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6032 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6033 | |
| 6034 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6035 | |
| 6036 | private: |
| 6037 | const uint32_t field_index_; |
| 6038 | |
| 6039 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 6040 | }; |
| 6041 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6042 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6043 | public: |
| 6044 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6045 | HInstruction* value, |
| 6046 | Primitive::Type field_type, |
| 6047 | uint32_t field_index, |
| 6048 | uint32_t dex_pc) |
| 6049 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6050 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6051 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6052 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6053 | SetRawInputAt(0, obj); |
| 6054 | SetRawInputAt(1, value); |
| 6055 | } |
| 6056 | |
| 6057 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6058 | bool CanThrow() const OVERRIDE { return true; } |
| 6059 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6060 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6061 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6062 | |
| 6063 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6064 | |
| 6065 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6066 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6067 | static constexpr size_t kFieldFieldTypeSize = |
| 6068 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6069 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6070 | kFieldFieldType + kFieldFieldTypeSize; |
| 6071 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6072 | "Too many packed fields."); |
| 6073 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6074 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6075 | const uint32_t field_index_; |
| 6076 | |
| 6077 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 6078 | }; |
| 6079 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6080 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6081 | public: |
| 6082 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 6083 | uint32_t field_index, |
| 6084 | uint32_t dex_pc) |
| 6085 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6086 | field_index_(field_index) { |
| 6087 | } |
| 6088 | |
| 6089 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6090 | bool CanThrow() const OVERRIDE { return true; } |
| 6091 | |
| 6092 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6093 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6094 | |
| 6095 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6096 | |
| 6097 | private: |
| 6098 | const uint32_t field_index_; |
| 6099 | |
| 6100 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 6101 | }; |
| 6102 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6103 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6104 | public: |
| 6105 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 6106 | Primitive::Type field_type, |
| 6107 | uint32_t field_index, |
| 6108 | uint32_t dex_pc) |
| 6109 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6110 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6111 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6112 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6113 | SetRawInputAt(0, value); |
| 6114 | } |
| 6115 | |
| 6116 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6117 | bool CanThrow() const OVERRIDE { return true; } |
| 6118 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6119 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6120 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6121 | |
| 6122 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6123 | |
| 6124 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6125 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6126 | static constexpr size_t kFieldFieldTypeSize = |
| 6127 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6128 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6129 | kFieldFieldType + kFieldFieldTypeSize; |
| 6130 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6131 | "Too many packed fields."); |
| 6132 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6133 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6134 | const uint32_t field_index_; |
| 6135 | |
| 6136 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6137 | }; |
| 6138 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6139 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6140 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6141 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6142 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6143 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6144 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6145 | bool CanBeNull() const OVERRIDE { return false; } |
| 6146 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6147 | DECLARE_INSTRUCTION(LoadException); |
| 6148 | |
| 6149 | private: |
| 6150 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6151 | }; |
| 6152 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6153 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6154 | // 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] | 6155 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6156 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6157 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6158 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6159 | |
| 6160 | DECLARE_INSTRUCTION(ClearException); |
| 6161 | |
| 6162 | private: |
| 6163 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6164 | }; |
| 6165 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6166 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6167 | public: |
| 6168 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6169 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6170 | SetRawInputAt(0, exception); |
| 6171 | } |
| 6172 | |
| 6173 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6174 | |
| 6175 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6176 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6177 | bool CanThrow() const OVERRIDE { return true; } |
| 6178 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6179 | |
| 6180 | DECLARE_INSTRUCTION(Throw); |
| 6181 | |
| 6182 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6183 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6184 | }; |
| 6185 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6186 | /** |
| 6187 | * Implementation strategies for the code generator of a HInstanceOf |
| 6188 | * or `HCheckCast`. |
| 6189 | */ |
| 6190 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6191 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6192 | kExactCheck, // Can do a single class compare. |
| 6193 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6194 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6195 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6196 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6197 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6198 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6199 | }; |
| 6200 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6201 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6202 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6203 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6204 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6205 | HInstanceOf(HInstruction* object, |
| 6206 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6207 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6208 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6209 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6210 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6211 | dex_pc) { |
| 6212 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6213 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6214 | SetRawInputAt(0, object); |
| 6215 | SetRawInputAt(1, constant); |
| 6216 | } |
| 6217 | |
| 6218 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6219 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6220 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6221 | return true; |
| 6222 | } |
| 6223 | |
| 6224 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6225 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6226 | } |
| 6227 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6228 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6229 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6230 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6231 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6232 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6233 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6234 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6235 | // Mips currently does runtime calls for any other checks. |
| 6236 | return check_kind != TypeCheckKind::kExactCheck; |
| 6237 | } |
| 6238 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6239 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6240 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6241 | } |
| 6242 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6243 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6244 | |
| 6245 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6246 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6247 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6248 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6249 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6250 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6251 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6252 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6253 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6254 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6255 | }; |
| 6256 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6257 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6258 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6259 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6260 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6261 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6262 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6263 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6264 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6265 | SetRawInputAt(0, input); |
| 6266 | } |
| 6267 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6268 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6269 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6270 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6271 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6272 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6273 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6274 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6275 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6276 | } |
| 6277 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6278 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6279 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6280 | DECLARE_INSTRUCTION(BoundType); |
| 6281 | |
| 6282 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6283 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6284 | // is false then CanBeNull() cannot be true). |
| 6285 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6286 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6287 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6288 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6289 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6290 | // 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] | 6291 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6292 | // It is used to bound the type in cases like: |
| 6293 | // if (x instanceof ClassX) { |
| 6294 | // // uper_bound_ will be ClassX |
| 6295 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6296 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6297 | |
| 6298 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6299 | }; |
| 6300 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6301 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6302 | public: |
| 6303 | HCheckCast(HInstruction* object, |
| 6304 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6305 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6306 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6307 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6308 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6309 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6310 | SetRawInputAt(0, object); |
| 6311 | SetRawInputAt(1, constant); |
| 6312 | } |
| 6313 | |
| 6314 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6315 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6316 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6317 | return true; |
| 6318 | } |
| 6319 | |
| 6320 | bool NeedsEnvironment() const OVERRIDE { |
| 6321 | // Instruction may throw a CheckCastError. |
| 6322 | return true; |
| 6323 | } |
| 6324 | |
| 6325 | bool CanThrow() const OVERRIDE { return true; } |
| 6326 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6327 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6328 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6329 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6330 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6331 | |
| 6332 | DECLARE_INSTRUCTION(CheckCast); |
| 6333 | |
| 6334 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6335 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6336 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6337 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6338 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6339 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6340 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6341 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6342 | |
| 6343 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6344 | }; |
| 6345 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6346 | /** |
| 6347 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6348 | * @details We define the combined barrier types that are actually required |
| 6349 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6350 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6351 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6352 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6353 | * The current recipe is as follows: |
| 6354 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6355 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6356 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6357 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6358 | * class has final fields. |
| 6359 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6360 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6361 | */ |
| 6362 | enum MemBarrierKind { |
| 6363 | kAnyStore, |
| 6364 | kLoadAny, |
| 6365 | kStoreStore, |
| 6366 | kAnyAny, |
| 6367 | kNTStoreStore, |
| 6368 | kLastBarrierKind = kNTStoreStore |
| 6369 | }; |
| 6370 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6371 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6372 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6373 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6374 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6375 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6376 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6377 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6378 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6379 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6380 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6381 | |
| 6382 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6383 | |
| 6384 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6385 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6386 | static constexpr size_t kFieldBarrierKindSize = |
| 6387 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6388 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6389 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6390 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6391 | "Too many packed fields."); |
| 6392 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6393 | |
| 6394 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6395 | }; |
| 6396 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6397 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6398 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6399 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6400 | kEnter, |
| 6401 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6402 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6403 | }; |
| 6404 | |
| 6405 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6406 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6407 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6408 | dex_pc) { |
| 6409 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6410 | SetRawInputAt(0, object); |
| 6411 | } |
| 6412 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6413 | // Instruction may go into runtime, so we need an environment. |
| 6414 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6415 | |
| 6416 | bool CanThrow() const OVERRIDE { |
| 6417 | // Verifier guarantees that monitor-exit cannot throw. |
| 6418 | // This is important because it allows the HGraphBuilder to remove |
| 6419 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6420 | return IsEnter(); |
| 6421 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6422 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6423 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6424 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6425 | |
| 6426 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6427 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6428 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6429 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6430 | static constexpr size_t kFieldOperationKindSize = |
| 6431 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6432 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6433 | kFieldOperationKind + kFieldOperationKindSize; |
| 6434 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6435 | "Too many packed fields."); |
| 6436 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6437 | |
| 6438 | private: |
| 6439 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6440 | }; |
| 6441 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6442 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6443 | public: |
| 6444 | HSelect(HInstruction* condition, |
| 6445 | HInstruction* true_value, |
| 6446 | HInstruction* false_value, |
| 6447 | uint32_t dex_pc) |
| 6448 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6449 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6450 | |
| 6451 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6452 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6453 | // that architectures which implement HSelect as a conditional move also |
| 6454 | // will not need to invert the condition. |
| 6455 | SetRawInputAt(0, false_value); |
| 6456 | SetRawInputAt(1, true_value); |
| 6457 | SetRawInputAt(2, condition); |
| 6458 | } |
| 6459 | |
| 6460 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6461 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6462 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6463 | |
| 6464 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6465 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6466 | return true; |
| 6467 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6468 | |
| 6469 | bool CanBeNull() const OVERRIDE { |
| 6470 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6471 | } |
| 6472 | |
| 6473 | DECLARE_INSTRUCTION(Select); |
| 6474 | |
| 6475 | private: |
| 6476 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6477 | }; |
| 6478 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6479 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6480 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6481 | MoveOperands(Location source, |
| 6482 | Location destination, |
| 6483 | Primitive::Type type, |
| 6484 | HInstruction* instruction) |
| 6485 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6486 | |
| 6487 | Location GetSource() const { return source_; } |
| 6488 | Location GetDestination() const { return destination_; } |
| 6489 | |
| 6490 | void SetSource(Location value) { source_ = value; } |
| 6491 | void SetDestination(Location value) { destination_ = value; } |
| 6492 | |
| 6493 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6494 | // destination (but not the source). |
| 6495 | Location MarkPending() { |
| 6496 | DCHECK(!IsPending()); |
| 6497 | Location dest = destination_; |
| 6498 | destination_ = Location::NoLocation(); |
| 6499 | return dest; |
| 6500 | } |
| 6501 | |
| 6502 | void ClearPending(Location dest) { |
| 6503 | DCHECK(IsPending()); |
| 6504 | destination_ = dest; |
| 6505 | } |
| 6506 | |
| 6507 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6508 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6509 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6510 | } |
| 6511 | |
| 6512 | // True if this blocks a move from the given location. |
| 6513 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6514 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6515 | } |
| 6516 | |
| 6517 | // A move is redundant if it's been eliminated, if its source and |
| 6518 | // destination are the same, or if its destination is unneeded. |
| 6519 | bool IsRedundant() const { |
| 6520 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6521 | } |
| 6522 | |
| 6523 | // We clear both operands to indicate move that's been eliminated. |
| 6524 | void Eliminate() { |
| 6525 | source_ = destination_ = Location::NoLocation(); |
| 6526 | } |
| 6527 | |
| 6528 | bool IsEliminated() const { |
| 6529 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6530 | return source_.IsInvalid(); |
| 6531 | } |
| 6532 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6533 | Primitive::Type GetType() const { return type_; } |
| 6534 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6535 | bool Is64BitMove() const { |
| 6536 | return Primitive::Is64BitType(type_); |
| 6537 | } |
| 6538 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6539 | HInstruction* GetInstruction() const { return instruction_; } |
| 6540 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6541 | private: |
| 6542 | Location source_; |
| 6543 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6544 | // The type this move is for. |
| 6545 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6546 | // The instruction this move is assocatied with. Null when this move is |
| 6547 | // for moving an input in the expected locations of user (including a phi user). |
| 6548 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6549 | // in the same parallel move. |
| 6550 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6551 | }; |
| 6552 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6553 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6554 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6555 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6556 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6557 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6558 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6559 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6560 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6561 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6562 | moves_.reserve(kDefaultNumberOfMoves); |
| 6563 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6564 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6565 | void AddMove(Location source, |
| 6566 | Location destination, |
| 6567 | Primitive::Type type, |
| 6568 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6569 | DCHECK(source.IsValid()); |
| 6570 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6571 | if (kIsDebugBuild) { |
| 6572 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6573 | for (const MoveOperands& move : moves_) { |
| 6574 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6575 | // Special case the situation where the move is for the spill slot |
| 6576 | // of the instruction. |
| 6577 | if ((GetPrevious() == instruction) |
| 6578 | || ((GetPrevious() == nullptr) |
| 6579 | && instruction->IsPhi() |
| 6580 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6581 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6582 | << "Doing parallel moves for the same instruction."; |
| 6583 | } else { |
| 6584 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6585 | } |
| 6586 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6587 | } |
| 6588 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6589 | for (const MoveOperands& move : moves_) { |
| 6590 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6591 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6592 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6593 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6594 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6595 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6596 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6597 | } |
| 6598 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6599 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6600 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6601 | } |
| 6602 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6603 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6604 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6605 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6606 | |
| 6607 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6608 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6609 | |
| 6610 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6611 | }; |
| 6612 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6613 | } // namespace art |
| 6614 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6615 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6616 | #include "nodes_shared.h" |
| 6617 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6618 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6619 | #include "nodes_arm.h" |
| 6620 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6621 | #ifdef ART_ENABLE_CODEGEN_mips |
| 6622 | #include "nodes_mips.h" |
| 6623 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6624 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6625 | #include "nodes_x86.h" |
| 6626 | #endif |
| 6627 | |
| 6628 | namespace art { |
| 6629 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6630 | class HGraphVisitor : public ValueObject { |
| 6631 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6632 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6633 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6634 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6635 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6636 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6637 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6638 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6639 | void VisitInsertionOrder(); |
| 6640 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6641 | // Visit the graph following dominator tree reverse post-order. |
| 6642 | void VisitReversePostOrder(); |
| 6643 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6644 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6645 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6646 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6647 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6648 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6649 | |
| 6650 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6651 | |
| 6652 | #undef DECLARE_VISIT_INSTRUCTION |
| 6653 | |
| 6654 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6655 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6656 | |
| 6657 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6658 | }; |
| 6659 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6660 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6661 | public: |
| 6662 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6663 | virtual ~HGraphDelegateVisitor() {} |
| 6664 | |
| 6665 | // Visit functions that delegate to to super class. |
| 6666 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6667 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6668 | |
| 6669 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6670 | |
| 6671 | #undef DECLARE_VISIT_INSTRUCTION |
| 6672 | |
| 6673 | private: |
| 6674 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6675 | }; |
| 6676 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6677 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6678 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6679 | // block id. |
| 6680 | class HBlocksInLoopIterator : public ValueObject { |
| 6681 | public: |
| 6682 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6683 | : blocks_in_loop_(info.GetBlocks()), |
| 6684 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6685 | index_(0) { |
| 6686 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6687 | Advance(); |
| 6688 | } |
| 6689 | } |
| 6690 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6691 | bool Done() const { return index_ == blocks_.size(); } |
| 6692 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6693 | void Advance() { |
| 6694 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6695 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6696 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6697 | break; |
| 6698 | } |
| 6699 | } |
| 6700 | } |
| 6701 | |
| 6702 | private: |
| 6703 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6704 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6705 | size_t index_; |
| 6706 | |
| 6707 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6708 | }; |
| 6709 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6710 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6711 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6712 | // post order. |
| 6713 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6714 | public: |
| 6715 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6716 | : blocks_in_loop_(info.GetBlocks()), |
| 6717 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6718 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6719 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6720 | Advance(); |
| 6721 | } |
| 6722 | } |
| 6723 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6724 | bool Done() const { return index_ == blocks_.size(); } |
| 6725 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6726 | void Advance() { |
| 6727 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6728 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6729 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6730 | break; |
| 6731 | } |
| 6732 | } |
| 6733 | } |
| 6734 | |
| 6735 | private: |
| 6736 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6737 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6738 | size_t index_; |
| 6739 | |
| 6740 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6741 | }; |
| 6742 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6743 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6744 | if (constant->IsIntConstant()) { |
| 6745 | return constant->AsIntConstant()->GetValue(); |
| 6746 | } else if (constant->IsLongConstant()) { |
| 6747 | return constant->AsLongConstant()->GetValue(); |
| 6748 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6749 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6750 | return 0; |
| 6751 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6752 | } |
| 6753 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6754 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6755 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6756 | inline const H##type* HInstruction::As##type() const { \ |
| 6757 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6758 | } \ |
| 6759 | inline H##type* HInstruction::As##type() { \ |
| 6760 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6761 | } |
| 6762 | |
| 6763 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6764 | #undef INSTRUCTION_TYPE_CHECK |
| 6765 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6766 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6767 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6768 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6769 | size_t number_of_new_blocks, |
| 6770 | size_t after) { |
| 6771 | DCHECK_LT(after, blocks->size()); |
| 6772 | size_t old_size = blocks->size(); |
| 6773 | size_t new_size = old_size + number_of_new_blocks; |
| 6774 | blocks->resize(new_size); |
| 6775 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6776 | } |
| 6777 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6778 | /* |
| 6779 | * Hunt "under the hood" of array lengths (leading to array references), |
| 6780 | * null checks (also leading to array references), and new arrays |
| 6781 | * (leading to the actual length). This makes it more likely related |
| 6782 | * instructions become actually comparable. |
| 6783 | */ |
| 6784 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 6785 | while (instruction->IsArrayLength() || |
| 6786 | instruction->IsNullCheck() || |
| 6787 | instruction->IsNewArray()) { |
| 6788 | instruction = instruction->IsNewArray() |
| 6789 | ? instruction->AsNewArray()->GetLength() |
| 6790 | : instruction->InputAt(0); |
| 6791 | } |
| 6792 | return instruction; |
| 6793 | } |
| 6794 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6795 | } // namespace art |
| 6796 | |
| 6797 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |