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 | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 174 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 175 | |
| 176 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 177 | }; |
| 178 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 179 | class ReferenceTypeInfo : ValueObject { |
| 180 | public: |
| 181 | typedef Handle<mirror::Class> TypeHandle; |
| 182 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 183 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 184 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 185 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 186 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 187 | } |
| 188 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 189 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 190 | return ReferenceTypeInfo(type_handle, is_exact); |
| 191 | } |
| 192 | |
| 193 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 194 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 195 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 196 | return handle.GetReference() != nullptr; |
| 197 | } |
| 198 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 199 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 200 | return IsValidHandle(type_handle_); |
| 201 | } |
| 202 | |
| 203 | bool IsExact() const { return is_exact_; } |
| 204 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 205 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 206 | DCHECK(IsValid()); |
| 207 | return GetTypeHandle()->IsObjectClass(); |
| 208 | } |
| 209 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 210 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 211 | DCHECK(IsValid()); |
| 212 | return GetTypeHandle()->IsStringClass(); |
| 213 | } |
| 214 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 215 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 216 | DCHECK(IsValid()); |
| 217 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 218 | } |
| 219 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 220 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 221 | DCHECK(IsValid()); |
| 222 | return GetTypeHandle()->IsInterface(); |
| 223 | } |
| 224 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 225 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 226 | DCHECK(IsValid()); |
| 227 | return GetTypeHandle()->IsArrayClass(); |
| 228 | } |
| 229 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 230 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 231 | DCHECK(IsValid()); |
| 232 | return GetTypeHandle()->IsPrimitiveArray(); |
| 233 | } |
| 234 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 235 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 236 | DCHECK(IsValid()); |
| 237 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 238 | } |
| 239 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 240 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 241 | DCHECK(IsValid()); |
| 242 | if (!IsExact()) return false; |
| 243 | if (!IsArrayClass()) return false; |
| 244 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 245 | } |
| 246 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 247 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 248 | DCHECK(IsValid()); |
| 249 | if (!IsExact()) return false; |
| 250 | if (!IsArrayClass()) return false; |
| 251 | if (!rti.IsArrayClass()) return false; |
| 252 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 253 | rti.GetTypeHandle()->GetComponentType()); |
| 254 | } |
| 255 | |
| 256 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 257 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 258 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 259 | DCHECK(IsValid()); |
| 260 | DCHECK(rti.IsValid()); |
| 261 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 262 | } |
| 263 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 264 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 265 | DCHECK(IsValid()); |
| 266 | DCHECK(rti.IsValid()); |
| 267 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 268 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 269 | } |
| 270 | |
| 271 | // Returns true if the type information provide the same amount of details. |
| 272 | // Note that it does not mean that the instructions have the same actual type |
| 273 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 274 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 275 | if (!IsValid() && !rti.IsValid()) { |
| 276 | // Invalid types are equal. |
| 277 | return true; |
| 278 | } |
| 279 | if (!IsValid() || !rti.IsValid()) { |
| 280 | // One is valid, the other not. |
| 281 | return false; |
| 282 | } |
| 283 | return IsExact() == rti.IsExact() |
| 284 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 285 | } |
| 286 | |
| 287 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 288 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 289 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 290 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 291 | |
| 292 | // The class of the object. |
| 293 | TypeHandle type_handle_; |
| 294 | // Whether or not the type is exact or a superclass of the actual type. |
| 295 | // Whether or not we have any information about this type. |
| 296 | bool is_exact_; |
| 297 | }; |
| 298 | |
| 299 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 300 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 301 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 302 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 303 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 304 | HGraph(ArenaAllocator* arena, |
| 305 | const DexFile& dex_file, |
| 306 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 307 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 308 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 309 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 310 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 311 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 312 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 313 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 314 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 315 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 316 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 317 | entry_block_(nullptr), |
| 318 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 319 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 320 | number_of_vregs_(0), |
| 321 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 322 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 323 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 324 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 325 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 326 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 327 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 328 | dex_file_(dex_file), |
| 329 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 330 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 331 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 332 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 333 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 334 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 335 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 336 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 337 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 338 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 339 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 340 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 341 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 342 | osr_(osr), |
| 343 | cha_single_implementation_list_(arena->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 344 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 345 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 346 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 347 | // 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] | 348 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 349 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 350 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 351 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 352 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 353 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 354 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 355 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 356 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 357 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 358 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 359 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 360 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 361 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 362 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 363 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 364 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 365 | void ComputeDominanceInformation(); |
| 366 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 367 | void ClearLoopInformation(); |
| 368 | void FindBackEdges(ArenaBitVector* visited); |
| 369 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 370 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 371 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 372 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 373 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 374 | // 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] | 375 | // 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] | 376 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 377 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 378 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 379 | // order and loop information. |
| 380 | void ComputeTryBlockInformation(); |
| 381 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 382 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 383 | // Returns the instruction to replace the invoke expression or null if the |
| 384 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 385 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 386 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 387 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 388 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 389 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 390 | // should be the new back edge. |
| 391 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 392 | HBasicBlock* reference, |
| 393 | bool replace_if_back_edge); |
| 394 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 395 | // Need to add a couple of blocks to test if the loop body is entered and |
| 396 | // put deoptimization instructions, etc. |
| 397 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 398 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 399 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 400 | // other blocks and has no instructions or phis. |
| 401 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 402 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 403 | // Splits the edge between `block` and `successor` while preserving the |
| 404 | // indices in the predecessor/successor lists. If there are multiple edges |
| 405 | // between the blocks, the lowest indices are used. |
| 406 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 407 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 408 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 409 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 410 | void SimplifyLoop(HBasicBlock* header); |
| 411 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 412 | int32_t GetNextInstructionId() { |
| 413 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 414 | return current_instruction_id_++; |
| 415 | } |
| 416 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 417 | int32_t GetCurrentInstructionId() const { |
| 418 | return current_instruction_id_; |
| 419 | } |
| 420 | |
| 421 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 422 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 423 | current_instruction_id_ = id; |
| 424 | } |
| 425 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 426 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 427 | return maximum_number_of_out_vregs_; |
| 428 | } |
| 429 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 430 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 431 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 434 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 435 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 436 | } |
| 437 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 438 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 439 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 440 | } |
| 441 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 442 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 443 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 444 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 445 | } |
| 446 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 447 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 448 | number_of_vregs_ = number_of_vregs; |
| 449 | } |
| 450 | |
| 451 | uint16_t GetNumberOfVRegs() const { |
| 452 | return number_of_vregs_; |
| 453 | } |
| 454 | |
| 455 | void SetNumberOfInVRegs(uint16_t value) { |
| 456 | number_of_in_vregs_ = value; |
| 457 | } |
| 458 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 459 | uint16_t GetNumberOfInVRegs() const { |
| 460 | return number_of_in_vregs_; |
| 461 | } |
| 462 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 463 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 464 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 465 | return number_of_vregs_ - number_of_in_vregs_; |
| 466 | } |
| 467 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 468 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 469 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 470 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 471 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 472 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 473 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 474 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 475 | } |
| 476 | |
| 477 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 478 | return ReverseRange(GetReversePostOrder()); |
| 479 | } |
| 480 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 481 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 482 | return linear_order_; |
| 483 | } |
| 484 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 485 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 486 | return ReverseRange(GetLinearOrder()); |
| 487 | } |
| 488 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 489 | bool HasBoundsChecks() const { |
| 490 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 491 | } |
| 492 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 493 | void SetHasBoundsChecks(bool value) { |
| 494 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 495 | } |
| 496 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 497 | bool ShouldGenerateConstructorBarrier() const { |
| 498 | return should_generate_constructor_barrier_; |
| 499 | } |
| 500 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 501 | bool IsDebuggable() const { return debuggable_; } |
| 502 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 503 | // 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] | 504 | // already, it is created and inserted into the graph. This method is only for |
| 505 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 506 | 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] | 507 | |
| 508 | // TODO: This is problematic for the consistency of reference type propagation |
| 509 | // because it can be created anytime after the pass and thus it will be left |
| 510 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 511 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 512 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 513 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 514 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 515 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 516 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 517 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 518 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 519 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 520 | 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] | 521 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 522 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 523 | 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] | 524 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 525 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 526 | HCurrentMethod* GetCurrentMethod(); |
| 527 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 528 | const DexFile& GetDexFile() const { |
| 529 | return dex_file_; |
| 530 | } |
| 531 | |
| 532 | uint32_t GetMethodIdx() const { |
| 533 | return method_idx_; |
| 534 | } |
| 535 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 536 | InvokeType GetInvokeType() const { |
| 537 | return invoke_type_; |
| 538 | } |
| 539 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 540 | InstructionSet GetInstructionSet() const { |
| 541 | return instruction_set_; |
| 542 | } |
| 543 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 544 | bool IsCompilingOsr() const { return osr_; } |
| 545 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 546 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 547 | return cha_single_implementation_list_; |
| 548 | } |
| 549 | |
| 550 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 551 | cha_single_implementation_list_.insert(method); |
| 552 | } |
| 553 | |
| 554 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 555 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 556 | } |
| 557 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 558 | bool HasTryCatch() const { return has_try_catch_; } |
| 559 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 560 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 561 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 562 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 563 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 564 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 565 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 566 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 567 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 568 | // The instruction has been inserted into the graph, either as a constant, or |
| 569 | // before cursor. |
| 570 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 571 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 572 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 573 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 574 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 575 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 576 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 577 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 578 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 579 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 580 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 581 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 582 | template <class InstructionType, typename ValueType> |
| 583 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 584 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 585 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 586 | // Try to find an existing constant of the given value. |
| 587 | InstructionType* constant = nullptr; |
| 588 | auto cached_constant = cache->find(value); |
| 589 | if (cached_constant != cache->end()) { |
| 590 | constant = cached_constant->second; |
| 591 | } |
| 592 | |
| 593 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 594 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 595 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 596 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 597 | cache->Overwrite(value, constant); |
| 598 | InsertConstant(constant); |
| 599 | } |
| 600 | return constant; |
| 601 | } |
| 602 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 603 | void InsertConstant(HConstant* instruction); |
| 604 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 605 | // Cache a float constant into the graph. This method should only be |
| 606 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 607 | void CacheFloatConstant(HFloatConstant* constant); |
| 608 | |
| 609 | // See CacheFloatConstant comment. |
| 610 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 611 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 612 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 613 | |
| 614 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 615 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 616 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 617 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 618 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 619 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 620 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 621 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 622 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 623 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 624 | HBasicBlock* entry_block_; |
| 625 | HBasicBlock* exit_block_; |
| 626 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 627 | // 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] | 628 | uint16_t maximum_number_of_out_vregs_; |
| 629 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 630 | // The number of virtual registers in this method. Contains the parameters. |
| 631 | uint16_t number_of_vregs_; |
| 632 | |
| 633 | // The number of virtual registers used by parameters of this method. |
| 634 | uint16_t number_of_in_vregs_; |
| 635 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 636 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 637 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 638 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 639 | // Has bounds checks. We can totally skip BCE if it's false. |
| 640 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 641 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 642 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 643 | // try/catch-related passes if false. |
| 644 | bool has_try_catch_; |
| 645 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 646 | // Flag whether there are any irreducible loops in the graph. |
| 647 | bool has_irreducible_loops_; |
| 648 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 649 | // Indicates whether the graph should be compiled in a way that |
| 650 | // ensures full debuggability. If false, we can apply more |
| 651 | // aggressive optimizations that may limit the level of debugging. |
| 652 | const bool debuggable_; |
| 653 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 654 | // 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] | 655 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 656 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 657 | // The dex file from which the method is from. |
| 658 | const DexFile& dex_file_; |
| 659 | |
| 660 | // The method index in the dex file. |
| 661 | const uint32_t method_idx_; |
| 662 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 663 | // If inlined, this encodes how the callee is being invoked. |
| 664 | const InvokeType invoke_type_; |
| 665 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 666 | // Whether the graph has been transformed to SSA form. Only used |
| 667 | // in debug mode to ensure we are not using properties only valid |
| 668 | // for non-SSA form (like the number of temporaries). |
| 669 | bool in_ssa_form_; |
| 670 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 671 | const bool should_generate_constructor_barrier_; |
| 672 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 673 | // Number of CHA guards in the graph. Used to short-circuit the |
| 674 | // CHA guard optimization pass when there is no CHA guard left. |
| 675 | uint32_t number_of_cha_guards_; |
| 676 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 677 | const InstructionSet instruction_set_; |
| 678 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 679 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 680 | HNullConstant* cached_null_constant_; |
| 681 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 682 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 683 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 684 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 685 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 686 | HCurrentMethod* cached_current_method_; |
| 687 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 688 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 689 | // for example for methods whose declaring class could not be resolved |
| 690 | // (such as when the superclass could not be found). |
| 691 | ArtMethod* art_method_; |
| 692 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 693 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 694 | // collection pointer to passes which may create NullConstant. |
| 695 | ReferenceTypeInfo inexact_object_rti_; |
| 696 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 697 | // Whether we are compiling this graph for on stack replacement: this will |
| 698 | // make all loops seen as irreducible and emit special stack maps to mark |
| 699 | // compiled code entries which the interpreter can directly jump to. |
| 700 | const bool osr_; |
| 701 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 702 | // List of methods that are assumed to have single implementation. |
| 703 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 704 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 705 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 706 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 707 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 708 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 709 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 710 | }; |
| 711 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 712 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 713 | public: |
| 714 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 715 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 716 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 717 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 718 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 719 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 720 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 721 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 722 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 723 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 724 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 725 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 726 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 727 | |
| 728 | void Dump(std::ostream& os); |
| 729 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 730 | HBasicBlock* GetHeader() const { |
| 731 | return header_; |
| 732 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 733 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 734 | void SetHeader(HBasicBlock* block) { |
| 735 | header_ = block; |
| 736 | } |
| 737 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 738 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 739 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 740 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 741 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 742 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 743 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 746 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 747 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 748 | } |
| 749 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 750 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 751 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 752 | } |
| 753 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 754 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 755 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 758 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 759 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 760 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 761 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 762 | } |
| 763 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 764 | // Returns the lifetime position of the back edge that has the |
| 765 | // greatest lifetime position. |
| 766 | size_t GetLifetimeEnd() const; |
| 767 | |
| 768 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 769 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 770 | } |
| 771 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 772 | // Finds blocks that are part of this loop. |
| 773 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 774 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 775 | // Returns whether this loop information contains `block`. |
| 776 | // Note that this loop information *must* be populated before entering this function. |
| 777 | bool Contains(const HBasicBlock& block) const; |
| 778 | |
| 779 | // Returns whether this loop information is an inner loop of `other`. |
| 780 | // Note that `other` *must* be populated before entering this function. |
| 781 | bool IsIn(const HLoopInformation& other) const; |
| 782 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 783 | // Returns true if instruction is not defined within this loop. |
| 784 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 785 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 786 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 787 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 788 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 789 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 790 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 791 | void ClearAllBlocks() { |
| 792 | blocks_.ClearAllBits(); |
| 793 | } |
| 794 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 795 | bool HasBackEdgeNotDominatedByHeader() const; |
| 796 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 797 | bool IsPopulated() const { |
| 798 | return blocks_.GetHighestBitSet() != -1; |
| 799 | } |
| 800 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 801 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 802 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 803 | bool HasExitEdge() const; |
| 804 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 805 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 806 | // Internal recursive implementation of `Populate`. |
| 807 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 808 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 809 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 810 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 811 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 812 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 813 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 814 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 815 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 816 | |
| 817 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 818 | }; |
| 819 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 820 | // Stores try/catch information for basic blocks. |
| 821 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 822 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 823 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 824 | public: |
| 825 | // Try block information constructor. |
| 826 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 827 | : try_entry_(&try_entry), |
| 828 | catch_dex_file_(nullptr), |
| 829 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 830 | DCHECK(try_entry_ != nullptr); |
| 831 | } |
| 832 | |
| 833 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 834 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 835 | : try_entry_(nullptr), |
| 836 | catch_dex_file_(&dex_file), |
| 837 | catch_type_index_(catch_type_index) {} |
| 838 | |
| 839 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 840 | |
| 841 | const HTryBoundary& GetTryEntry() const { |
| 842 | DCHECK(IsTryBlock()); |
| 843 | return *try_entry_; |
| 844 | } |
| 845 | |
| 846 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 847 | |
| 848 | bool IsCatchAllTypeIndex() const { |
| 849 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 850 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 851 | } |
| 852 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 853 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 854 | DCHECK(IsCatchBlock()); |
| 855 | return catch_type_index_; |
| 856 | } |
| 857 | |
| 858 | const DexFile& GetCatchDexFile() const { |
| 859 | DCHECK(IsCatchBlock()); |
| 860 | return *catch_dex_file_; |
| 861 | } |
| 862 | |
| 863 | private: |
| 864 | // One of possibly several TryBoundary instructions entering the block's try. |
| 865 | // Only set for try blocks. |
| 866 | const HTryBoundary* try_entry_; |
| 867 | |
| 868 | // Exception type information. Only set for catch blocks. |
| 869 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 870 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 871 | }; |
| 872 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 873 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 874 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 875 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 876 | // A block in a method. Contains the list of instructions represented |
| 877 | // as a double linked list. Each block knows its predecessors and |
| 878 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 879 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 880 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 881 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 882 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 883 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 884 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 885 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 886 | loop_information_(nullptr), |
| 887 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 888 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 889 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 890 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 891 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 892 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 893 | try_catch_information_(nullptr) { |
| 894 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 895 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 896 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 897 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 898 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 899 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 900 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 903 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 904 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 905 | } |
| 906 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 907 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 908 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 909 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 910 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 911 | return ContainsElement(successors_, block, start_from); |
| 912 | } |
| 913 | |
| 914 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 915 | return dominated_blocks_; |
| 916 | } |
| 917 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 918 | bool IsEntryBlock() const { |
| 919 | return graph_->GetEntryBlock() == this; |
| 920 | } |
| 921 | |
| 922 | bool IsExitBlock() const { |
| 923 | return graph_->GetExitBlock() == this; |
| 924 | } |
| 925 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 926 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 927 | bool IsSingleTryBoundary() const; |
| 928 | |
| 929 | // Returns true if this block emits nothing but a jump. |
| 930 | bool IsSingleJump() const { |
| 931 | HLoopInformation* loop_info = GetLoopInformation(); |
| 932 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 933 | // Back edges generate a suspend check. |
| 934 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 935 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 936 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 937 | void AddBackEdge(HBasicBlock* back_edge) { |
| 938 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 939 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 940 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 941 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 942 | loop_information_->AddBackEdge(back_edge); |
| 943 | } |
| 944 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 945 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 946 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 947 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 948 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 949 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 950 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 951 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 952 | HBasicBlock* GetDominator() const { return dominator_; } |
| 953 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 954 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 955 | |
| 956 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 957 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 958 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 959 | |
| 960 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 961 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 962 | } |
| 963 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 964 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 965 | |
| 966 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 967 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 970 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 971 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 972 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 973 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 974 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 975 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 976 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 977 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 978 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 979 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 980 | successors_.push_back(block); |
| 981 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 982 | } |
| 983 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 984 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 985 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 986 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 987 | new_block->predecessors_.push_back(this); |
| 988 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 991 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 992 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 993 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 994 | new_block->successors_.push_back(this); |
| 995 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 996 | } |
| 997 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 998 | // Insert `this` between `predecessor` and `successor. This method |
| 999 | // preserves the indicies, and will update the first edge found between |
| 1000 | // `predecessor` and `successor`. |
| 1001 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1002 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1003 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1004 | successor->predecessors_[predecessor_index] = this; |
| 1005 | predecessor->successors_[successor_index] = this; |
| 1006 | successors_.push_back(successor); |
| 1007 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1008 | } |
| 1009 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1010 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1011 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1012 | } |
| 1013 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1014 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1015 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1018 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1019 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1023 | predecessors_.push_back(block); |
| 1024 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1025 | } |
| 1026 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1027 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1028 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1029 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1030 | } |
| 1031 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1032 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1033 | DCHECK_EQ(successors_.size(), 2u); |
| 1034 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1035 | } |
| 1036 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1037 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1038 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1041 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1042 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1043 | } |
| 1044 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1045 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1046 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1047 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1051 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1052 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1056 | // predecessors is at index `idx`. |
| 1057 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1058 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1059 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1060 | } |
| 1061 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1062 | // Create a new block between this block and its predecessors. The new block |
| 1063 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1064 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1065 | // loop and try/catch information are not updated. |
| 1066 | HBasicBlock* CreateImmediateDominator(); |
| 1067 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1068 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1069 | // created, latter block. Note that this method will add the block to the |
| 1070 | // graph, create a Goto at the end of the former block and will create an edge |
| 1071 | // 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] | 1072 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1073 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1074 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1075 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1076 | // created block. Note that this method just updates raw block information, |
| 1077 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1078 | // update the graph, reverse post order, loop information, nor make sure the |
| 1079 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1080 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1081 | |
| 1082 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1083 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1084 | |
| 1085 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1086 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1087 | // that this method does not update the graph, reverse post order, loop |
| 1088 | // information, nor make sure the blocks are consistent (for example ending |
| 1089 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1090 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1091 | |
| 1092 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1093 | // of `this` are moved to `other`. |
| 1094 | // Note that this method does not update the graph, reverse post order, loop |
| 1095 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1096 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1097 | void ReplaceWith(HBasicBlock* other); |
| 1098 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1099 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1100 | // order, links to predecessors, successors, dominators and deletes the block |
| 1101 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1102 | // predecessor of `other` and vice versa. |
| 1103 | void MergeWith(HBasicBlock* other); |
| 1104 | |
| 1105 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1106 | // removes it from all loops it is included in and eventually from the graph. |
| 1107 | // The block must not dominate any other block. Predecessors and successors |
| 1108 | // are safely updated. |
| 1109 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1110 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1111 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1112 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1113 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1114 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1115 | // Replace instruction `initial` with `replacement` within this block. |
| 1116 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1117 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1118 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1119 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1120 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1121 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1122 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1123 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1124 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1125 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1126 | |
| 1127 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1128 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1129 | } |
| 1130 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1131 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1132 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1133 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1134 | } |
| 1135 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1136 | bool IsFirstPredecessorBackEdge() const { |
| 1137 | DCHECK(IsLoopHeader()); |
| 1138 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1139 | } |
| 1140 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1141 | HLoopInformation* GetLoopInformation() const { |
| 1142 | return loop_information_; |
| 1143 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1144 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1145 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1146 | // 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] | 1147 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1148 | void SetInLoop(HLoopInformation* info) { |
| 1149 | if (IsLoopHeader()) { |
| 1150 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1151 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1152 | loop_information_ = info; |
| 1153 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1154 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1155 | // Note that a non loop header having a loop information means this loop information |
| 1156 | // has already been populated |
| 1157 | loop_information_ = info; |
| 1158 | } else { |
| 1159 | // Block is part of an inner loop. Do not update the loop information. |
| 1160 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1161 | // at this point, because this method is being called while populating `info`. |
| 1162 | } |
| 1163 | } |
| 1164 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1165 | // Raw update of the loop information. |
| 1166 | void SetLoopInformation(HLoopInformation* info) { |
| 1167 | loop_information_ = info; |
| 1168 | } |
| 1169 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1170 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1171 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1172 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1173 | |
| 1174 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1175 | try_catch_information_ = try_catch_information; |
| 1176 | } |
| 1177 | |
| 1178 | bool IsTryBlock() const { |
| 1179 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1180 | } |
| 1181 | |
| 1182 | bool IsCatchBlock() const { |
| 1183 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1184 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1185 | |
| 1186 | // Returns the try entry that this block's successors should have. They will |
| 1187 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1188 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1189 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1190 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1191 | bool HasThrowingInstructions() const; |
| 1192 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1193 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1194 | bool Dominates(HBasicBlock* block) const; |
| 1195 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1196 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1197 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1198 | |
| 1199 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1200 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1201 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1202 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1203 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1204 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1205 | bool HasSinglePhi() const; |
| 1206 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1207 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1208 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1209 | ArenaVector<HBasicBlock*> predecessors_; |
| 1210 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1211 | HInstructionList instructions_; |
| 1212 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1213 | HLoopInformation* loop_information_; |
| 1214 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1215 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1216 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1217 | // The dex program counter of the first instruction of this block. |
| 1218 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1219 | size_t lifetime_start_; |
| 1220 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1221 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1222 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1223 | friend class HGraph; |
| 1224 | friend class HInstruction; |
| 1225 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1226 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1227 | }; |
| 1228 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1229 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1230 | // from the innermost to the outermost. |
| 1231 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1232 | public: |
| 1233 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1234 | : current_(block.GetLoopInformation()) {} |
| 1235 | |
| 1236 | bool Done() const { return current_ == nullptr; } |
| 1237 | |
| 1238 | void Advance() { |
| 1239 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1240 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | HLoopInformation* Current() const { |
| 1244 | DCHECK(!Done()); |
| 1245 | return current_; |
| 1246 | } |
| 1247 | |
| 1248 | private: |
| 1249 | HLoopInformation* current_; |
| 1250 | |
| 1251 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1252 | }; |
| 1253 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1254 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1255 | M(Above, Condition) \ |
| 1256 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1257 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1258 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1259 | M(ArrayGet, Instruction) \ |
| 1260 | M(ArrayLength, Instruction) \ |
| 1261 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1262 | M(Below, Condition) \ |
| 1263 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1264 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1265 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1266 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1267 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1268 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1269 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1270 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1271 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1272 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1273 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1274 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1275 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1276 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1277 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1278 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1279 | M(Exit, Instruction) \ |
| 1280 | M(FloatConstant, Constant) \ |
| 1281 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1282 | M(GreaterThan, Condition) \ |
| 1283 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1284 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1285 | M(InstanceFieldGet, Instruction) \ |
| 1286 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1287 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1288 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1289 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1290 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1291 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1292 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1293 | M(LessThan, Condition) \ |
| 1294 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1295 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1296 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1297 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1298 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1299 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1300 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1301 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1302 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1303 | M(Neg, UnaryOperation) \ |
| 1304 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1305 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1306 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1307 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1308 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1309 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1310 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1311 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1312 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1313 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1314 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1315 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1316 | M(Return, Instruction) \ |
| 1317 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1318 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1319 | M(Shl, BinaryOperation) \ |
| 1320 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1321 | M(StaticFieldGet, Instruction) \ |
| 1322 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1323 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1324 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1325 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1326 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1327 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1328 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1329 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1330 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1331 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1332 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1333 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1334 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1335 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1336 | /* |
| 1337 | * Instructions, shared across several (not all) architectures. |
| 1338 | */ |
| 1339 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1340 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1341 | #else |
| 1342 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1343 | M(BitwiseNegatedRight, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1344 | M(MultiplyAccumulate, Instruction) \ |
| 1345 | M(IntermediateAddress, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1346 | #endif |
| 1347 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1348 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1349 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1350 | #else |
| 1351 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1352 | M(ArmDexCacheArraysBase, Instruction) |
| 1353 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1354 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1355 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1356 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1357 | #else |
| 1358 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1359 | M(Arm64DataProcWithShifterOp, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1360 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1361 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1362 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1363 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1364 | #else |
| 1365 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1366 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1367 | M(MipsDexCacheArraysBase, Instruction) \ |
| 1368 | M(MipsPackedSwitch, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1369 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1370 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1371 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1372 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1373 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1374 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1375 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1376 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1377 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1378 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1379 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1380 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1381 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1382 | |
| 1383 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1384 | |
| 1385 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1386 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1387 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1388 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1389 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1390 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1391 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1392 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1393 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1394 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1395 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1396 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1397 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1398 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1399 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1400 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1401 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1402 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1403 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1404 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1405 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1406 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1407 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1408 | #undef FORWARD_DECLARATION |
| 1409 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1410 | #define DECLARE_INSTRUCTION(type) \ |
| 1411 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1412 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1413 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1414 | return other->Is##type(); \ |
| 1415 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1416 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1417 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1418 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1419 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1420 | const H##type* As##type() const { return this; } \ |
| 1421 | H##type* As##type() { return this; } |
| 1422 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1423 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1424 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1425 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1426 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1427 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1428 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1429 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1430 | // Hook for the IntrusiveForwardList<>. |
| 1431 | // TODO: Hide this better. |
| 1432 | IntrusiveForwardListHook hook; |
| 1433 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1434 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1435 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1436 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1437 | |
| 1438 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1439 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1440 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1441 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1442 | |
| 1443 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1444 | }; |
| 1445 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1446 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1447 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1448 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1449 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1450 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1451 | // by the used instructions. |
| 1452 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1453 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1454 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1455 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1456 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1457 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1458 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1459 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1460 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1461 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1462 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1466 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1467 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1468 | |
| 1469 | private: |
| 1470 | // Instruction used by the user. |
| 1471 | HInstruction* instruction_; |
| 1472 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1473 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1474 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1475 | }; |
| 1476 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1477 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1478 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1479 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1480 | struct HInputExtractor { |
| 1481 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1482 | return record.GetInstruction(); |
| 1483 | } |
| 1484 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1485 | return record.GetInstruction(); |
| 1486 | } |
| 1487 | }; |
| 1488 | |
| 1489 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1490 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1491 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1492 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1493 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1494 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1495 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1496 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1497 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1498 | * modify the value of a reference field read [although it may modify the |
| 1499 | * reference fetch prior to reading the field, which is represented by its own |
| 1500 | * write/read dependence]). The analysis makes conservative points-to |
| 1501 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1502 | * the same, and any reference read depends on any reference read without |
| 1503 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1504 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1505 | * The internal representation uses 38-bit and is described in the table below. |
| 1506 | * The first line indicates the side effect, and for field/array accesses the |
| 1507 | * second line indicates the type of the access (in the order of the |
| 1508 | * Primitive::Type enum). |
| 1509 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1510 | * vertically). |
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 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1513 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1514 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1515 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1516 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1517 | * |
| 1518 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1519 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1520 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1521 | class SideEffects : public ValueObject { |
| 1522 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1523 | SideEffects() : flags_(0) {} |
| 1524 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1525 | static SideEffects None() { |
| 1526 | return SideEffects(0); |
| 1527 | } |
| 1528 | |
| 1529 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1530 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1531 | } |
| 1532 | |
| 1533 | static SideEffects AllChanges() { |
| 1534 | return SideEffects(kAllChangeBits); |
| 1535 | } |
| 1536 | |
| 1537 | static SideEffects AllDependencies() { |
| 1538 | return SideEffects(kAllDependOnBits); |
| 1539 | } |
| 1540 | |
| 1541 | static SideEffects AllExceptGCDependency() { |
| 1542 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1543 | } |
| 1544 | |
| 1545 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1546 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1547 | } |
| 1548 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1549 | static SideEffects AllWrites() { |
| 1550 | return SideEffects(kAllWrites); |
| 1551 | } |
| 1552 | |
| 1553 | static SideEffects AllReads() { |
| 1554 | return SideEffects(kAllReads); |
| 1555 | } |
| 1556 | |
| 1557 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1558 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1559 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1560 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1561 | } |
| 1562 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1563 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1564 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1565 | } |
| 1566 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1567 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1568 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1569 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1570 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1574 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1577 | static SideEffects CanTriggerGC() { |
| 1578 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1579 | } |
| 1580 | |
| 1581 | static SideEffects DependsOnGC() { |
| 1582 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1583 | } |
| 1584 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1585 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1586 | SideEffects Union(SideEffects other) const { |
| 1587 | return SideEffects(flags_ | other.flags_); |
| 1588 | } |
| 1589 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1590 | SideEffects Exclusion(SideEffects other) const { |
| 1591 | return SideEffects(flags_ & ~other.flags_); |
| 1592 | } |
| 1593 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1594 | void Add(SideEffects other) { |
| 1595 | flags_ |= other.flags_; |
| 1596 | } |
| 1597 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1598 | bool Includes(SideEffects other) const { |
| 1599 | return (other.flags_ & flags_) == other.flags_; |
| 1600 | } |
| 1601 | |
| 1602 | bool HasSideEffects() const { |
| 1603 | return (flags_ & kAllChangeBits); |
| 1604 | } |
| 1605 | |
| 1606 | bool HasDependencies() const { |
| 1607 | return (flags_ & kAllDependOnBits); |
| 1608 | } |
| 1609 | |
| 1610 | // Returns true if there are no side effects or dependencies. |
| 1611 | bool DoesNothing() const { |
| 1612 | return flags_ == 0; |
| 1613 | } |
| 1614 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1615 | // Returns true if something is written. |
| 1616 | bool DoesAnyWrite() const { |
| 1617 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1618 | } |
| 1619 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1620 | // Returns true if something is read. |
| 1621 | bool DoesAnyRead() const { |
| 1622 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1623 | } |
| 1624 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1625 | // Returns true if potentially everything is written and read |
| 1626 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1627 | bool DoesAllReadWrite() const { |
| 1628 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1629 | } |
| 1630 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1631 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1632 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1635 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1636 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1637 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1638 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1642 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1643 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1644 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1645 | for (int s = kLastBit; s >= 0; s--) { |
| 1646 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1647 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1648 | // This is a bit for the GC side effect. |
| 1649 | if (current_bit_is_set) { |
| 1650 | flags += "GC"; |
| 1651 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1652 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1653 | } else { |
| 1654 | // This is a bit for the array/field analysis. |
| 1655 | // The underscore character stands for the 'can trigger GC' bit. |
| 1656 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1657 | if (current_bit_is_set) { |
| 1658 | flags += kDebug[s]; |
| 1659 | } |
| 1660 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1661 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1662 | flags += "|"; |
| 1663 | } |
| 1664 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1665 | } |
| 1666 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1667 | } |
| 1668 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1669 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1670 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1671 | private: |
| 1672 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1673 | |
| 1674 | static constexpr int kFieldWriteOffset = 0; |
| 1675 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1676 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1677 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1678 | |
| 1679 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1680 | |
| 1681 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1682 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1683 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1684 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1685 | |
| 1686 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1687 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1688 | |
| 1689 | // Aliases. |
| 1690 | |
| 1691 | static_assert(kChangeBits == kDependOnBits, |
| 1692 | "the 'change' bits should match the 'depend on' bits."); |
| 1693 | |
| 1694 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1695 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1696 | static constexpr uint64_t kAllWrites = |
| 1697 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1698 | static constexpr uint64_t kAllReads = |
| 1699 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1700 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1701 | // Translates type to bit flag. |
| 1702 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1703 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1704 | const uint64_t one = 1; |
| 1705 | const int shift = type; // 0-based consecutive enum |
| 1706 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1707 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1708 | return one << (type + offset); |
| 1709 | } |
| 1710 | |
| 1711 | // Private constructor on direct flags value. |
| 1712 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1713 | |
| 1714 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1715 | }; |
| 1716 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1717 | // 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] | 1718 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1719 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1720 | HEnvironment(ArenaAllocator* arena, |
| 1721 | size_t number_of_vregs, |
| 1722 | const DexFile& dex_file, |
| 1723 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1724 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1725 | InvokeType invoke_type, |
| 1726 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1727 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1728 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1729 | parent_(nullptr), |
| 1730 | dex_file_(dex_file), |
| 1731 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1732 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1733 | invoke_type_(invoke_type), |
| 1734 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1735 | } |
| 1736 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1737 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1738 | : HEnvironment(arena, |
| 1739 | to_copy.Size(), |
| 1740 | to_copy.GetDexFile(), |
| 1741 | to_copy.GetMethodIdx(), |
| 1742 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1743 | to_copy.GetInvokeType(), |
| 1744 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1745 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1746 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1747 | if (parent_ != nullptr) { |
| 1748 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1749 | } else { |
| 1750 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1751 | parent_->CopyFrom(parent); |
| 1752 | if (parent->GetParent() != nullptr) { |
| 1753 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1754 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1755 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1758 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1759 | void CopyFrom(HEnvironment* environment); |
| 1760 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1761 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1762 | // input to the loop phi instead. This is for inserting instructions that |
| 1763 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1764 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1765 | |
| 1766 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1767 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1771 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1774 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1775 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1776 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1777 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1778 | HEnvironment* GetParent() const { return parent_; } |
| 1779 | |
| 1780 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1781 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1785 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | uint32_t GetDexPc() const { |
| 1789 | return dex_pc_; |
| 1790 | } |
| 1791 | |
| 1792 | uint32_t GetMethodIdx() const { |
| 1793 | return method_idx_; |
| 1794 | } |
| 1795 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1796 | InvokeType GetInvokeType() const { |
| 1797 | return invoke_type_; |
| 1798 | } |
| 1799 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1800 | const DexFile& GetDexFile() const { |
| 1801 | return dex_file_; |
| 1802 | } |
| 1803 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1804 | HInstruction* GetHolder() const { |
| 1805 | return holder_; |
| 1806 | } |
| 1807 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1808 | |
| 1809 | bool IsFromInlinedInvoke() const { |
| 1810 | return GetParent() != nullptr; |
| 1811 | } |
| 1812 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1813 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1814 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1815 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1816 | HEnvironment* parent_; |
| 1817 | const DexFile& dex_file_; |
| 1818 | const uint32_t method_idx_; |
| 1819 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1820 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1821 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1822 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1823 | HInstruction* const holder_; |
| 1824 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1825 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1826 | |
| 1827 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1828 | }; |
| 1829 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1830 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1831 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1832 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1833 | : previous_(nullptr), |
| 1834 | next_(nullptr), |
| 1835 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1836 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1837 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1838 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1839 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1840 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1841 | locations_(nullptr), |
| 1842 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1843 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1844 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1845 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1846 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1847 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1848 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1849 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1850 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1851 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1852 | enum InstructionKind { |
| 1853 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1854 | }; |
| 1855 | #undef DECLARE_KIND |
| 1856 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1857 | HInstruction* GetNext() const { return next_; } |
| 1858 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1859 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1860 | HInstruction* GetNextDisregardingMoves() const; |
| 1861 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1862 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1863 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1864 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1865 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1866 | bool IsInBlock() const { return block_ != nullptr; } |
| 1867 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1868 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1869 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1870 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1871 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1872 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1873 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1874 | |
| 1875 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1876 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1877 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1878 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1879 | } |
| 1880 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1881 | HInputsRef GetInputs() { |
| 1882 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1883 | } |
| 1884 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1885 | HConstInputsRef GetInputs() const { |
| 1886 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1890 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1891 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 1892 | bool HasInput(HInstruction* input) const { |
| 1893 | for (const HInstruction* i : GetInputs()) { |
| 1894 | if (i == input) { |
| 1895 | return true; |
| 1896 | } |
| 1897 | } |
| 1898 | return false; |
| 1899 | } |
| 1900 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1901 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1902 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1903 | } |
| 1904 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1905 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1906 | virtual const char* DebugName() const = 0; |
| 1907 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1908 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1909 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1910 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1911 | |
| 1912 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1913 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1914 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1915 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1916 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1917 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1918 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1919 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1920 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1921 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1922 | // Does not apply for all instructions, but having this at top level greatly |
| 1923 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1924 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1925 | virtual bool CanBeNull() const { |
| 1926 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1927 | return true; |
| 1928 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1929 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1930 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1931 | return false; |
| 1932 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1933 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1934 | virtual bool IsActualObject() const { |
| 1935 | return GetType() == Primitive::kPrimNot; |
| 1936 | } |
| 1937 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1938 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1939 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1940 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1941 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1942 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1943 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1944 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1945 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1946 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1947 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1948 | // Note: fixup_end remains valid across push_front(). |
| 1949 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1950 | HUseListNode<HInstruction*>* new_node = |
| 1951 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1952 | uses_.push_front(*new_node); |
| 1953 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1956 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1957 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1958 | // Note: env_fixup_end remains valid across push_front(). |
| 1959 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 1960 | HUseListNode<HEnvironment*>* new_node = |
| 1961 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 1962 | env_uses_.push_front(*new_node); |
| 1963 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1964 | } |
| 1965 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1966 | void RemoveAsUserOfInput(size_t input) { |
| 1967 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1968 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1969 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1970 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1971 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1972 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1973 | void RemoveAsUserOfAllInputs() { |
| 1974 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 1975 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1976 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1977 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 1978 | } |
| 1979 | } |
| 1980 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1981 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1982 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1983 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1984 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 1985 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 1986 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1987 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1988 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1989 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1990 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 1991 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1992 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 1993 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1994 | !CanThrow() && |
| 1995 | !IsSuspendCheck() && |
| 1996 | !IsControlFlow() && |
| 1997 | !IsNativeDebugInfo() && |
| 1998 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1999 | // If we added an explicit barrier then we should keep it. |
| 2000 | !IsMemoryBarrier(); |
| 2001 | } |
| 2002 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2003 | bool IsDeadAndRemovable() const { |
| 2004 | return IsRemovable() && !HasUses(); |
| 2005 | } |
| 2006 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2007 | // Does this instruction strictly dominate `other_instruction`? |
| 2008 | // Returns false if this instruction and `other_instruction` are the same. |
| 2009 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2010 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2011 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2012 | int GetId() const { return id_; } |
| 2013 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2014 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2015 | int GetSsaIndex() const { return ssa_index_; } |
| 2016 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2017 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2018 | |
| 2019 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2020 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2021 | // Set the `environment_` field. Raw because this method does not |
| 2022 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2023 | void SetRawEnvironment(HEnvironment* environment) { |
| 2024 | DCHECK(environment_ == nullptr); |
| 2025 | DCHECK_EQ(environment->GetHolder(), this); |
| 2026 | environment_ = environment; |
| 2027 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2028 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2029 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2030 | DCHECK(environment_ != nullptr); |
| 2031 | DCHECK_EQ(environment->GetHolder(), this); |
| 2032 | DCHECK(environment->GetParent() == nullptr); |
| 2033 | environment->parent_ = environment_; |
| 2034 | environment_ = environment; |
| 2035 | } |
| 2036 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2037 | void RemoveEnvironment(); |
| 2038 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2039 | // Set the environment of this instruction, copying it from `environment`. While |
| 2040 | // copying, the uses lists are being updated. |
| 2041 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2042 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2043 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2044 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2045 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2046 | if (environment->GetParent() != nullptr) { |
| 2047 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2048 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2049 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2050 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2051 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2052 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2053 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2054 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2055 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2056 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2057 | if (environment->GetParent() != nullptr) { |
| 2058 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2059 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2062 | // Returns the number of entries in the environment. Typically, that is the |
| 2063 | // number of dex registers in a method. It could be more in case of inlining. |
| 2064 | size_t EnvironmentSize() const; |
| 2065 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2066 | LocationSummary* GetLocations() const { return locations_; } |
| 2067 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2068 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2069 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2070 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2071 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2072 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2073 | // uses of this instruction by `other` are *not* updated. |
| 2074 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2075 | ReplaceWith(other); |
| 2076 | other->ReplaceInput(this, use_index); |
| 2077 | } |
| 2078 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2079 | // Move `this` instruction before `cursor`. |
| 2080 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2081 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2082 | // Move `this` before its first user and out of any loops. If there is no |
| 2083 | // out-of-loop user that dominates all other users, move the instruction |
| 2084 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2085 | // |
| 2086 | // This can be used only on non-throwing instructions with no side effects that |
| 2087 | // have at least one use but no environment uses. |
| 2088 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2089 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2090 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2091 | bool Is##type() const; \ |
| 2092 | const H##type* As##type() const; \ |
| 2093 | H##type* As##type(); |
| 2094 | |
| 2095 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2096 | #undef INSTRUCTION_TYPE_CHECK |
| 2097 | |
| 2098 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2099 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2100 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2101 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2102 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2103 | #undef INSTRUCTION_TYPE_CHECK |
| 2104 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2105 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2106 | // TODO: this method is used by LICM and GVN with possibly different |
| 2107 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2108 | virtual bool CanBeMoved() const { return false; } |
| 2109 | |
| 2110 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2111 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2112 | return false; |
| 2113 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2114 | |
| 2115 | // Returns whether any data encoded in the two instructions is equal. |
| 2116 | // This method does not look at the inputs. Both instructions must be |
| 2117 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2118 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2119 | return false; |
| 2120 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2121 | |
| 2122 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2123 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2124 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2125 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2126 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2127 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2128 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2129 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2130 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2131 | InstructionKind GetKind() const PURE; |
| 2132 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2133 | |
| 2134 | virtual size_t ComputeHashCode() const { |
| 2135 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2136 | for (const HInstruction* input : GetInputs()) { |
| 2137 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2138 | } |
| 2139 | return result; |
| 2140 | } |
| 2141 | |
| 2142 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2143 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2144 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2145 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2146 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2147 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2148 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2149 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2150 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2151 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2152 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2153 | |
| 2154 | // Returns whether the code generation of the instruction will require to have access |
| 2155 | // to the current method. Such instructions are: |
| 2156 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2157 | // 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] | 2158 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2159 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2160 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2161 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2164 | // Returns whether the code generation of the instruction will require to have access |
| 2165 | // to the dex cache of the current method's declaring class via the current method. |
| 2166 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2167 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2168 | // Does this instruction have any use in an environment before |
| 2169 | // control flow hits 'other'? |
| 2170 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2171 | |
| 2172 | // Remove all references to environment uses of this instruction. |
| 2173 | // The caller must ensure that this is safe to do. |
| 2174 | void RemoveEnvironmentUsers(); |
| 2175 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2176 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2177 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2178 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2179 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2180 | // If set, the machine code for this instruction is assumed to be generated by |
| 2181 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2182 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2183 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2184 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2185 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2186 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2187 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2188 | return GetInputRecords()[i]; |
| 2189 | } |
| 2190 | |
| 2191 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2192 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2193 | input_records[index] = input; |
| 2194 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2195 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2196 | uint32_t GetPackedFields() const { |
| 2197 | return packed_fields_; |
| 2198 | } |
| 2199 | |
| 2200 | template <size_t flag> |
| 2201 | bool GetPackedFlag() const { |
| 2202 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2203 | } |
| 2204 | |
| 2205 | template <size_t flag> |
| 2206 | void SetPackedFlag(bool value = true) { |
| 2207 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2208 | } |
| 2209 | |
| 2210 | template <typename BitFieldType> |
| 2211 | typename BitFieldType::value_type GetPackedField() const { |
| 2212 | return BitFieldType::Decode(packed_fields_); |
| 2213 | } |
| 2214 | |
| 2215 | template <typename BitFieldType> |
| 2216 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2217 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2218 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2219 | } |
| 2220 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2221 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2222 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2223 | auto before_use_node = uses_.before_begin(); |
| 2224 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2225 | HInstruction* user = use_node->GetUser(); |
| 2226 | size_t input_index = use_node->GetIndex(); |
| 2227 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2228 | before_use_node = use_node; |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2233 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2234 | if (next != uses_.end()) { |
| 2235 | HInstruction* next_user = next->GetUser(); |
| 2236 | size_t next_index = next->GetIndex(); |
| 2237 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2238 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2243 | auto before_env_use_node = env_uses_.before_begin(); |
| 2244 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2245 | HEnvironment* user = env_use_node->GetUser(); |
| 2246 | size_t input_index = env_use_node->GetIndex(); |
| 2247 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2248 | before_env_use_node = env_use_node; |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2253 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2254 | if (next != env_uses_.end()) { |
| 2255 | HEnvironment* next_user = next->GetUser(); |
| 2256 | size_t next_index = next->GetIndex(); |
| 2257 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2258 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2259 | } |
| 2260 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2261 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2262 | HInstruction* previous_; |
| 2263 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2264 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2265 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2266 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2267 | // An instruction gets an id when it is added to the graph. |
| 2268 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2269 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2270 | int id_; |
| 2271 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2272 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2273 | int ssa_index_; |
| 2274 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2275 | // Packed fields. |
| 2276 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2277 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2278 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2279 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2280 | |
| 2281 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2282 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2283 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2284 | // The environment associated with this instruction. Not null if the instruction |
| 2285 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2286 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2287 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2288 | // Set by the code generator. |
| 2289 | LocationSummary* locations_; |
| 2290 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2291 | // Set by the liveness analysis. |
| 2292 | LiveInterval* live_interval_; |
| 2293 | |
| 2294 | // Set by the liveness analysis, this is the position in a linear |
| 2295 | // order of blocks where this instruction's live interval start. |
| 2296 | size_t lifetime_position_; |
| 2297 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2298 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2299 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2300 | // The reference handle part of the reference type info. |
| 2301 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2302 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2303 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2304 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2305 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2306 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2307 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2308 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2309 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2310 | |
| 2311 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2312 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2313 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2314 | |
| 2315 | class HInstructionIterator : public ValueObject { |
| 2316 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2317 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2318 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2319 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2322 | bool Done() const { return instruction_ == nullptr; } |
| 2323 | HInstruction* Current() const { return instruction_; } |
| 2324 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2325 | instruction_ = next_; |
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 | |
| 2329 | private: |
| 2330 | HInstruction* instruction_; |
| 2331 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2332 | |
| 2333 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2334 | }; |
| 2335 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2336 | class HBackwardInstructionIterator : public ValueObject { |
| 2337 | public: |
| 2338 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2339 | : instruction_(instructions.last_instruction_) { |
| 2340 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2341 | } |
| 2342 | |
| 2343 | bool Done() const { return instruction_ == nullptr; } |
| 2344 | HInstruction* Current() const { return instruction_; } |
| 2345 | void Advance() { |
| 2346 | instruction_ = next_; |
| 2347 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2348 | } |
| 2349 | |
| 2350 | private: |
| 2351 | HInstruction* instruction_; |
| 2352 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2353 | |
| 2354 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2355 | }; |
| 2356 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2357 | class HVariableInputSizeInstruction : public HInstruction { |
| 2358 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2359 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2360 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 2361 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2362 | } |
| 2363 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2364 | void AddInput(HInstruction* input); |
| 2365 | void InsertInputAt(size_t index, HInstruction* input); |
| 2366 | void RemoveInputAt(size_t index); |
| 2367 | |
| 2368 | protected: |
| 2369 | HVariableInputSizeInstruction(SideEffects side_effects, |
| 2370 | uint32_t dex_pc, |
| 2371 | ArenaAllocator* arena, |
| 2372 | size_t number_of_inputs, |
| 2373 | ArenaAllocKind kind) |
| 2374 | : HInstruction(side_effects, dex_pc), |
| 2375 | inputs_(number_of_inputs, arena->Adapter(kind)) {} |
| 2376 | |
| 2377 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
| 2378 | |
| 2379 | private: |
| 2380 | DISALLOW_COPY_AND_ASSIGN(HVariableInputSizeInstruction); |
| 2381 | }; |
| 2382 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2383 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2384 | class HTemplateInstruction: public HInstruction { |
| 2385 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2386 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2387 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2388 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2389 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2390 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2391 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2392 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2393 | } |
| 2394 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2395 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2396 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2397 | |
| 2398 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2399 | }; |
| 2400 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2401 | // HTemplateInstruction specialization for N=0. |
| 2402 | template<> |
| 2403 | class HTemplateInstruction<0>: public HInstruction { |
| 2404 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2405 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2406 | : HInstruction(side_effects, dex_pc) {} |
| 2407 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2408 | virtual ~HTemplateInstruction() {} |
| 2409 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2410 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2411 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2412 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | private: |
| 2416 | friend class SsaBuilder; |
| 2417 | }; |
| 2418 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2419 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2420 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2421 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2422 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2423 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2424 | this->template SetPackedField<TypeField>(type); |
| 2425 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2426 | virtual ~HExpression() {} |
| 2427 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2428 | Primitive::Type GetType() const OVERRIDE { |
| 2429 | return TypeField::Decode(this->GetPackedFields()); |
| 2430 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2431 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2432 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2433 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2434 | static constexpr size_t kFieldTypeSize = |
| 2435 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2436 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2437 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2438 | "Too many packed fields."); |
| 2439 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2440 | }; |
| 2441 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2442 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2443 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2444 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2445 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2446 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2447 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2448 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2449 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2450 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2451 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2452 | |
| 2453 | private: |
| 2454 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2455 | }; |
| 2456 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2457 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2458 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2459 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2460 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2461 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2462 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2463 | SetRawInputAt(0, value); |
| 2464 | } |
| 2465 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2466 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2467 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2468 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2469 | |
| 2470 | private: |
| 2471 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2472 | }; |
| 2473 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2474 | class HPhi FINAL : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2475 | public: |
| 2476 | HPhi(ArenaAllocator* arena, |
| 2477 | uint32_t reg_number, |
| 2478 | size_t number_of_inputs, |
| 2479 | Primitive::Type type, |
| 2480 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2481 | : HVariableInputSizeInstruction( |
| 2482 | SideEffects::None(), |
| 2483 | dex_pc, |
| 2484 | arena, |
| 2485 | number_of_inputs, |
| 2486 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2487 | reg_number_(reg_number) { |
| 2488 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2489 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2490 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2491 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2492 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2493 | SetPackedFlag<kFlagIsLive>(true); |
| 2494 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2495 | } |
| 2496 | |
| 2497 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2498 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2499 | return Primitive::PrimitiveKind(type); |
| 2500 | } |
| 2501 | |
| 2502 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2503 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2504 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2505 | void SetType(Primitive::Type new_type) { |
| 2506 | // Make sure that only valid type changes occur. The following are allowed: |
| 2507 | // (1) int -> float/ref (primitive type propagation), |
| 2508 | // (2) long -> double (primitive type propagation). |
| 2509 | DCHECK(GetType() == new_type || |
| 2510 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2511 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2512 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2513 | SetPackedField<TypeField>(new_type); |
| 2514 | } |
| 2515 | |
| 2516 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2517 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2518 | |
| 2519 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2520 | |
| 2521 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2522 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2523 | bool IsDead() const { return !IsLive(); } |
| 2524 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2525 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2526 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2527 | return other != nullptr |
| 2528 | && other->IsPhi() |
| 2529 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2530 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2531 | } |
| 2532 | |
| 2533 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2534 | // An equivalent phi is a phi having the same dex register and type. |
| 2535 | // It assumes that phis with the same dex register are adjacent. |
| 2536 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2537 | HInstruction* next = GetNext(); |
| 2538 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2539 | if (next->GetType() == GetType()) { |
| 2540 | return next->AsPhi(); |
| 2541 | } |
| 2542 | next = next->GetNext(); |
| 2543 | } |
| 2544 | return nullptr; |
| 2545 | } |
| 2546 | |
| 2547 | DECLARE_INSTRUCTION(Phi); |
| 2548 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2549 | private: |
| 2550 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2551 | static constexpr size_t kFieldTypeSize = |
| 2552 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2553 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2554 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2555 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2556 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2557 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2558 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2559 | const uint32_t reg_number_; |
| 2560 | |
| 2561 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2562 | }; |
| 2563 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2564 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2565 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2566 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2567 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2568 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2569 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2570 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2571 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2572 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2573 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2574 | |
| 2575 | private: |
| 2576 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2577 | }; |
| 2578 | |
| 2579 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2580 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2581 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2582 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2583 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2584 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2585 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2586 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2587 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2588 | } |
| 2589 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2590 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2591 | |
| 2592 | private: |
| 2593 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2594 | }; |
| 2595 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2596 | class HConstant : public HExpression<0> { |
| 2597 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2598 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2599 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2600 | |
| 2601 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2602 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2603 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2604 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2605 | // Is this constant 0 in the arithmetic sense? |
| 2606 | virtual bool IsArithmeticZero() const { return false; } |
| 2607 | // Is this constant a 0-bit pattern? |
| 2608 | virtual bool IsZeroBitPattern() const { return false; } |
| 2609 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2610 | virtual bool IsOne() const { return false; } |
| 2611 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2612 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2613 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2614 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2615 | |
| 2616 | private: |
| 2617 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2618 | }; |
| 2619 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2620 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2621 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2622 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2623 | return true; |
| 2624 | } |
| 2625 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2626 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2627 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2628 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2629 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2630 | // The null constant representation is a 0-bit pattern. |
| 2631 | virtual bool IsZeroBitPattern() const { return true; } |
| 2632 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2633 | DECLARE_INSTRUCTION(NullConstant); |
| 2634 | |
| 2635 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2636 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2637 | |
| 2638 | friend class HGraph; |
| 2639 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2640 | }; |
| 2641 | |
| 2642 | // Constants of the type int. Those can be from Dex instructions, or |
| 2643 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2644 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2645 | public: |
| 2646 | int32_t GetValue() const { return value_; } |
| 2647 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2648 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2649 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2650 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2651 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2652 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2653 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2654 | return other->AsIntConstant()->value_ == value_; |
| 2655 | } |
| 2656 | |
| 2657 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2658 | |
| 2659 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2660 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2661 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2662 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2663 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2664 | // Integer constants are used to encode Boolean values as well, |
| 2665 | // where 1 means true and 0 means false. |
| 2666 | bool IsTrue() const { return GetValue() == 1; } |
| 2667 | bool IsFalse() const { return GetValue() == 0; } |
| 2668 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2669 | DECLARE_INSTRUCTION(IntConstant); |
| 2670 | |
| 2671 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2672 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2673 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2674 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2675 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2676 | |
| 2677 | const int32_t value_; |
| 2678 | |
| 2679 | friend class HGraph; |
| 2680 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2681 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2682 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2683 | }; |
| 2684 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2685 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2686 | public: |
| 2687 | int64_t GetValue() const { return value_; } |
| 2688 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2689 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2690 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2691 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2692 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2693 | return other->AsLongConstant()->value_ == value_; |
| 2694 | } |
| 2695 | |
| 2696 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2697 | |
| 2698 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2699 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2700 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2701 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2702 | |
| 2703 | DECLARE_INSTRUCTION(LongConstant); |
| 2704 | |
| 2705 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2706 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2707 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2708 | |
| 2709 | const int64_t value_; |
| 2710 | |
| 2711 | friend class HGraph; |
| 2712 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2713 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2714 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2715 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2716 | public: |
| 2717 | float GetValue() const { return value_; } |
| 2718 | |
| 2719 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2720 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2721 | } |
| 2722 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2723 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2724 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2725 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2726 | } |
| 2727 | |
| 2728 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2729 | |
| 2730 | bool IsMinusOne() const OVERRIDE { |
| 2731 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2732 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2733 | bool IsArithmeticZero() const OVERRIDE { |
| 2734 | return std::fpclassify(value_) == FP_ZERO; |
| 2735 | } |
| 2736 | bool IsArithmeticPositiveZero() const { |
| 2737 | return IsArithmeticZero() && !std::signbit(value_); |
| 2738 | } |
| 2739 | bool IsArithmeticNegativeZero() const { |
| 2740 | return IsArithmeticZero() && std::signbit(value_); |
| 2741 | } |
| 2742 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2743 | 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] | 2744 | } |
| 2745 | bool IsOne() const OVERRIDE { |
| 2746 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2747 | } |
| 2748 | bool IsNaN() const { |
| 2749 | return std::isnan(value_); |
| 2750 | } |
| 2751 | |
| 2752 | DECLARE_INSTRUCTION(FloatConstant); |
| 2753 | |
| 2754 | private: |
| 2755 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2756 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2757 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2758 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2759 | |
| 2760 | const float value_; |
| 2761 | |
| 2762 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2763 | friend class SsaBuilder; |
| 2764 | friend class HGraph; |
| 2765 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2766 | }; |
| 2767 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2768 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2769 | public: |
| 2770 | double GetValue() const { return value_; } |
| 2771 | |
| 2772 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2773 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2774 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2775 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2776 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2777 | } |
| 2778 | |
| 2779 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2780 | |
| 2781 | bool IsMinusOne() const OVERRIDE { |
| 2782 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2783 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2784 | bool IsArithmeticZero() const OVERRIDE { |
| 2785 | return std::fpclassify(value_) == FP_ZERO; |
| 2786 | } |
| 2787 | bool IsArithmeticPositiveZero() const { |
| 2788 | return IsArithmeticZero() && !std::signbit(value_); |
| 2789 | } |
| 2790 | bool IsArithmeticNegativeZero() const { |
| 2791 | return IsArithmeticZero() && std::signbit(value_); |
| 2792 | } |
| 2793 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2794 | 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] | 2795 | } |
| 2796 | bool IsOne() const OVERRIDE { |
| 2797 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2798 | } |
| 2799 | bool IsNaN() const { |
| 2800 | return std::isnan(value_); |
| 2801 | } |
| 2802 | |
| 2803 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2804 | |
| 2805 | private: |
| 2806 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2807 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2808 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2809 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2810 | |
| 2811 | const double value_; |
| 2812 | |
| 2813 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2814 | friend class SsaBuilder; |
| 2815 | friend class HGraph; |
| 2816 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2817 | }; |
| 2818 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2819 | // Conditional branch. A block ending with an HIf instruction must have |
| 2820 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2821 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2822 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2823 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2824 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2825 | SetRawInputAt(0, input); |
| 2826 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2827 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2828 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2829 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2830 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2831 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2835 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2838 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2839 | |
| 2840 | private: |
| 2841 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2842 | }; |
| 2843 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2844 | |
| 2845 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2846 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2847 | // non-exceptional control flow. |
| 2848 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2849 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2850 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2851 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2852 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2853 | kEntry, |
| 2854 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2855 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2856 | }; |
| 2857 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2858 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2859 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2860 | SetPackedField<BoundaryKindField>(kind); |
| 2861 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2862 | |
| 2863 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2864 | |
| 2865 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2866 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2867 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2868 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2869 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2870 | } |
| 2871 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2872 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2873 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2874 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2875 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2876 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | // If not present already, adds `handler` to its block's list of exception |
| 2880 | // handlers. |
| 2881 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2882 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2883 | GetBlock()->AddSuccessor(handler); |
| 2884 | } |
| 2885 | } |
| 2886 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2887 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2888 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2889 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2890 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2891 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2892 | DECLARE_INSTRUCTION(TryBoundary); |
| 2893 | |
| 2894 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2895 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2896 | static constexpr size_t kFieldBoundaryKindSize = |
| 2897 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2898 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2899 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2900 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2901 | "Too many packed fields."); |
| 2902 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2903 | |
| 2904 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2905 | }; |
| 2906 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2907 | // Deoptimize to interpreter, upon checking a condition. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2908 | class HDeoptimize FINAL : public HTemplateInstruction<1> { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2909 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2910 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2911 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2912 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2913 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2914 | SetRawInputAt(0, cond); |
| 2915 | } |
| 2916 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2917 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2918 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2919 | return true; |
| 2920 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2921 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2922 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2923 | |
| 2924 | DECLARE_INSTRUCTION(Deoptimize); |
| 2925 | |
| 2926 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2927 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2928 | }; |
| 2929 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2930 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 2931 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 2932 | // if it's true, starts to do deoptimization. |
| 2933 | // It has a 4-byte slot on stack. |
| 2934 | // TODO: allocate a register for this flag. |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2935 | class HShouldDeoptimizeFlag FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2936 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2937 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 2938 | // with regard to other passes. |
| 2939 | HShouldDeoptimizeFlag(ArenaAllocator* arena, uint32_t dex_pc) |
| 2940 | : HVariableInputSizeInstruction(SideEffects::None(), dex_pc, arena, 0, kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2943 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimInt; } |
| 2944 | |
| 2945 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 2946 | // further guard elimination/motion since a guard might have been used for justification |
| 2947 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 2948 | // to avoid other optimizations trying to move it. |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2949 | bool CanBeMoved() const OVERRIDE { return false; } |
| 2950 | |
| 2951 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 2952 | |
| 2953 | private: |
| 2954 | DISALLOW_COPY_AND_ASSIGN(HShouldDeoptimizeFlag); |
| 2955 | }; |
| 2956 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2957 | // Represents the ArtMethod that was passed as a first argument to |
| 2958 | // the method. It is used by instructions that depend on it, like |
| 2959 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2960 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2961 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2962 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2963 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2964 | |
| 2965 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2966 | |
| 2967 | private: |
| 2968 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2969 | }; |
| 2970 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2971 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2972 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2973 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2974 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2975 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2976 | kVTable, |
| 2977 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2978 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2979 | }; |
| 2980 | HClassTableGet(HInstruction* cls, |
| 2981 | Primitive::Type type, |
| 2982 | TableKind kind, |
| 2983 | size_t index, |
| 2984 | uint32_t dex_pc) |
| 2985 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2986 | index_(index) { |
| 2987 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2988 | SetRawInputAt(0, cls); |
| 2989 | } |
| 2990 | |
| 2991 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2992 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2993 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2994 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2995 | } |
| 2996 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2997 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2998 | size_t GetIndex() const { return index_; } |
| 2999 | |
| 3000 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3001 | |
| 3002 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3003 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 3004 | static constexpr size_t kFieldTableKindSize = |
| 3005 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3006 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3007 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3008 | "Too many packed fields."); |
| 3009 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3010 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3011 | // The index of the ArtMethod in the table. |
| 3012 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3013 | |
| 3014 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 3015 | }; |
| 3016 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3017 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3018 | // have one successor for each entry in the switch table, and the final successor |
| 3019 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3020 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3021 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3022 | HPackedSwitch(int32_t start_value, |
| 3023 | uint32_t num_entries, |
| 3024 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3025 | uint32_t dex_pc = kNoDexPc) |
| 3026 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 3027 | start_value_(start_value), |
| 3028 | num_entries_(num_entries) { |
| 3029 | SetRawInputAt(0, input); |
| 3030 | } |
| 3031 | |
| 3032 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3033 | |
| 3034 | int32_t GetStartValue() const { return start_value_; } |
| 3035 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3036 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3037 | |
| 3038 | HBasicBlock* GetDefaultBlock() const { |
| 3039 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3040 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3041 | } |
| 3042 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3043 | |
| 3044 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3045 | const int32_t start_value_; |
| 3046 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3047 | |
| 3048 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 3049 | }; |
| 3050 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3051 | class HUnaryOperation : public HExpression<1> { |
| 3052 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3053 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3054 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3055 | SetRawInputAt(0, input); |
| 3056 | } |
| 3057 | |
| 3058 | HInstruction* GetInput() const { return InputAt(0); } |
| 3059 | Primitive::Type GetResultType() const { return GetType(); } |
| 3060 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3061 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3062 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3063 | return true; |
| 3064 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3065 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3066 | // Try to statically evaluate `this` and return a HConstant |
| 3067 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3068 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3069 | HConstant* TryStaticEvaluation() const; |
| 3070 | |
| 3071 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3072 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3073 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3074 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3075 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3076 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3077 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3078 | |
| 3079 | private: |
| 3080 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 3081 | }; |
| 3082 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3083 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3084 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3085 | HBinaryOperation(Primitive::Type result_type, |
| 3086 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3087 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3088 | SideEffects side_effects = SideEffects::None(), |
| 3089 | uint32_t dex_pc = kNoDexPc) |
| 3090 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3091 | SetRawInputAt(0, left); |
| 3092 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3093 | } |
| 3094 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3095 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3096 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3097 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3098 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3099 | virtual bool IsCommutative() const { return false; } |
| 3100 | |
| 3101 | // Put constant on the right. |
| 3102 | // Returns whether order is changed. |
| 3103 | bool OrderInputsWithConstantOnTheRight() { |
| 3104 | HInstruction* left = InputAt(0); |
| 3105 | HInstruction* right = InputAt(1); |
| 3106 | if (left->IsConstant() && !right->IsConstant()) { |
| 3107 | ReplaceInput(right, 0); |
| 3108 | ReplaceInput(left, 1); |
| 3109 | return true; |
| 3110 | } |
| 3111 | return false; |
| 3112 | } |
| 3113 | |
| 3114 | // Order inputs by instruction id, but favor constant on the right side. |
| 3115 | // This helps GVN for commutative ops. |
| 3116 | void OrderInputs() { |
| 3117 | DCHECK(IsCommutative()); |
| 3118 | HInstruction* left = InputAt(0); |
| 3119 | HInstruction* right = InputAt(1); |
| 3120 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3121 | return; |
| 3122 | } |
| 3123 | if (OrderInputsWithConstantOnTheRight()) { |
| 3124 | return; |
| 3125 | } |
| 3126 | // Order according to instruction id. |
| 3127 | if (left->GetId() > right->GetId()) { |
| 3128 | ReplaceInput(right, 0); |
| 3129 | ReplaceInput(left, 1); |
| 3130 | } |
| 3131 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3132 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3133 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3134 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3135 | return true; |
| 3136 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3137 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3138 | // Try to statically evaluate `this` and return a HConstant |
| 3139 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3140 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3141 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3142 | |
| 3143 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3144 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3145 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3146 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3147 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3148 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3149 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3150 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3151 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3152 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3153 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3154 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3155 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3156 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3157 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3158 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3159 | // 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] | 3160 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3161 | HConstant* GetConstantRight() const; |
| 3162 | |
| 3163 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3164 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3165 | HInstruction* GetLeastConstantLeft() const; |
| 3166 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3167 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3168 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3169 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3170 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3171 | }; |
| 3172 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3173 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3174 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3175 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3176 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3177 | kGtBias, // return 1 for NaN comparisons |
| 3178 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3179 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3180 | }; |
| 3181 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3182 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3183 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3184 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3185 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3186 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3187 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3188 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3189 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3190 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3191 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3192 | // `instruction`, and disregard moves in between. |
| 3193 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3194 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3195 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3196 | |
| 3197 | virtual IfCondition GetCondition() const = 0; |
| 3198 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3199 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3200 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3201 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3202 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3203 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3204 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3205 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3206 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3207 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3208 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3209 | } |
| 3210 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3211 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3212 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3213 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3214 | if (if_cond == kCondNE) { |
| 3215 | return true; |
| 3216 | } else if (if_cond == kCondEQ) { |
| 3217 | return false; |
| 3218 | } |
| 3219 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3223 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3224 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3225 | if (if_cond == kCondEQ) { |
| 3226 | return true; |
| 3227 | } else if (if_cond == kCondNE) { |
| 3228 | return false; |
| 3229 | } |
| 3230 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3231 | } |
| 3232 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3233 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3234 | // Needed if we merge a HCompare into a HCondition. |
| 3235 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3236 | static constexpr size_t kFieldComparisonBiasSize = |
| 3237 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3238 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3239 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3240 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3241 | using ComparisonBiasField = |
| 3242 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3243 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3244 | template <typename T> |
| 3245 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3246 | |
| 3247 | template <typename T> |
| 3248 | int32_t CompareFP(T x, T y) const { |
| 3249 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3250 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3251 | // Handle the bias. |
| 3252 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3253 | } |
| 3254 | |
| 3255 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3256 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3257 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3258 | } |
| 3259 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3260 | private: |
| 3261 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3262 | }; |
| 3263 | |
| 3264 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3265 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3266 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3267 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3268 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3269 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3270 | bool IsCommutative() const OVERRIDE { return true; } |
| 3271 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3272 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3273 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3274 | return MakeConstantCondition(true, GetDexPc()); |
| 3275 | } |
| 3276 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3277 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3278 | } |
| 3279 | // In the following Evaluate methods, a HCompare instruction has |
| 3280 | // been merged into this HEqual instruction; evaluate it as |
| 3281 | // `Compare(x, y) == 0`. |
| 3282 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3283 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3284 | GetDexPc()); |
| 3285 | } |
| 3286 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3287 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3288 | } |
| 3289 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3290 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3291 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3292 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3293 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3294 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3295 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3296 | return kCondEQ; |
| 3297 | } |
| 3298 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3299 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3300 | return kCondNE; |
| 3301 | } |
| 3302 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3303 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3304 | 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] | 3305 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3306 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3307 | }; |
| 3308 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3309 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3310 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3311 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3312 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3313 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3314 | bool IsCommutative() const OVERRIDE { return true; } |
| 3315 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3316 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3317 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3318 | return MakeConstantCondition(false, GetDexPc()); |
| 3319 | } |
| 3320 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3321 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3322 | } |
| 3323 | // In the following Evaluate methods, a HCompare instruction has |
| 3324 | // been merged into this HNotEqual instruction; evaluate it as |
| 3325 | // `Compare(x, y) != 0`. |
| 3326 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3327 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3328 | } |
| 3329 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3330 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3331 | } |
| 3332 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3333 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3334 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3335 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3336 | DECLARE_INSTRUCTION(NotEqual); |
| 3337 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3338 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3339 | return kCondNE; |
| 3340 | } |
| 3341 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3342 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3343 | return kCondEQ; |
| 3344 | } |
| 3345 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3346 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3347 | 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] | 3348 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3349 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3350 | }; |
| 3351 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3352 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3353 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3354 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3355 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3356 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3357 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3358 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3359 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3360 | // In the following Evaluate methods, a HCompare instruction has |
| 3361 | // been merged into this HLessThan instruction; evaluate it as |
| 3362 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3363 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3364 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3365 | } |
| 3366 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3367 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3368 | } |
| 3369 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3370 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3371 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3372 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3373 | DECLARE_INSTRUCTION(LessThan); |
| 3374 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3375 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3376 | return kCondLT; |
| 3377 | } |
| 3378 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3379 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3380 | return kCondGE; |
| 3381 | } |
| 3382 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3383 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3384 | 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] | 3385 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3386 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3387 | }; |
| 3388 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3389 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3390 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3391 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3392 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3393 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3394 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3395 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3396 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3397 | // In the following Evaluate methods, a HCompare instruction has |
| 3398 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3399 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3400 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3401 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3402 | } |
| 3403 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3404 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3405 | } |
| 3406 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3407 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3408 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3409 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3410 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3411 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3412 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3413 | return kCondLE; |
| 3414 | } |
| 3415 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3416 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3417 | return kCondGT; |
| 3418 | } |
| 3419 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3420 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3421 | 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] | 3422 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3423 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3424 | }; |
| 3425 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3426 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3427 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3428 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3429 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3430 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3431 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3432 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3433 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3434 | // In the following Evaluate methods, a HCompare instruction has |
| 3435 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3436 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3437 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3438 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3439 | } |
| 3440 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3441 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3442 | } |
| 3443 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3444 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3445 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3446 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3447 | DECLARE_INSTRUCTION(GreaterThan); |
| 3448 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3449 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3450 | return kCondGT; |
| 3451 | } |
| 3452 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3453 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3454 | return kCondLE; |
| 3455 | } |
| 3456 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3457 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3458 | 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] | 3459 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3460 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3461 | }; |
| 3462 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3463 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3464 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3465 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3466 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3467 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3468 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3469 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3470 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3471 | // In the following Evaluate methods, a HCompare instruction has |
| 3472 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3473 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3474 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3475 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3476 | } |
| 3477 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3478 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3479 | } |
| 3480 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3481 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3482 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3483 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3484 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3485 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3486 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3487 | return kCondGE; |
| 3488 | } |
| 3489 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3490 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3491 | return kCondLT; |
| 3492 | } |
| 3493 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3494 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3495 | 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] | 3496 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3497 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3498 | }; |
| 3499 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3500 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3501 | public: |
| 3502 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3503 | : HCondition(first, second, dex_pc) {} |
| 3504 | |
| 3505 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3506 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3507 | } |
| 3508 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3509 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3510 | } |
| 3511 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3512 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3513 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3514 | UNREACHABLE(); |
| 3515 | } |
| 3516 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3517 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3518 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3519 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | DECLARE_INSTRUCTION(Below); |
| 3523 | |
| 3524 | IfCondition GetCondition() const OVERRIDE { |
| 3525 | return kCondB; |
| 3526 | } |
| 3527 | |
| 3528 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3529 | return kCondAE; |
| 3530 | } |
| 3531 | |
| 3532 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3533 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3534 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3535 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3536 | |
| 3537 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3538 | }; |
| 3539 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3540 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3541 | public: |
| 3542 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3543 | : HCondition(first, second, dex_pc) {} |
| 3544 | |
| 3545 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3546 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3547 | } |
| 3548 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3549 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3550 | } |
| 3551 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3552 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3553 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3554 | UNREACHABLE(); |
| 3555 | } |
| 3556 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3557 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3558 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3559 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3560 | } |
| 3561 | |
| 3562 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3563 | |
| 3564 | IfCondition GetCondition() const OVERRIDE { |
| 3565 | return kCondBE; |
| 3566 | } |
| 3567 | |
| 3568 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3569 | return kCondA; |
| 3570 | } |
| 3571 | |
| 3572 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3573 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3574 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3575 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3576 | |
| 3577 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3578 | }; |
| 3579 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3580 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3581 | public: |
| 3582 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3583 | : HCondition(first, second, dex_pc) {} |
| 3584 | |
| 3585 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3586 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3587 | } |
| 3588 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3589 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3590 | } |
| 3591 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3592 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3593 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3594 | UNREACHABLE(); |
| 3595 | } |
| 3596 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3597 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3598 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3599 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | DECLARE_INSTRUCTION(Above); |
| 3603 | |
| 3604 | IfCondition GetCondition() const OVERRIDE { |
| 3605 | return kCondA; |
| 3606 | } |
| 3607 | |
| 3608 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3609 | return kCondBE; |
| 3610 | } |
| 3611 | |
| 3612 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3613 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3614 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3615 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3616 | |
| 3617 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3618 | }; |
| 3619 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3620 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3621 | public: |
| 3622 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3623 | : HCondition(first, second, dex_pc) {} |
| 3624 | |
| 3625 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3626 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3627 | } |
| 3628 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3629 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3630 | } |
| 3631 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3632 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3633 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3634 | UNREACHABLE(); |
| 3635 | } |
| 3636 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3637 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3638 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3639 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3643 | |
| 3644 | IfCondition GetCondition() const OVERRIDE { |
| 3645 | return kCondAE; |
| 3646 | } |
| 3647 | |
| 3648 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3649 | return kCondB; |
| 3650 | } |
| 3651 | |
| 3652 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3653 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3654 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3655 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3656 | |
| 3657 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3658 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3659 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3660 | // Instruction to check how two inputs compare to each other. |
| 3661 | // 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] | 3662 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3663 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3664 | // Note that `comparison_type` is the type of comparison performed |
| 3665 | // between the comparison's inputs, not the type of the instantiated |
| 3666 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3667 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3668 | HInstruction* first, |
| 3669 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3670 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3671 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3672 | : HBinaryOperation(Primitive::kPrimInt, |
| 3673 | first, |
| 3674 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3675 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3676 | dex_pc) { |
| 3677 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3678 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3679 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3680 | } |
| 3681 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3682 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3683 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3684 | |
| 3685 | template <typename T> |
| 3686 | int32_t ComputeFP(T x, T y) const { |
| 3687 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3688 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3689 | // Handle the bias. |
| 3690 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3691 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3692 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3693 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3694 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3695 | // reach this code path when processing a freshly built HIR |
| 3696 | // graph. However HCompare integer instructions can be synthesized |
| 3697 | // by the instruction simplifier to implement IntegerCompare and |
| 3698 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3699 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3700 | } |
| 3701 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3702 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3703 | } |
| 3704 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3705 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3706 | } |
| 3707 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3708 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3709 | } |
| 3710 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3711 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3712 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3713 | } |
| 3714 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3715 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3716 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3717 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3718 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3719 | bool IsGtBias() const { |
| 3720 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3721 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3722 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3723 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3724 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3725 | // Comparisons do not require a runtime call in any back end. |
| 3726 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3727 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3728 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3729 | DECLARE_INSTRUCTION(Compare); |
| 3730 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3731 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3732 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3733 | static constexpr size_t kFieldComparisonBiasSize = |
| 3734 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3735 | static constexpr size_t kNumberOfComparePackedBits = |
| 3736 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3737 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3738 | using ComparisonBiasField = |
| 3739 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3740 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3741 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3742 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3743 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3744 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3745 | } |
| 3746 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3747 | private: |
| 3748 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3749 | }; |
| 3750 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3751 | class HNewInstance FINAL : public HExpression<2> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3752 | public: |
| 3753 | HNewInstance(HInstruction* cls, |
| 3754 | HCurrentMethod* current_method, |
| 3755 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3756 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3757 | const DexFile& dex_file, |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3758 | bool needs_access_check, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3759 | bool finalizable, |
| 3760 | QuickEntrypointEnum entrypoint) |
| 3761 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3762 | type_index_(type_index), |
| 3763 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3764 | entrypoint_(entrypoint) { |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3765 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3766 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3767 | SetRawInputAt(0, cls); |
| 3768 | SetRawInputAt(1, current_method); |
| 3769 | } |
| 3770 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3771 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3772 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3773 | |
| 3774 | // Calls runtime so needs an environment. |
| 3775 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3776 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3777 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3778 | bool CanThrow() const OVERRIDE { return true; } |
| 3779 | |
| 3780 | // Needs to call into runtime to make sure it's instantiable/accessible. |
| 3781 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3782 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3783 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3784 | |
| 3785 | bool CanBeNull() const OVERRIDE { return false; } |
| 3786 | |
| 3787 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3788 | |
| 3789 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3790 | entrypoint_ = entrypoint; |
| 3791 | } |
| 3792 | |
| 3793 | bool IsStringAlloc() const; |
| 3794 | |
| 3795 | DECLARE_INSTRUCTION(NewInstance); |
| 3796 | |
| 3797 | private: |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3798 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfExpressionPackedBits; |
| 3799 | static constexpr size_t kFlagFinalizable = kFlagNeedsAccessCheck + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3800 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3801 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3802 | "Too many packed fields."); |
| 3803 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3804 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3805 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3806 | QuickEntrypointEnum entrypoint_; |
| 3807 | |
| 3808 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3809 | }; |
| 3810 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3811 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3812 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3813 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3814 | }; |
| 3815 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3816 | enum IntrinsicSideEffects { |
| 3817 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3818 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3819 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3820 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3821 | }; |
| 3822 | |
| 3823 | enum IntrinsicExceptions { |
| 3824 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3825 | kCanThrow // Intrinsic may throw exceptions. |
| 3826 | }; |
| 3827 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3828 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3829 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3830 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3831 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3832 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3833 | SetRawInputAt(index, argument); |
| 3834 | } |
| 3835 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3836 | // Return the number of arguments. This number can be lower than |
| 3837 | // the number of inputs returned by InputCount(), as some invoke |
| 3838 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3839 | // inputs at the end of their list of inputs. |
| 3840 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3841 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3842 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3843 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3844 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3845 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3846 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3847 | InvokeType GetInvokeType() const { |
| 3848 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3849 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3850 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3851 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3852 | return intrinsic_; |
| 3853 | } |
| 3854 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3855 | void SetIntrinsic(Intrinsics intrinsic, |
| 3856 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3857 | IntrinsicSideEffects side_effects, |
| 3858 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3859 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3860 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3861 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3862 | } |
| 3863 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 3864 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 3865 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3866 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3867 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 3868 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3869 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3870 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3871 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3872 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3873 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3874 | uint32_t* GetIntrinsicOptimizations() { |
| 3875 | return &intrinsic_optimizations_; |
| 3876 | } |
| 3877 | |
| 3878 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3879 | return &intrinsic_optimizations_; |
| 3880 | } |
| 3881 | |
| 3882 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3883 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3884 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
| 3885 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3886 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3887 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3888 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3889 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 3890 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3891 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3892 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3893 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3894 | static constexpr size_t kFieldReturnTypeSize = |
| 3895 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3896 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3897 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3898 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3899 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3900 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3901 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3902 | HInvoke(ArenaAllocator* arena, |
| 3903 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3904 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3905 | Primitive::Type return_type, |
| 3906 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3907 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3908 | ArtMethod* resolved_method, |
| 3909 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3910 | : HVariableInputSizeInstruction( |
| 3911 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 3912 | dex_pc, |
| 3913 | arena, |
| 3914 | number_of_arguments + number_of_other_inputs, |
| 3915 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3916 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3917 | resolved_method_(resolved_method), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3918 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3919 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3920 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3921 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3922 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3923 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3924 | } |
| 3925 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3926 | uint32_t number_of_arguments_; |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3927 | ArtMethod* const resolved_method_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3928 | const uint32_t dex_method_index_; |
| 3929 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3930 | |
| 3931 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3932 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3933 | |
| 3934 | private: |
| 3935 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3936 | }; |
| 3937 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3938 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3939 | public: |
| 3940 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3941 | uint32_t number_of_arguments, |
| 3942 | Primitive::Type return_type, |
| 3943 | uint32_t dex_pc, |
| 3944 | uint32_t dex_method_index, |
| 3945 | InvokeType invoke_type) |
| 3946 | : HInvoke(arena, |
| 3947 | number_of_arguments, |
| 3948 | 0u /* number_of_other_inputs */, |
| 3949 | return_type, |
| 3950 | dex_pc, |
| 3951 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3952 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3953 | invoke_type) { |
| 3954 | } |
| 3955 | |
| 3956 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3957 | |
| 3958 | private: |
| 3959 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3960 | }; |
| 3961 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3962 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3963 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3964 | // Requirements of this method call regarding the class |
| 3965 | // initialization (clinit) check of its declaring class. |
| 3966 | enum class ClinitCheckRequirement { |
| 3967 | kNone, // Class already initialized. |
| 3968 | kExplicit, // Static call having explicit clinit check as last input. |
| 3969 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3970 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3971 | }; |
| 3972 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3973 | // Determines how to load the target ArtMethod*. |
| 3974 | enum class MethodLoadKind { |
| 3975 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3976 | kStringInit, |
| 3977 | |
| 3978 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3979 | kRecursive, |
| 3980 | |
| 3981 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3982 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3983 | kDirectAddress, |
| 3984 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3985 | // 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] | 3986 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3987 | // may cause class initialization (the entry may point to a resolution method), |
| 3988 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3989 | kDexCachePcRelative, |
| 3990 | |
| 3991 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3992 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3993 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3994 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3995 | kDexCacheViaMethod, |
| 3996 | }; |
| 3997 | |
| 3998 | // Determines the location of the code pointer. |
| 3999 | enum class CodePtrLocation { |
| 4000 | // Recursive call, use local PC-relative call instruction. |
| 4001 | kCallSelf, |
| 4002 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4003 | // Use code pointer from the ArtMethod*. |
| 4004 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4005 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4006 | kCallArtMethod, |
| 4007 | }; |
| 4008 | |
| 4009 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4010 | MethodLoadKind method_load_kind; |
| 4011 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4012 | // The method load data holds |
| 4013 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4014 | // Note that there are multiple string init methods, each having its own offset. |
| 4015 | // - the method address for kDirectAddress |
| 4016 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4017 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4018 | }; |
| 4019 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4020 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 4021 | uint32_t number_of_arguments, |
| 4022 | Primitive::Type return_type, |
| 4023 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4024 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4025 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4026 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4027 | InvokeType invoke_type, |
| 4028 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4029 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4030 | : HInvoke(arena, |
| 4031 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4032 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4033 | // potentially one other if the clinit check is explicit, and potentially |
| 4034 | // one other if the method is a string factory. |
| 4035 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4036 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4037 | return_type, |
| 4038 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4039 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4040 | resolved_method, |
| 4041 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4042 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4043 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4044 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4045 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4046 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4047 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4048 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4049 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4050 | |
| 4051 | // Using the current method is the default and once we find a better |
| 4052 | // method load kind, we should not go back to using the current method. |
| 4053 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4054 | |
| 4055 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4056 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4057 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4058 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4059 | dispatch_info_ = dispatch_info; |
| 4060 | } |
| 4061 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4062 | void AddSpecialInput(HInstruction* input) { |
| 4063 | // We allow only one special input. |
| 4064 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4065 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4066 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4067 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4068 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4069 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4070 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4071 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4072 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4073 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4074 | DCHECK(!input_records.empty()); |
| 4075 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4076 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4077 | // Note: `last_input` may be null during arguments setup. |
| 4078 | if (last_input != nullptr) { |
| 4079 | // `last_input` is the last input of a static invoke marked as having |
| 4080 | // an explicit clinit check. It must either be: |
| 4081 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4082 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4083 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4084 | } |
| 4085 | } |
| 4086 | return input_records; |
| 4087 | } |
| 4088 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4089 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4090 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4091 | // TODO: for intrinsics we can generate implicit null checks. |
| 4092 | return false; |
| 4093 | } |
| 4094 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4095 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4096 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4097 | } |
| 4098 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4099 | // Get the index of the special input, if any. |
| 4100 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4101 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4102 | // method pointer; otherwise there may be one platform-specific special input, |
| 4103 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4104 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4105 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4106 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4107 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4108 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4109 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4110 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4111 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4112 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4113 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4114 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 4115 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4116 | bool HasCurrentMethodInput() const { |
| 4117 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4118 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4119 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4120 | return true; |
| 4121 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4122 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4123 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4124 | return false; |
| 4125 | } |
| 4126 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4127 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4128 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4129 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4130 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | uint64_t GetMethodAddress() const { |
| 4134 | DCHECK(HasMethodAddress()); |
| 4135 | return dispatch_info_.method_load_data; |
| 4136 | } |
| 4137 | |
| 4138 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4139 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4140 | return dispatch_info_.method_load_data; |
| 4141 | } |
| 4142 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4143 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4144 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4145 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4146 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4147 | // Is this instruction a call to a static method? |
| 4148 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4149 | return GetInvokeType() == kStatic; |
| 4150 | } |
| 4151 | |
| 4152 | MethodReference GetTargetMethod() const { |
| 4153 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4154 | } |
| 4155 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4156 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4157 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4158 | // instruction; only relevant for static calls with explicit clinit check. |
| 4159 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4160 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4161 | size_t last_input_index = inputs_.size() - 1u; |
| 4162 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4163 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4164 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4165 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4166 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4167 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4168 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4169 | } |
| 4170 | |
| 4171 | // 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] | 4172 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4173 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4174 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | // Is this a call to a static method whose declaring class has an |
| 4178 | // implicit intialization check requirement? |
| 4179 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4180 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4181 | } |
| 4182 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4183 | // Does this method load kind need the current method as an input? |
| 4184 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4185 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4186 | } |
| 4187 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4188 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4189 | |
| 4190 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4191 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4192 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4193 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4194 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4195 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4196 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4197 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4198 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4199 | kFieldClinitCheckRequirement, |
| 4200 | kFieldClinitCheckRequirementSize>; |
| 4201 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4202 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4203 | MethodReference target_method_; |
| 4204 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4205 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4206 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4207 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4208 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4209 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4210 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4211 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4212 | public: |
| 4213 | HInvokeVirtual(ArenaAllocator* arena, |
| 4214 | uint32_t number_of_arguments, |
| 4215 | Primitive::Type return_type, |
| 4216 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4217 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4218 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4219 | uint32_t vtable_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4220 | : HInvoke(arena, |
| 4221 | number_of_arguments, |
| 4222 | 0u, |
| 4223 | return_type, |
| 4224 | dex_pc, |
| 4225 | dex_method_index, |
| 4226 | resolved_method, |
| 4227 | kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4228 | vtable_index_(vtable_index) {} |
| 4229 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4230 | bool CanBeNull() const OVERRIDE { |
| 4231 | switch (GetIntrinsic()) { |
| 4232 | case Intrinsics::kThreadCurrentThread: |
| 4233 | case Intrinsics::kStringBufferAppend: |
| 4234 | case Intrinsics::kStringBufferToString: |
| 4235 | case Intrinsics::kStringBuilderAppend: |
| 4236 | case Intrinsics::kStringBuilderToString: |
| 4237 | return false; |
| 4238 | default: |
| 4239 | return HInvoke::CanBeNull(); |
| 4240 | } |
| 4241 | } |
| 4242 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4243 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4244 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4245 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4246 | } |
| 4247 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4248 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4249 | |
| 4250 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4251 | |
| 4252 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4253 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4254 | const uint32_t vtable_index_; |
| 4255 | |
| 4256 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4257 | }; |
| 4258 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4259 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4260 | public: |
| 4261 | HInvokeInterface(ArenaAllocator* arena, |
| 4262 | uint32_t number_of_arguments, |
| 4263 | Primitive::Type return_type, |
| 4264 | uint32_t dex_pc, |
| 4265 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4266 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4267 | uint32_t imt_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4268 | : HInvoke(arena, |
| 4269 | number_of_arguments, |
| 4270 | 0u, |
| 4271 | return_type, |
| 4272 | dex_pc, |
| 4273 | dex_method_index, |
| 4274 | resolved_method, |
| 4275 | kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4276 | imt_index_(imt_index) {} |
| 4277 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4278 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4279 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4280 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4281 | } |
| 4282 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4283 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4284 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4285 | |
| 4286 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4287 | |
| 4288 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4289 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4290 | const uint32_t imt_index_; |
| 4291 | |
| 4292 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4293 | }; |
| 4294 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4295 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4296 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4297 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4298 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4299 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4300 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4301 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4302 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4303 | |
| 4304 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4305 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4306 | } |
| 4307 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4308 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4309 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4310 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4311 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4312 | } |
| 4313 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4314 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4315 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4316 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4317 | DECLARE_INSTRUCTION(Neg); |
| 4318 | |
| 4319 | private: |
| 4320 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4321 | }; |
| 4322 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4323 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4324 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4325 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4326 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4327 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4328 | dex::TypeIndex type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4329 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4330 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4331 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4332 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4333 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4334 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4335 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4336 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4337 | } |
| 4338 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4339 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4340 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4341 | |
| 4342 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4343 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4344 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4345 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4346 | bool CanThrow() const OVERRIDE { return true; } |
| 4347 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4348 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4349 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4350 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4351 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4352 | DECLARE_INSTRUCTION(NewArray); |
| 4353 | |
| 4354 | private: |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4355 | const dex::TypeIndex type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4356 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4357 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4358 | |
| 4359 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4360 | }; |
| 4361 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4362 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4363 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4364 | HAdd(Primitive::Type result_type, |
| 4365 | HInstruction* left, |
| 4366 | HInstruction* right, |
| 4367 | uint32_t dex_pc = kNoDexPc) |
| 4368 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4369 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4370 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4371 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4372 | 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] | 4373 | |
| 4374 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4375 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4376 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4377 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4378 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4379 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4380 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4381 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4382 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4383 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4384 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4385 | } |
| 4386 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4387 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4388 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4389 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4390 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4391 | DECLARE_INSTRUCTION(Add); |
| 4392 | |
| 4393 | private: |
| 4394 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4395 | }; |
| 4396 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4397 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4398 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4399 | HSub(Primitive::Type result_type, |
| 4400 | HInstruction* left, |
| 4401 | HInstruction* right, |
| 4402 | uint32_t dex_pc = kNoDexPc) |
| 4403 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4404 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4405 | 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] | 4406 | |
| 4407 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4408 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4409 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4410 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4411 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4412 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4413 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4414 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4415 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4416 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4417 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4418 | } |
| 4419 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4420 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4421 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4422 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4423 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4424 | DECLARE_INSTRUCTION(Sub); |
| 4425 | |
| 4426 | private: |
| 4427 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4428 | }; |
| 4429 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4430 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4431 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4432 | HMul(Primitive::Type result_type, |
| 4433 | HInstruction* left, |
| 4434 | HInstruction* right, |
| 4435 | uint32_t dex_pc = kNoDexPc) |
| 4436 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4437 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4438 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4439 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4440 | 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] | 4441 | |
| 4442 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4443 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4444 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4445 | } |
| 4446 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4447 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4448 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4449 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4450 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4451 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4452 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4453 | } |
| 4454 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4455 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4456 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4457 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4458 | |
| 4459 | DECLARE_INSTRUCTION(Mul); |
| 4460 | |
| 4461 | private: |
| 4462 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4463 | }; |
| 4464 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4465 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4466 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4467 | HDiv(Primitive::Type result_type, |
| 4468 | HInstruction* left, |
| 4469 | HInstruction* right, |
| 4470 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4471 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4472 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4473 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4474 | T ComputeIntegral(T x, T y) const { |
| 4475 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4476 | // Our graph structure ensures we never have 0 for `y` during |
| 4477 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4478 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4479 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4480 | return (y == -1) ? -x : x / y; |
| 4481 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4482 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4483 | template <typename T> |
| 4484 | T ComputeFP(T x, T y) const { |
| 4485 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4486 | return x / y; |
| 4487 | } |
| 4488 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4489 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4490 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4491 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4492 | } |
| 4493 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4494 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4495 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4496 | } |
| 4497 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4498 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4499 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4500 | } |
| 4501 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4502 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4503 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4504 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4505 | |
| 4506 | DECLARE_INSTRUCTION(Div); |
| 4507 | |
| 4508 | private: |
| 4509 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4510 | }; |
| 4511 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4512 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4513 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4514 | HRem(Primitive::Type result_type, |
| 4515 | HInstruction* left, |
| 4516 | HInstruction* right, |
| 4517 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4518 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4519 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4520 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4521 | T ComputeIntegral(T x, T y) const { |
| 4522 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4523 | // Our graph structure ensures we never have 0 for `y` during |
| 4524 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4525 | DCHECK_NE(y, 0); |
| 4526 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4527 | return (y == -1) ? 0 : x % y; |
| 4528 | } |
| 4529 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4530 | template <typename T> |
| 4531 | T ComputeFP(T x, T y) const { |
| 4532 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4533 | return std::fmod(x, y); |
| 4534 | } |
| 4535 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4536 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4537 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4538 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4539 | } |
| 4540 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4541 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4542 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4543 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4544 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4545 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4546 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4547 | } |
| 4548 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4549 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4550 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4551 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4552 | |
| 4553 | DECLARE_INSTRUCTION(Rem); |
| 4554 | |
| 4555 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4556 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4557 | }; |
| 4558 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4559 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4560 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4561 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4562 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4563 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4564 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4565 | SetRawInputAt(0, value); |
| 4566 | } |
| 4567 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4568 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4569 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4570 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4571 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4572 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4573 | return true; |
| 4574 | } |
| 4575 | |
| 4576 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4577 | bool CanThrow() const OVERRIDE { return true; } |
| 4578 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4579 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4580 | |
| 4581 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4582 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4583 | }; |
| 4584 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4585 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4586 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4587 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4588 | HInstruction* value, |
| 4589 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4590 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4591 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4592 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4593 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4594 | } |
| 4595 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4596 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4597 | 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] | 4598 | return value << (distance & max_shift_distance); |
| 4599 | } |
| 4600 | |
| 4601 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4602 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4603 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4604 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4605 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4606 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4607 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4608 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4609 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4610 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4611 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4612 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4613 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4614 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4615 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4616 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4617 | UNREACHABLE(); |
| 4618 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4619 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4620 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4621 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4622 | UNREACHABLE(); |
| 4623 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4624 | |
| 4625 | DECLARE_INSTRUCTION(Shl); |
| 4626 | |
| 4627 | private: |
| 4628 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4629 | }; |
| 4630 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4631 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4632 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4633 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4634 | HInstruction* value, |
| 4635 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4636 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4637 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4638 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4639 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4640 | } |
| 4641 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4642 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4643 | 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] | 4644 | return value >> (distance & max_shift_distance); |
| 4645 | } |
| 4646 | |
| 4647 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4648 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4649 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4650 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4651 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4652 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4653 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4654 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4655 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4656 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4657 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4658 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4659 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4660 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4661 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4662 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4663 | UNREACHABLE(); |
| 4664 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4665 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4666 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4667 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4668 | UNREACHABLE(); |
| 4669 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4670 | |
| 4671 | DECLARE_INSTRUCTION(Shr); |
| 4672 | |
| 4673 | private: |
| 4674 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4675 | }; |
| 4676 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4677 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4678 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4679 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4680 | HInstruction* value, |
| 4681 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4682 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4683 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4684 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4685 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4688 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4689 | 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] | 4690 | typedef typename std::make_unsigned<T>::type V; |
| 4691 | V ux = static_cast<V>(value); |
| 4692 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4693 | } |
| 4694 | |
| 4695 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4696 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4697 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4698 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4699 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4700 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4701 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4702 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4703 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4704 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4705 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4706 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4707 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4708 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4709 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4710 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4711 | UNREACHABLE(); |
| 4712 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4713 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4714 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4715 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4716 | UNREACHABLE(); |
| 4717 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4718 | |
| 4719 | DECLARE_INSTRUCTION(UShr); |
| 4720 | |
| 4721 | private: |
| 4722 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4723 | }; |
| 4724 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4725 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4726 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4727 | HAnd(Primitive::Type result_type, |
| 4728 | HInstruction* left, |
| 4729 | HInstruction* right, |
| 4730 | uint32_t dex_pc = kNoDexPc) |
| 4731 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4732 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4733 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4734 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4735 | 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] | 4736 | |
| 4737 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4738 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4739 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4740 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4741 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4742 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4743 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4744 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4745 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4746 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4747 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4748 | UNREACHABLE(); |
| 4749 | } |
| 4750 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4751 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4752 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4753 | UNREACHABLE(); |
| 4754 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4755 | |
| 4756 | DECLARE_INSTRUCTION(And); |
| 4757 | |
| 4758 | private: |
| 4759 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4760 | }; |
| 4761 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4762 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4763 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4764 | HOr(Primitive::Type result_type, |
| 4765 | HInstruction* left, |
| 4766 | HInstruction* right, |
| 4767 | uint32_t dex_pc = kNoDexPc) |
| 4768 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4769 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4770 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4771 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4772 | 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] | 4773 | |
| 4774 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4775 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4776 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4777 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4778 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4779 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4780 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4781 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4782 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4783 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4784 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4785 | UNREACHABLE(); |
| 4786 | } |
| 4787 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4788 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4789 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4790 | UNREACHABLE(); |
| 4791 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4792 | |
| 4793 | DECLARE_INSTRUCTION(Or); |
| 4794 | |
| 4795 | private: |
| 4796 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4797 | }; |
| 4798 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4799 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4800 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4801 | HXor(Primitive::Type result_type, |
| 4802 | HInstruction* left, |
| 4803 | HInstruction* right, |
| 4804 | uint32_t dex_pc = kNoDexPc) |
| 4805 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4806 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4807 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4808 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4809 | 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] | 4810 | |
| 4811 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4812 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4813 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4814 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4815 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4816 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4817 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4818 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4819 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4820 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4821 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4822 | UNREACHABLE(); |
| 4823 | } |
| 4824 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4825 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4826 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4827 | UNREACHABLE(); |
| 4828 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4829 | |
| 4830 | DECLARE_INSTRUCTION(Xor); |
| 4831 | |
| 4832 | private: |
| 4833 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4834 | }; |
| 4835 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4836 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4837 | public: |
| 4838 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4839 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4840 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4841 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4842 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4843 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4844 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4845 | 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] | 4846 | typedef typename std::make_unsigned<T>::type V; |
| 4847 | V ux = static_cast<V>(value); |
| 4848 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4849 | return static_cast<T>(ux); |
| 4850 | } else { |
| 4851 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4852 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4853 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4854 | } |
| 4855 | } |
| 4856 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4857 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4858 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4859 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4860 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4861 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4862 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4863 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4864 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4865 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4866 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4867 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4868 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4869 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4870 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4871 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4872 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4873 | UNREACHABLE(); |
| 4874 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4875 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4876 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4877 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4878 | UNREACHABLE(); |
| 4879 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4880 | |
| 4881 | DECLARE_INSTRUCTION(Ror); |
| 4882 | |
| 4883 | private: |
| 4884 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4885 | }; |
| 4886 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4887 | // The value of a parameter in this method. Its location depends on |
| 4888 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4889 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4890 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4891 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4892 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4893 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4894 | Primitive::Type parameter_type, |
| 4895 | bool is_this = false) |
| 4896 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4897 | dex_file_(dex_file), |
| 4898 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4899 | index_(index) { |
| 4900 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4901 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4902 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4903 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4904 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4905 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4906 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4907 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4908 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4909 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4910 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4911 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4912 | DECLARE_INSTRUCTION(ParameterValue); |
| 4913 | |
| 4914 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4915 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4916 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4917 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4918 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4919 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4920 | "Too many packed fields."); |
| 4921 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4922 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4923 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4924 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4925 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4926 | const uint8_t index_; |
| 4927 | |
| 4928 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4929 | }; |
| 4930 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4931 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4932 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4933 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4934 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4935 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4936 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4937 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4938 | return true; |
| 4939 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4940 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4941 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4942 | |
| 4943 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4944 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4945 | } |
| 4946 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4947 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4948 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4949 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4950 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4951 | UNREACHABLE(); |
| 4952 | } |
| 4953 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4954 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4955 | UNREACHABLE(); |
| 4956 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4957 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4958 | DECLARE_INSTRUCTION(Not); |
| 4959 | |
| 4960 | private: |
| 4961 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4962 | }; |
| 4963 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4964 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4965 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4966 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4967 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4968 | |
| 4969 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4970 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4971 | return true; |
| 4972 | } |
| 4973 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4974 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4975 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4976 | return !x; |
| 4977 | } |
| 4978 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4979 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4980 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4981 | } |
| 4982 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4983 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4984 | UNREACHABLE(); |
| 4985 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4986 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4987 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4988 | UNREACHABLE(); |
| 4989 | } |
| 4990 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4991 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4992 | UNREACHABLE(); |
| 4993 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4994 | |
| 4995 | DECLARE_INSTRUCTION(BooleanNot); |
| 4996 | |
| 4997 | private: |
| 4998 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4999 | }; |
| 5000 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5001 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5002 | public: |
| 5003 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 5004 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5005 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5006 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5007 | // Invariant: We should never generate a conversion to a Boolean value. |
| 5008 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | HInstruction* GetInput() const { return InputAt(0); } |
| 5012 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 5013 | Primitive::Type GetResultType() const { return GetType(); } |
| 5014 | |
| 5015 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5016 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5017 | return true; |
| 5018 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5019 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5020 | // Try to statically evaluate the conversion and return a HConstant |
| 5021 | // containing the result. If the input cannot be converted, return nullptr. |
| 5022 | HConstant* TryStaticEvaluation() const; |
| 5023 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5024 | DECLARE_INSTRUCTION(TypeConversion); |
| 5025 | |
| 5026 | private: |
| 5027 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 5028 | }; |
| 5029 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5030 | static constexpr uint32_t kNoRegNumber = -1; |
| 5031 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5032 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5033 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5034 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 5035 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5036 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5037 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5038 | SetRawInputAt(0, value); |
| 5039 | } |
| 5040 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5041 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5042 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5043 | return true; |
| 5044 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5045 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5046 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5047 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5048 | bool CanThrow() const OVERRIDE { return true; } |
| 5049 | |
| 5050 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5051 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5052 | |
| 5053 | DECLARE_INSTRUCTION(NullCheck); |
| 5054 | |
| 5055 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5056 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 5057 | }; |
| 5058 | |
| 5059 | class FieldInfo : public ValueObject { |
| 5060 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5061 | FieldInfo(MemberOffset field_offset, |
| 5062 | Primitive::Type field_type, |
| 5063 | bool is_volatile, |
| 5064 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5065 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5066 | const DexFile& dex_file, |
| 5067 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5068 | : field_offset_(field_offset), |
| 5069 | field_type_(field_type), |
| 5070 | is_volatile_(is_volatile), |
| 5071 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5072 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5073 | dex_file_(dex_file), |
| 5074 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5075 | |
| 5076 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5077 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5078 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5079 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5080 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5081 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5082 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5083 | |
| 5084 | private: |
| 5085 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5086 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5087 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5088 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5089 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5090 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5091 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5092 | }; |
| 5093 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5094 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5095 | public: |
| 5096 | HInstanceFieldGet(HInstruction* value, |
| 5097 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5098 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5099 | bool is_volatile, |
| 5100 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5101 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5102 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5103 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5104 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5105 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5106 | field_info_(field_offset, |
| 5107 | field_type, |
| 5108 | is_volatile, |
| 5109 | field_idx, |
| 5110 | declaring_class_def_index, |
| 5111 | dex_file, |
| 5112 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5113 | SetRawInputAt(0, value); |
| 5114 | } |
| 5115 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5116 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5117 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5118 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5119 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5120 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5121 | } |
| 5122 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5123 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5124 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5125 | } |
| 5126 | |
| 5127 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5128 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5129 | } |
| 5130 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5131 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5132 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5133 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5134 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5135 | |
| 5136 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5137 | |
| 5138 | private: |
| 5139 | const FieldInfo field_info_; |
| 5140 | |
| 5141 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5142 | }; |
| 5143 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5144 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5145 | public: |
| 5146 | HInstanceFieldSet(HInstruction* object, |
| 5147 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5148 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5149 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5150 | bool is_volatile, |
| 5151 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5152 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5153 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5154 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5155 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5156 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5157 | field_info_(field_offset, |
| 5158 | field_type, |
| 5159 | is_volatile, |
| 5160 | field_idx, |
| 5161 | declaring_class_def_index, |
| 5162 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5163 | dex_cache) { |
| 5164 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5165 | SetRawInputAt(0, object); |
| 5166 | SetRawInputAt(1, value); |
| 5167 | } |
| 5168 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5169 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5170 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5171 | } |
| 5172 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5173 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5174 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5175 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5176 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5177 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5178 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5179 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5180 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5181 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5182 | |
| 5183 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5184 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5185 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5186 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5187 | "Too many packed fields."); |
| 5188 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5189 | const FieldInfo field_info_; |
| 5190 | |
| 5191 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5192 | }; |
| 5193 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5194 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5195 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5196 | HArrayGet(HInstruction* array, |
| 5197 | HInstruction* index, |
| 5198 | Primitive::Type type, |
| 5199 | uint32_t dex_pc, |
| 5200 | bool is_string_char_at = false) |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5201 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5202 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5203 | SetRawInputAt(0, array); |
| 5204 | SetRawInputAt(1, index); |
| 5205 | } |
| 5206 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5207 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5208 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5209 | return true; |
| 5210 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5211 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5212 | // TODO: We can be smarter here. |
| 5213 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5214 | // which generates the implicit null check. There are cases when these can be removed |
| 5215 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5216 | // implicit check here (as long as the address falls in the first page). |
| 5217 | return false; |
| 5218 | } |
| 5219 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5220 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5221 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5222 | if (kIsDebugBuild && result) { |
| 5223 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5224 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5225 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5226 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5227 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5228 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5229 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5230 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5231 | } |
| 5232 | } |
| 5233 | return result; |
| 5234 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5235 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5236 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5237 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5238 | HInstruction* GetArray() const { return InputAt(0); } |
| 5239 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5240 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5241 | DECLARE_INSTRUCTION(ArrayGet); |
| 5242 | |
| 5243 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5244 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5245 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5246 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5247 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5248 | // a flag, so that code generators don't need to do the locking. |
| 5249 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5250 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5251 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5252 | "Too many packed fields."); |
| 5253 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5254 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5255 | }; |
| 5256 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5257 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5258 | public: |
| 5259 | HArraySet(HInstruction* array, |
| 5260 | HInstruction* index, |
| 5261 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5262 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5263 | uint32_t dex_pc) |
| 5264 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5265 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5266 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5267 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5268 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5269 | SetRawInputAt(0, array); |
| 5270 | SetRawInputAt(1, index); |
| 5271 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5272 | // Make a best guess now, may be refined during SSA building. |
| 5273 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5274 | } |
| 5275 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5276 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5277 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5278 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5279 | } |
| 5280 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5281 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5282 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5283 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5284 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5285 | // TODO: Same as for ArrayGet. |
| 5286 | return false; |
| 5287 | } |
| 5288 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5289 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5290 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5291 | } |
| 5292 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5293 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5294 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5295 | } |
| 5296 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5297 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5298 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5299 | } |
| 5300 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5301 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5302 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5303 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5304 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5305 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5306 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5307 | HInstruction* GetArray() const { return InputAt(0); } |
| 5308 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5309 | HInstruction* GetValue() const { return InputAt(2); } |
| 5310 | |
| 5311 | Primitive::Type GetComponentType() const { |
| 5312 | // The Dex format does not type floating point index operations. Since the |
| 5313 | // `expected_component_type_` is set during building and can therefore not |
| 5314 | // be correct, we also check what is the value type. If it is a floating |
| 5315 | // point type, we must use that type. |
| 5316 | Primitive::Type value_type = GetValue()->GetType(); |
| 5317 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5318 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5319 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5320 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5321 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5322 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5323 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5324 | } |
| 5325 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5326 | void ComputeSideEffects() { |
| 5327 | Primitive::Type type = GetComponentType(); |
| 5328 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5329 | SideEffectsForArchRuntimeCalls(type))); |
| 5330 | } |
| 5331 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5332 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5333 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5334 | } |
| 5335 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5336 | DECLARE_INSTRUCTION(ArraySet); |
| 5337 | |
| 5338 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5339 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5340 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5341 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5342 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5343 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5344 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5345 | // Cached information for the reference_type_info_ so that codegen |
| 5346 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5347 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5348 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5349 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5350 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5351 | using ExpectedComponentTypeField = |
| 5352 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5353 | |
| 5354 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5355 | }; |
| 5356 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5357 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5358 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5359 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5360 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5361 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5362 | // Note that arrays do not change length, so the instruction does not |
| 5363 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5364 | SetRawInputAt(0, array); |
| 5365 | } |
| 5366 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5367 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5368 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5369 | return true; |
| 5370 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5371 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5372 | return obj == InputAt(0); |
| 5373 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5374 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5375 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5376 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5377 | DECLARE_INSTRUCTION(ArrayLength); |
| 5378 | |
| 5379 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5380 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5381 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5382 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5383 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5384 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5385 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5386 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5387 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5388 | "Too many packed fields."); |
| 5389 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5390 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5391 | }; |
| 5392 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5393 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5394 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5395 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5396 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5397 | HBoundsCheck(HInstruction* index, |
| 5398 | HInstruction* length, |
| 5399 | uint32_t dex_pc, |
| 5400 | uint32_t string_char_at_method_index = DexFile::kDexNoIndex) |
| 5401 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc), |
| 5402 | string_char_at_method_index_(string_char_at_method_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5403 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5404 | SetRawInputAt(0, index); |
| 5405 | SetRawInputAt(1, length); |
| 5406 | } |
| 5407 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5408 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5409 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5410 | return true; |
| 5411 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5412 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5413 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5414 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5415 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5416 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5417 | bool IsStringCharAt() const { return GetStringCharAtMethodIndex() != DexFile::kDexNoIndex; } |
| 5418 | uint32_t GetStringCharAtMethodIndex() const { return string_char_at_method_index_; } |
| 5419 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5420 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5421 | |
| 5422 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5423 | |
| 5424 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5425 | // We treat a String as an array, creating the HBoundsCheck from String.charAt() |
| 5426 | // intrinsic in the instruction simplifier. We want to include the String.charAt() |
| 5427 | // in the stack trace if we actually throw the StringIndexOutOfBoundsException, |
| 5428 | // so we need to create an HEnvironment which will be translated to an InlineInfo |
| 5429 | // indicating the extra stack frame. Since we add this HEnvironment quite late, |
| 5430 | // in the PrepareForRegisterAllocation pass, we need to remember the method index |
| 5431 | // from the invoke as we don't want to look again at the dex bytecode. |
| 5432 | uint32_t string_char_at_method_index_; // DexFile::kDexNoIndex if regular array. |
| 5433 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5434 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5435 | }; |
| 5436 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5437 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5438 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5439 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5440 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5441 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5442 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5443 | return true; |
| 5444 | } |
| 5445 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5446 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5447 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5448 | |
| 5449 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5450 | |
| 5451 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5452 | // Only used for code generation, in order to share the same slow path between back edges |
| 5453 | // of a same loop. |
| 5454 | SlowPathCode* slow_path_; |
| 5455 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5456 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5457 | }; |
| 5458 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5459 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5460 | // It ensures that we can generate line number and local variables at this point. |
| 5461 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5462 | public: |
| 5463 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5464 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5465 | |
| 5466 | bool NeedsEnvironment() const OVERRIDE { |
| 5467 | return true; |
| 5468 | } |
| 5469 | |
| 5470 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5471 | |
| 5472 | private: |
| 5473 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5474 | }; |
| 5475 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5476 | /** |
| 5477 | * Instruction to load a Class object. |
| 5478 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5479 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5480 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5481 | // Determines how to load the Class. |
| 5482 | enum class LoadKind { |
| 5483 | // Use the Class* from the method's own ArtMethod*. |
| 5484 | kReferrersClass, |
| 5485 | |
| 5486 | // Use boot image Class* address that will be known at link time. |
| 5487 | // Used for boot image classes referenced by boot image code in non-PIC mode. |
| 5488 | kBootImageLinkTimeAddress, |
| 5489 | |
| 5490 | // Use PC-relative boot image Class* address that will be known at link time. |
| 5491 | // Used for boot image classes referenced by boot image code in PIC mode. |
| 5492 | kBootImageLinkTimePcRelative, |
| 5493 | |
| 5494 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5495 | // Used for boot image classes referenced by apps in AOT- and JIT-compiled code. |
| 5496 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5497 | // GetIncludePatchInformation(). |
| 5498 | kBootImageAddress, |
| 5499 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5500 | // Load from the root table associated with the JIT compiled method. |
| 5501 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5502 | |
| 5503 | // Load from resolved types array in the dex cache using a PC-relative load. |
| 5504 | // Used for classes outside boot image when we know that we can access |
| 5505 | // the dex cache arrays using a PC-relative load. |
| 5506 | kDexCachePcRelative, |
| 5507 | |
| 5508 | // Load from resolved types array accessed through the class loaded from |
| 5509 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5510 | // all other types are unavailable. |
| 5511 | kDexCacheViaMethod, |
| 5512 | |
| 5513 | kLast = kDexCacheViaMethod |
| 5514 | }; |
| 5515 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5516 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5517 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5518 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5519 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5520 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5521 | bool needs_access_check) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5522 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5523 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5524 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5525 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5526 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5527 | // Referrers class should not need access check. We never inline unverified |
| 5528 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5529 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5530 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5531 | SetPackedField<LoadKindField>( |
| 5532 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kDexCacheViaMethod); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5533 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5534 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5535 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5536 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5540 | DCHECK(HasAddress(load_kind)); |
| 5541 | load_data_.address = address; |
| 5542 | SetLoadKindInternal(load_kind); |
| 5543 | } |
| 5544 | |
| 5545 | void SetLoadKindWithTypeReference(LoadKind load_kind, |
| 5546 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5547 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5548 | DCHECK(HasTypeReference(load_kind)); |
| 5549 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5550 | DCHECK_EQ(type_index_, type_index); |
| 5551 | SetLoadKindInternal(load_kind); |
| 5552 | } |
| 5553 | |
| 5554 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5555 | const DexFile& dex_file, |
| 5556 | uint32_t element_index) { |
| 5557 | DCHECK(HasDexCacheReference(load_kind)); |
| 5558 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5559 | load_data_.dex_cache_element_index = element_index; |
| 5560 | SetLoadKindInternal(load_kind); |
| 5561 | } |
| 5562 | |
| 5563 | LoadKind GetLoadKind() const { |
| 5564 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5565 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5566 | |
| 5567 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5568 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5569 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5570 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5571 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5572 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5573 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5574 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5575 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5576 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5577 | } |
| 5578 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5579 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5580 | // The entrypoint the code generator is going to call does not do |
| 5581 | // clinit of the class. |
| 5582 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5583 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5587 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5588 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5589 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5590 | } |
| 5591 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5592 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5593 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5594 | } |
| 5595 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5596 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5597 | return loaded_class_rti_; |
| 5598 | } |
| 5599 | |
| 5600 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5601 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5602 | DCHECK(rti.IsExact()); |
| 5603 | loaded_class_rti_ = rti; |
| 5604 | } |
| 5605 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5606 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5607 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5608 | |
| 5609 | uint32_t GetDexCacheElementOffset() const; |
| 5610 | |
| 5611 | uint64_t GetAddress() const { |
| 5612 | DCHECK(HasAddress(GetLoadKind())); |
| 5613 | return load_data_.address; |
| 5614 | } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5615 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5616 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5617 | return !IsReferrersClass(); |
| 5618 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5619 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5620 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5621 | return SideEffects::CanTriggerGC(); |
| 5622 | } |
| 5623 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5624 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5625 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5626 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5627 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5628 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5629 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5630 | void MarkInDexCache() { |
| 5631 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5632 | DCHECK(!NeedsEnvironment()); |
| 5633 | RemoveEnvironment(); |
| 5634 | SetSideEffects(SideEffects::None()); |
| 5635 | } |
| 5636 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5637 | void MarkInBootImage() { |
| 5638 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 5639 | } |
| 5640 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5641 | void AddSpecialInput(HInstruction* special_input); |
| 5642 | |
| 5643 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5644 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5645 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5646 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 5647 | } |
| 5648 | |
| 5649 | Primitive::Type GetType() const OVERRIDE { |
| 5650 | return Primitive::kPrimNot; |
| 5651 | } |
| 5652 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5653 | DECLARE_INSTRUCTION(LoadClass); |
| 5654 | |
| 5655 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5656 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5657 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5658 | static constexpr size_t kFlagIsInBootImage = kFlagIsInDexCache + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5659 | // Whether this instruction must generate the initialization check. |
| 5660 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5661 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5662 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 5663 | static constexpr size_t kFieldLoadKindSize = |
| 5664 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5665 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5666 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5667 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 5668 | |
| 5669 | static bool HasTypeReference(LoadKind load_kind) { |
| 5670 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5671 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5672 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5673 | load_kind == LoadKind::kReferrersClass; |
| 5674 | } |
| 5675 | |
| 5676 | static bool HasAddress(LoadKind load_kind) { |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5677 | return load_kind == LoadKind::kBootImageAddress || |
| 5678 | load_kind == LoadKind::kJitTableAddress; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5679 | } |
| 5680 | |
| 5681 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5682 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5683 | } |
| 5684 | |
| 5685 | void SetLoadKindInternal(LoadKind load_kind); |
| 5686 | |
| 5687 | // The special input is the HCurrentMethod for kDexCacheViaMethod or kReferrersClass. |
| 5688 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5689 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
| 5690 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5691 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5692 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5693 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5694 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5695 | union { |
| 5696 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5697 | uint64_t address; // Up to 64-bit, needed for kJitTableAddress on 64-bit targets. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5698 | } load_data_; |
| 5699 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5700 | ReferenceTypeInfo loaded_class_rti_; |
| 5701 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5702 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5703 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5704 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 5705 | |
| 5706 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5707 | inline uint32_t HLoadClass::GetDexCacheElementOffset() const { |
| 5708 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5709 | return load_data_.dex_cache_element_index; |
| 5710 | } |
| 5711 | |
| 5712 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5713 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5714 | // The special input is used for PC-relative loads on some architectures, |
| 5715 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5716 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5717 | GetLoadKind() == LoadKind::kDexCachePcRelative || |
| 5718 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5719 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5720 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5721 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 5722 | special_input->AddUseAt(this, 0); |
| 5723 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5724 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5725 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5726 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5727 | // Determines how to load the String. |
| 5728 | enum class LoadKind { |
| 5729 | // Use boot image String* address that will be known at link time. |
| 5730 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5731 | kBootImageLinkTimeAddress, |
| 5732 | |
| 5733 | // Use PC-relative boot image String* address that will be known at link time. |
| 5734 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5735 | kBootImageLinkTimePcRelative, |
| 5736 | |
| 5737 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5738 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5739 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5740 | // GetIncludePatchInformation(). |
| 5741 | kBootImageAddress, |
| 5742 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5743 | // Load from an entry in the .bss section using a PC-relative load. |
| 5744 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 5745 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5746 | |
| 5747 | // Load from resolved strings array accessed through the class loaded from |
| 5748 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5749 | // all other types are unavailable. |
| 5750 | kDexCacheViaMethod, |
| 5751 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5752 | // Load from the root table associated with the JIT compiled method. |
| 5753 | kJitTableAddress, |
| 5754 | |
| 5755 | kLast = kJitTableAddress, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5756 | }; |
| 5757 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5758 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5759 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5760 | const DexFile& dex_file, |
| 5761 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5762 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5763 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5764 | string_index_(string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5765 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5766 | load_data_.dex_file_ = &dex_file; |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5767 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5768 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5769 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5770 | DCHECK(HasAddress(load_kind)); |
| 5771 | load_data_.address = address; |
| 5772 | SetLoadKindInternal(load_kind); |
| 5773 | } |
| 5774 | |
| 5775 | void SetLoadKindWithStringReference(LoadKind load_kind, |
| 5776 | const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5777 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5778 | DCHECK(HasStringReference(load_kind)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5779 | load_data_.dex_file_ = &dex_file; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5780 | string_index_ = string_index; |
| 5781 | SetLoadKindInternal(load_kind); |
| 5782 | } |
| 5783 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5784 | LoadKind GetLoadKind() const { |
| 5785 | return GetPackedField<LoadKindField>(); |
| 5786 | } |
| 5787 | |
| 5788 | const DexFile& GetDexFile() const; |
| 5789 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5790 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5791 | return string_index_; |
| 5792 | } |
| 5793 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5794 | uint64_t GetAddress() const { |
| 5795 | DCHECK(HasAddress(GetLoadKind())); |
| 5796 | return load_data_.address; |
| 5797 | } |
| 5798 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5799 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5800 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5801 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5802 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5803 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5804 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5805 | // Will call the runtime if we need to load the string through |
| 5806 | // the dex cache and the string is not guaranteed to be there yet. |
| 5807 | bool NeedsEnvironment() const OVERRIDE { |
| 5808 | LoadKind load_kind = GetLoadKind(); |
| 5809 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5810 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5811 | load_kind == LoadKind::kBootImageAddress || |
| 5812 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5813 | return false; |
| 5814 | } |
Vladimir Marko | 4d1be49 | 2017-01-06 14:43:11 +0000 | [diff] [blame^] | 5815 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5816 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5817 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5818 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5819 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5820 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5821 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5822 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5823 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5824 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5825 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5826 | return SideEffects::CanTriggerGC(); |
| 5827 | } |
| 5828 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5829 | void AddSpecialInput(HInstruction* special_input); |
| 5830 | |
| 5831 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5832 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5833 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5834 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5835 | } |
| 5836 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5837 | Primitive::Type GetType() const OVERRIDE { |
| 5838 | return Primitive::kPrimNot; |
| 5839 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5840 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5841 | DECLARE_INSTRUCTION(LoadString); |
| 5842 | |
| 5843 | private: |
Vladimir Marko | 4d1be49 | 2017-01-06 14:43:11 +0000 | [diff] [blame^] | 5844 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5845 | static constexpr size_t kFieldLoadKindSize = |
| 5846 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5847 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5848 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5849 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5850 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5851 | static bool HasStringReference(LoadKind load_kind) { |
| 5852 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5853 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5854 | load_kind == LoadKind::kBssEntry || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5855 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5856 | load_kind == LoadKind::kJitTableAddress; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5857 | } |
| 5858 | |
| 5859 | static bool HasAddress(LoadKind load_kind) { |
Vladimir Marko | 54d6a20 | 2016-11-09 12:46:38 +0000 | [diff] [blame] | 5860 | return load_kind == LoadKind::kBootImageAddress; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5861 | } |
| 5862 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5863 | void SetLoadKindInternal(LoadKind load_kind); |
| 5864 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5865 | // The special input is the HCurrentMethod for kDexCacheViaMethod. |
| 5866 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5867 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5868 | HUserRecord<HInstruction*> special_input_; |
| 5869 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5870 | // String index serves also as the hash code and it's also needed for slow-paths, |
| 5871 | // so it must not be overwritten with other load data. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5872 | dex::StringIndex string_index_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5873 | |
| 5874 | union { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5875 | const DexFile* dex_file_; // For string reference. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5876 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5877 | } load_data_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5878 | |
| 5879 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5880 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5881 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5882 | |
| 5883 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5884 | inline const DexFile& HLoadString::GetDexFile() const { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5885 | DCHECK(HasStringReference(GetLoadKind())) << GetLoadKind(); |
| 5886 | return *load_data_.dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5887 | } |
| 5888 | |
| 5889 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5890 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5891 | // The special input is used for PC-relative loads on some architectures, |
| 5892 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5893 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5894 | GetLoadKind() == LoadKind::kBssEntry || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5895 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5896 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5897 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5898 | // so use the GetInputRecords() from the base class to set the input record. |
| 5899 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5900 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5901 | special_input->AddUseAt(this, 0); |
| 5902 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5903 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5904 | /** |
| 5905 | * Performs an initialization check on its Class object input. |
| 5906 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5907 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5908 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5909 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5910 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5911 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5912 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5913 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5914 | SetRawInputAt(0, constant); |
| 5915 | } |
| 5916 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5917 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5918 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5919 | return true; |
| 5920 | } |
| 5921 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5922 | bool NeedsEnvironment() const OVERRIDE { |
| 5923 | // May call runtime to initialize the class. |
| 5924 | return true; |
| 5925 | } |
| 5926 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5927 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5928 | |
| 5929 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5930 | |
| 5931 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5932 | |
| 5933 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5934 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5935 | }; |
| 5936 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5937 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5938 | public: |
| 5939 | HStaticFieldGet(HInstruction* cls, |
| 5940 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5941 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5942 | bool is_volatile, |
| 5943 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5944 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5945 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5946 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5947 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5948 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5949 | field_info_(field_offset, |
| 5950 | field_type, |
| 5951 | is_volatile, |
| 5952 | field_idx, |
| 5953 | declaring_class_def_index, |
| 5954 | dex_file, |
| 5955 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5956 | SetRawInputAt(0, cls); |
| 5957 | } |
| 5958 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5959 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5960 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5961 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5962 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5963 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5964 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | size_t ComputeHashCode() const OVERRIDE { |
| 5968 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5969 | } |
| 5970 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5971 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5972 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5973 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5974 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5975 | |
| 5976 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5977 | |
| 5978 | private: |
| 5979 | const FieldInfo field_info_; |
| 5980 | |
| 5981 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5982 | }; |
| 5983 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5984 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5985 | public: |
| 5986 | HStaticFieldSet(HInstruction* cls, |
| 5987 | HInstruction* value, |
| 5988 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5989 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5990 | bool is_volatile, |
| 5991 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5992 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5993 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5994 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5995 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5996 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5997 | field_info_(field_offset, |
| 5998 | field_type, |
| 5999 | is_volatile, |
| 6000 | field_idx, |
| 6001 | declaring_class_def_index, |
| 6002 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6003 | dex_cache) { |
| 6004 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6005 | SetRawInputAt(0, cls); |
| 6006 | SetRawInputAt(1, value); |
| 6007 | } |
| 6008 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6009 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6010 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 6011 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6012 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6013 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6014 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6015 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6016 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6017 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6018 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6019 | |
| 6020 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6021 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6022 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6023 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6024 | "Too many packed fields."); |
| 6025 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6026 | const FieldInfo field_info_; |
| 6027 | |
| 6028 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 6029 | }; |
| 6030 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6031 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6032 | public: |
| 6033 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 6034 | Primitive::Type field_type, |
| 6035 | uint32_t field_index, |
| 6036 | uint32_t dex_pc) |
| 6037 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6038 | field_index_(field_index) { |
| 6039 | SetRawInputAt(0, obj); |
| 6040 | } |
| 6041 | |
| 6042 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6043 | bool CanThrow() const OVERRIDE { return true; } |
| 6044 | |
| 6045 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6046 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6047 | |
| 6048 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6049 | |
| 6050 | private: |
| 6051 | const uint32_t field_index_; |
| 6052 | |
| 6053 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 6054 | }; |
| 6055 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6056 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6057 | public: |
| 6058 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6059 | HInstruction* value, |
| 6060 | Primitive::Type field_type, |
| 6061 | uint32_t field_index, |
| 6062 | uint32_t dex_pc) |
| 6063 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6064 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6065 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6066 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6067 | SetRawInputAt(0, obj); |
| 6068 | SetRawInputAt(1, value); |
| 6069 | } |
| 6070 | |
| 6071 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6072 | bool CanThrow() const OVERRIDE { return true; } |
| 6073 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6074 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6075 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6076 | |
| 6077 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6078 | |
| 6079 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6080 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6081 | static constexpr size_t kFieldFieldTypeSize = |
| 6082 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6083 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6084 | kFieldFieldType + kFieldFieldTypeSize; |
| 6085 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6086 | "Too many packed fields."); |
| 6087 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6088 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6089 | const uint32_t field_index_; |
| 6090 | |
| 6091 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 6092 | }; |
| 6093 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6094 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6095 | public: |
| 6096 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 6097 | uint32_t field_index, |
| 6098 | uint32_t dex_pc) |
| 6099 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6100 | field_index_(field_index) { |
| 6101 | } |
| 6102 | |
| 6103 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6104 | bool CanThrow() const OVERRIDE { return true; } |
| 6105 | |
| 6106 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6107 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6108 | |
| 6109 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6110 | |
| 6111 | private: |
| 6112 | const uint32_t field_index_; |
| 6113 | |
| 6114 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 6115 | }; |
| 6116 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6117 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6118 | public: |
| 6119 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 6120 | Primitive::Type field_type, |
| 6121 | uint32_t field_index, |
| 6122 | uint32_t dex_pc) |
| 6123 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6124 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6125 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6126 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6127 | SetRawInputAt(0, value); |
| 6128 | } |
| 6129 | |
| 6130 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6131 | bool CanThrow() const OVERRIDE { return true; } |
| 6132 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6133 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6134 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6135 | |
| 6136 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6137 | |
| 6138 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6139 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6140 | static constexpr size_t kFieldFieldTypeSize = |
| 6141 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6142 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6143 | kFieldFieldType + kFieldFieldTypeSize; |
| 6144 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6145 | "Too many packed fields."); |
| 6146 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6147 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6148 | const uint32_t field_index_; |
| 6149 | |
| 6150 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6151 | }; |
| 6152 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6153 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6154 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6155 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6156 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6157 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6158 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6159 | bool CanBeNull() const OVERRIDE { return false; } |
| 6160 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6161 | DECLARE_INSTRUCTION(LoadException); |
| 6162 | |
| 6163 | private: |
| 6164 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6165 | }; |
| 6166 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6167 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6168 | // 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] | 6169 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6170 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6171 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6172 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6173 | |
| 6174 | DECLARE_INSTRUCTION(ClearException); |
| 6175 | |
| 6176 | private: |
| 6177 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6178 | }; |
| 6179 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6180 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6181 | public: |
| 6182 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6183 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6184 | SetRawInputAt(0, exception); |
| 6185 | } |
| 6186 | |
| 6187 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6188 | |
| 6189 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6190 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6191 | bool CanThrow() const OVERRIDE { return true; } |
| 6192 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6193 | |
| 6194 | DECLARE_INSTRUCTION(Throw); |
| 6195 | |
| 6196 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6197 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6198 | }; |
| 6199 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6200 | /** |
| 6201 | * Implementation strategies for the code generator of a HInstanceOf |
| 6202 | * or `HCheckCast`. |
| 6203 | */ |
| 6204 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6205 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6206 | kExactCheck, // Can do a single class compare. |
| 6207 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6208 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6209 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6210 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6211 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6212 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6213 | }; |
| 6214 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6215 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6216 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6217 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6218 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6219 | HInstanceOf(HInstruction* object, |
| 6220 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6221 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6222 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6223 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6224 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6225 | dex_pc) { |
| 6226 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6227 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6228 | SetRawInputAt(0, object); |
| 6229 | SetRawInputAt(1, constant); |
| 6230 | } |
| 6231 | |
| 6232 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6233 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6234 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6235 | return true; |
| 6236 | } |
| 6237 | |
| 6238 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6239 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6240 | } |
| 6241 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6242 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6243 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6244 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6245 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6246 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6247 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6248 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6249 | // Mips currently does runtime calls for any other checks. |
| 6250 | return check_kind != TypeCheckKind::kExactCheck; |
| 6251 | } |
| 6252 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6253 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6254 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6255 | } |
| 6256 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6257 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6258 | |
| 6259 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6260 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6261 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6262 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6263 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6264 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6265 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6266 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6267 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6268 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6269 | }; |
| 6270 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6271 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6272 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6273 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6274 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6275 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6276 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6277 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6278 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6279 | SetRawInputAt(0, input); |
| 6280 | } |
| 6281 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6282 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6283 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6284 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6285 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6286 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6287 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6288 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6289 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6290 | } |
| 6291 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6292 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6293 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6294 | DECLARE_INSTRUCTION(BoundType); |
| 6295 | |
| 6296 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6297 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6298 | // is false then CanBeNull() cannot be true). |
| 6299 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6300 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6301 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6302 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6303 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6304 | // 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] | 6305 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6306 | // It is used to bound the type in cases like: |
| 6307 | // if (x instanceof ClassX) { |
| 6308 | // // uper_bound_ will be ClassX |
| 6309 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6310 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6311 | |
| 6312 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6313 | }; |
| 6314 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6315 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6316 | public: |
| 6317 | HCheckCast(HInstruction* object, |
| 6318 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6319 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6320 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6321 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6322 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6323 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6324 | SetRawInputAt(0, object); |
| 6325 | SetRawInputAt(1, constant); |
| 6326 | } |
| 6327 | |
| 6328 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6329 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6330 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6331 | return true; |
| 6332 | } |
| 6333 | |
| 6334 | bool NeedsEnvironment() const OVERRIDE { |
| 6335 | // Instruction may throw a CheckCastError. |
| 6336 | return true; |
| 6337 | } |
| 6338 | |
| 6339 | bool CanThrow() const OVERRIDE { return true; } |
| 6340 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6341 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6342 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6343 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6344 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6345 | |
| 6346 | DECLARE_INSTRUCTION(CheckCast); |
| 6347 | |
| 6348 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6349 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6350 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6351 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6352 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6353 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6354 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6355 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6356 | |
| 6357 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6358 | }; |
| 6359 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6360 | /** |
| 6361 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6362 | * @details We define the combined barrier types that are actually required |
| 6363 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6364 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6365 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6366 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6367 | * The current recipe is as follows: |
| 6368 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6369 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6370 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6371 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6372 | * class has final fields. |
| 6373 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6374 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6375 | */ |
| 6376 | enum MemBarrierKind { |
| 6377 | kAnyStore, |
| 6378 | kLoadAny, |
| 6379 | kStoreStore, |
| 6380 | kAnyAny, |
| 6381 | kNTStoreStore, |
| 6382 | kLastBarrierKind = kNTStoreStore |
| 6383 | }; |
| 6384 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6385 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6386 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6387 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6388 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6389 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6390 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6391 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6392 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6393 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6394 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6395 | |
| 6396 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6397 | |
| 6398 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6399 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6400 | static constexpr size_t kFieldBarrierKindSize = |
| 6401 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6402 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6403 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6404 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6405 | "Too many packed fields."); |
| 6406 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6407 | |
| 6408 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6409 | }; |
| 6410 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6411 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6412 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6413 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6414 | kEnter, |
| 6415 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6416 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6417 | }; |
| 6418 | |
| 6419 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6420 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6421 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6422 | dex_pc) { |
| 6423 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6424 | SetRawInputAt(0, object); |
| 6425 | } |
| 6426 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6427 | // Instruction may go into runtime, so we need an environment. |
| 6428 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6429 | |
| 6430 | bool CanThrow() const OVERRIDE { |
| 6431 | // Verifier guarantees that monitor-exit cannot throw. |
| 6432 | // This is important because it allows the HGraphBuilder to remove |
| 6433 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6434 | return IsEnter(); |
| 6435 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6436 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6437 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6438 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6439 | |
| 6440 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6441 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6442 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6443 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6444 | static constexpr size_t kFieldOperationKindSize = |
| 6445 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6446 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6447 | kFieldOperationKind + kFieldOperationKindSize; |
| 6448 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6449 | "Too many packed fields."); |
| 6450 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6451 | |
| 6452 | private: |
| 6453 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6454 | }; |
| 6455 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6456 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6457 | public: |
| 6458 | HSelect(HInstruction* condition, |
| 6459 | HInstruction* true_value, |
| 6460 | HInstruction* false_value, |
| 6461 | uint32_t dex_pc) |
| 6462 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6463 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6464 | |
| 6465 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6466 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6467 | // that architectures which implement HSelect as a conditional move also |
| 6468 | // will not need to invert the condition. |
| 6469 | SetRawInputAt(0, false_value); |
| 6470 | SetRawInputAt(1, true_value); |
| 6471 | SetRawInputAt(2, condition); |
| 6472 | } |
| 6473 | |
| 6474 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6475 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6476 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6477 | |
| 6478 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6479 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6480 | return true; |
| 6481 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6482 | |
| 6483 | bool CanBeNull() const OVERRIDE { |
| 6484 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6485 | } |
| 6486 | |
| 6487 | DECLARE_INSTRUCTION(Select); |
| 6488 | |
| 6489 | private: |
| 6490 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6491 | }; |
| 6492 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6493 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6494 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6495 | MoveOperands(Location source, |
| 6496 | Location destination, |
| 6497 | Primitive::Type type, |
| 6498 | HInstruction* instruction) |
| 6499 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6500 | |
| 6501 | Location GetSource() const { return source_; } |
| 6502 | Location GetDestination() const { return destination_; } |
| 6503 | |
| 6504 | void SetSource(Location value) { source_ = value; } |
| 6505 | void SetDestination(Location value) { destination_ = value; } |
| 6506 | |
| 6507 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6508 | // destination (but not the source). |
| 6509 | Location MarkPending() { |
| 6510 | DCHECK(!IsPending()); |
| 6511 | Location dest = destination_; |
| 6512 | destination_ = Location::NoLocation(); |
| 6513 | return dest; |
| 6514 | } |
| 6515 | |
| 6516 | void ClearPending(Location dest) { |
| 6517 | DCHECK(IsPending()); |
| 6518 | destination_ = dest; |
| 6519 | } |
| 6520 | |
| 6521 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6522 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6523 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6524 | } |
| 6525 | |
| 6526 | // True if this blocks a move from the given location. |
| 6527 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6528 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6529 | } |
| 6530 | |
| 6531 | // A move is redundant if it's been eliminated, if its source and |
| 6532 | // destination are the same, or if its destination is unneeded. |
| 6533 | bool IsRedundant() const { |
| 6534 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6535 | } |
| 6536 | |
| 6537 | // We clear both operands to indicate move that's been eliminated. |
| 6538 | void Eliminate() { |
| 6539 | source_ = destination_ = Location::NoLocation(); |
| 6540 | } |
| 6541 | |
| 6542 | bool IsEliminated() const { |
| 6543 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6544 | return source_.IsInvalid(); |
| 6545 | } |
| 6546 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6547 | Primitive::Type GetType() const { return type_; } |
| 6548 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6549 | bool Is64BitMove() const { |
| 6550 | return Primitive::Is64BitType(type_); |
| 6551 | } |
| 6552 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6553 | HInstruction* GetInstruction() const { return instruction_; } |
| 6554 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6555 | private: |
| 6556 | Location source_; |
| 6557 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6558 | // The type this move is for. |
| 6559 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6560 | // The instruction this move is assocatied with. Null when this move is |
| 6561 | // for moving an input in the expected locations of user (including a phi user). |
| 6562 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6563 | // in the same parallel move. |
| 6564 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6565 | }; |
| 6566 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6567 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6568 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6569 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6570 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6571 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6572 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6573 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6574 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6575 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6576 | moves_.reserve(kDefaultNumberOfMoves); |
| 6577 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6578 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6579 | void AddMove(Location source, |
| 6580 | Location destination, |
| 6581 | Primitive::Type type, |
| 6582 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6583 | DCHECK(source.IsValid()); |
| 6584 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6585 | if (kIsDebugBuild) { |
| 6586 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6587 | for (const MoveOperands& move : moves_) { |
| 6588 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6589 | // Special case the situation where the move is for the spill slot |
| 6590 | // of the instruction. |
| 6591 | if ((GetPrevious() == instruction) |
| 6592 | || ((GetPrevious() == nullptr) |
| 6593 | && instruction->IsPhi() |
| 6594 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6595 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6596 | << "Doing parallel moves for the same instruction."; |
| 6597 | } else { |
| 6598 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6599 | } |
| 6600 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6601 | } |
| 6602 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6603 | for (const MoveOperands& move : moves_) { |
| 6604 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6605 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6606 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6607 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6608 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6609 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6610 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6611 | } |
| 6612 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6613 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6614 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6615 | } |
| 6616 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6617 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6618 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6619 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6620 | |
| 6621 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6622 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6623 | |
| 6624 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6625 | }; |
| 6626 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6627 | } // namespace art |
| 6628 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6629 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6630 | #include "nodes_shared.h" |
| 6631 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6632 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6633 | #include "nodes_arm.h" |
| 6634 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6635 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6636 | #include "nodes_arm64.h" |
| 6637 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6638 | #ifdef ART_ENABLE_CODEGEN_mips |
| 6639 | #include "nodes_mips.h" |
| 6640 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6641 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6642 | #include "nodes_x86.h" |
| 6643 | #endif |
| 6644 | |
| 6645 | namespace art { |
| 6646 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6647 | class HGraphVisitor : public ValueObject { |
| 6648 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6649 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6650 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6651 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6652 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6653 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6654 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6655 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6656 | void VisitInsertionOrder(); |
| 6657 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6658 | // Visit the graph following dominator tree reverse post-order. |
| 6659 | void VisitReversePostOrder(); |
| 6660 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6661 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6662 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6663 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6664 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6665 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6666 | |
| 6667 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6668 | |
| 6669 | #undef DECLARE_VISIT_INSTRUCTION |
| 6670 | |
| 6671 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6672 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6673 | |
| 6674 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6675 | }; |
| 6676 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6677 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6678 | public: |
| 6679 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6680 | virtual ~HGraphDelegateVisitor() {} |
| 6681 | |
| 6682 | // Visit functions that delegate to to super class. |
| 6683 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6684 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6685 | |
| 6686 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6687 | |
| 6688 | #undef DECLARE_VISIT_INSTRUCTION |
| 6689 | |
| 6690 | private: |
| 6691 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6692 | }; |
| 6693 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6694 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6695 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6696 | // block id. |
| 6697 | class HBlocksInLoopIterator : public ValueObject { |
| 6698 | public: |
| 6699 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6700 | : blocks_in_loop_(info.GetBlocks()), |
| 6701 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6702 | index_(0) { |
| 6703 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6704 | Advance(); |
| 6705 | } |
| 6706 | } |
| 6707 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6708 | bool Done() const { return index_ == blocks_.size(); } |
| 6709 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6710 | void Advance() { |
| 6711 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6712 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6713 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6714 | break; |
| 6715 | } |
| 6716 | } |
| 6717 | } |
| 6718 | |
| 6719 | private: |
| 6720 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6721 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6722 | size_t index_; |
| 6723 | |
| 6724 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6725 | }; |
| 6726 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6727 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6728 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6729 | // post order. |
| 6730 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6731 | public: |
| 6732 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6733 | : blocks_in_loop_(info.GetBlocks()), |
| 6734 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6735 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6736 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6737 | Advance(); |
| 6738 | } |
| 6739 | } |
| 6740 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6741 | bool Done() const { return index_ == blocks_.size(); } |
| 6742 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6743 | void Advance() { |
| 6744 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6745 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6746 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6747 | break; |
| 6748 | } |
| 6749 | } |
| 6750 | } |
| 6751 | |
| 6752 | private: |
| 6753 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6754 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6755 | size_t index_; |
| 6756 | |
| 6757 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6758 | }; |
| 6759 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6760 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6761 | if (constant->IsIntConstant()) { |
| 6762 | return constant->AsIntConstant()->GetValue(); |
| 6763 | } else if (constant->IsLongConstant()) { |
| 6764 | return constant->AsLongConstant()->GetValue(); |
| 6765 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6766 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6767 | return 0; |
| 6768 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6769 | } |
| 6770 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6771 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6772 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6773 | inline const H##type* HInstruction::As##type() const { \ |
| 6774 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6775 | } \ |
| 6776 | inline H##type* HInstruction::As##type() { \ |
| 6777 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6778 | } |
| 6779 | |
| 6780 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6781 | #undef INSTRUCTION_TYPE_CHECK |
| 6782 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6783 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6784 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6785 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6786 | size_t number_of_new_blocks, |
| 6787 | size_t after) { |
| 6788 | DCHECK_LT(after, blocks->size()); |
| 6789 | size_t old_size = blocks->size(); |
| 6790 | size_t new_size = old_size + number_of_new_blocks; |
| 6791 | blocks->resize(new_size); |
| 6792 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 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_ |