Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_NODES_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_NODES_H_ |
| 19 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 20 | #include <algorithm> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 21 | #include <array> |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 22 | #include <type_traits> |
| 23 | |
Mathieu Chartier | e5d80f8 | 2015-10-15 17:47:48 -0700 | [diff] [blame] | 24 | #include "base/arena_bit_vector.h" |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 25 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 26 | #include "base/arena_object.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 27 | #include "base/array_ref.h" |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 28 | #include "base/iteration_range.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 29 | #include "base/stl_util.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 30 | #include "base/transform_array_ref.h" |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 31 | #include "dex_file.h" |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 32 | #include "dex_file_types.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 33 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 34 | #include "handle.h" |
| 35 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 36 | #include "invoke_type.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 37 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 38 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 39 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 40 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 41 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 42 | #include "primitive.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 43 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 44 | |
| 45 | namespace art { |
| 46 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 47 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 48 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 49 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 50 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 51 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 52 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 53 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 54 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 55 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 56 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 57 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 58 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 59 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 60 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 61 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 62 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 63 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 64 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 65 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 66 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 67 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 68 | namespace mirror { |
| 69 | class DexCache; |
| 70 | } // namespace mirror |
| 71 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 72 | static const int kDefaultNumberOfBlocks = 8; |
| 73 | static const int kDefaultNumberOfSuccessors = 2; |
| 74 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 75 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 76 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 77 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 78 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 79 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 80 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 81 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 82 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 83 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 84 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 85 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 86 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 87 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 88 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 89 | static constexpr uint32_t kNoDexPc = -1; |
| 90 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 91 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 92 | // For the purposes of the compiler, the dex files must actually be the same object |
| 93 | // if we want to safely treat them as the same. This is especially important for JIT |
| 94 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 95 | // times and provide different class resolution but no two class loaders should ever |
| 96 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 97 | // all sorts of weird failures. |
| 98 | return &lhs == &rhs; |
| 99 | } |
| 100 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 101 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 102 | // All types. |
| 103 | kCondEQ, // == |
| 104 | kCondNE, // != |
| 105 | // Signed integers and floating-point numbers. |
| 106 | kCondLT, // < |
| 107 | kCondLE, // <= |
| 108 | kCondGT, // > |
| 109 | kCondGE, // >= |
| 110 | // Unsigned integers. |
| 111 | kCondB, // < |
| 112 | kCondBE, // <= |
| 113 | kCondA, // > |
| 114 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 115 | // First and last aliases. |
| 116 | kCondFirst = kCondEQ, |
| 117 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 120 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 121 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 122 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 123 | kAnalysisFailThrowCatchLoop, |
| 124 | kAnalysisFailAmbiguousArrayOp, |
| 125 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 128 | template <typename T> |
| 129 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 130 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 131 | } |
| 132 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 133 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 134 | public: |
| 135 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 136 | |
| 137 | void AddInstruction(HInstruction* instruction); |
| 138 | void RemoveInstruction(HInstruction* instruction); |
| 139 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 140 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 141 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 142 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 143 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 144 | // Return true if this list contains `instruction`. |
| 145 | bool Contains(HInstruction* instruction) const; |
| 146 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 147 | // Return true if `instruction1` is found before `instruction2` in |
| 148 | // this instruction list and false otherwise. Abort if none |
| 149 | // of these instructions is found. |
| 150 | bool FoundBefore(const HInstruction* instruction1, |
| 151 | const HInstruction* instruction2) const; |
| 152 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 153 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 154 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 155 | |
| 156 | // Update the block of all instructions to be `block`. |
| 157 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 158 | |
| 159 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 160 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 161 | void Add(const HInstructionList& instruction_list); |
| 162 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 163 | // Return the number of instructions in the list. This is an expensive operation. |
| 164 | size_t CountSize() const; |
| 165 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 166 | private: |
| 167 | HInstruction* first_instruction_; |
| 168 | HInstruction* last_instruction_; |
| 169 | |
| 170 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 171 | friend class HGraph; |
| 172 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 173 | friend class HInstructionIterator; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 174 | friend class HInstructionIteratorHandleChanges; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 175 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 176 | |
| 177 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 178 | }; |
| 179 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 180 | class ReferenceTypeInfo : ValueObject { |
| 181 | public: |
| 182 | typedef Handle<mirror::Class> TypeHandle; |
| 183 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 184 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 185 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 186 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 187 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 188 | } |
| 189 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 190 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 191 | return ReferenceTypeInfo(type_handle, is_exact); |
| 192 | } |
| 193 | |
| 194 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 195 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 196 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 197 | return handle.GetReference() != nullptr; |
| 198 | } |
| 199 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 200 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 201 | return IsValidHandle(type_handle_); |
| 202 | } |
| 203 | |
| 204 | bool IsExact() const { return is_exact_; } |
| 205 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 206 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 207 | DCHECK(IsValid()); |
| 208 | return GetTypeHandle()->IsObjectClass(); |
| 209 | } |
| 210 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 211 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 212 | DCHECK(IsValid()); |
| 213 | return GetTypeHandle()->IsStringClass(); |
| 214 | } |
| 215 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 216 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 217 | DCHECK(IsValid()); |
| 218 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 219 | } |
| 220 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 221 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 222 | DCHECK(IsValid()); |
| 223 | return GetTypeHandle()->IsInterface(); |
| 224 | } |
| 225 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 226 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 227 | DCHECK(IsValid()); |
| 228 | return GetTypeHandle()->IsArrayClass(); |
| 229 | } |
| 230 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 231 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 232 | DCHECK(IsValid()); |
| 233 | return GetTypeHandle()->IsPrimitiveArray(); |
| 234 | } |
| 235 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 236 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 237 | DCHECK(IsValid()); |
| 238 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 239 | } |
| 240 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 241 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 242 | DCHECK(IsValid()); |
| 243 | if (!IsExact()) return false; |
| 244 | if (!IsArrayClass()) return false; |
| 245 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 246 | } |
| 247 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 248 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 249 | DCHECK(IsValid()); |
| 250 | if (!IsExact()) return false; |
| 251 | if (!IsArrayClass()) return false; |
| 252 | if (!rti.IsArrayClass()) return false; |
| 253 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 254 | rti.GetTypeHandle()->GetComponentType()); |
| 255 | } |
| 256 | |
| 257 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 258 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 259 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 260 | DCHECK(IsValid()); |
| 261 | DCHECK(rti.IsValid()); |
| 262 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 263 | } |
| 264 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 265 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 266 | DCHECK(IsValid()); |
| 267 | DCHECK(rti.IsValid()); |
| 268 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 269 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 270 | } |
| 271 | |
| 272 | // Returns true if the type information provide the same amount of details. |
| 273 | // Note that it does not mean that the instructions have the same actual type |
| 274 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 275 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 276 | if (!IsValid() && !rti.IsValid()) { |
| 277 | // Invalid types are equal. |
| 278 | return true; |
| 279 | } |
| 280 | if (!IsValid() || !rti.IsValid()) { |
| 281 | // One is valid, the other not. |
| 282 | return false; |
| 283 | } |
| 284 | return IsExact() == rti.IsExact() |
| 285 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 286 | } |
| 287 | |
| 288 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 289 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 290 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 291 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 292 | |
| 293 | // The class of the object. |
| 294 | TypeHandle type_handle_; |
| 295 | // Whether or not the type is exact or a superclass of the actual type. |
| 296 | // Whether or not we have any information about this type. |
| 297 | bool is_exact_; |
| 298 | }; |
| 299 | |
| 300 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 301 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 302 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 303 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 304 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 305 | HGraph(ArenaAllocator* arena, |
| 306 | const DexFile& dex_file, |
| 307 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 308 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 309 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 310 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 311 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 312 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 313 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 314 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 315 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 316 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 317 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 318 | entry_block_(nullptr), |
| 319 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 320 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 321 | number_of_vregs_(0), |
| 322 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 323 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 324 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 325 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 326 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 327 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 328 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 329 | dex_file_(dex_file), |
| 330 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 331 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 332 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 333 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 334 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 335 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 336 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 337 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 338 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 339 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 340 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 341 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 342 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 343 | osr_(osr), |
| 344 | cha_single_implementation_list_(arena->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 345 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 346 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 347 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 348 | // 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] | 349 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 350 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 351 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 352 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 353 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 354 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 355 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 356 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 357 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 358 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 359 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 360 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 361 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 362 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 363 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 364 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 365 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 366 | void ComputeDominanceInformation(); |
| 367 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 368 | void ClearLoopInformation(); |
| 369 | void FindBackEdges(ArenaBitVector* visited); |
| 370 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 371 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 372 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 373 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 374 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 375 | // 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] | 376 | // 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] | 377 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 378 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 379 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 380 | // order and loop information. |
| 381 | void ComputeTryBlockInformation(); |
| 382 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 383 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 384 | // Returns the instruction to replace the invoke expression or null if the |
| 385 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 386 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 387 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 388 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 389 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 390 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 391 | // should be the new back edge. |
| 392 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 393 | HBasicBlock* reference, |
| 394 | bool replace_if_back_edge); |
| 395 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 396 | // Need to add a couple of blocks to test if the loop body is entered and |
| 397 | // put deoptimization instructions, etc. |
| 398 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 399 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 400 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 401 | // other blocks and has no instructions or phis. |
| 402 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 403 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 404 | // Splits the edge between `block` and `successor` while preserving the |
| 405 | // indices in the predecessor/successor lists. If there are multiple edges |
| 406 | // between the blocks, the lowest indices are used. |
| 407 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 408 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 409 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 410 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 411 | void SimplifyLoop(HBasicBlock* header); |
| 412 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 413 | int32_t GetNextInstructionId() { |
| 414 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 415 | return current_instruction_id_++; |
| 416 | } |
| 417 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 418 | int32_t GetCurrentInstructionId() const { |
| 419 | return current_instruction_id_; |
| 420 | } |
| 421 | |
| 422 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 423 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 424 | current_instruction_id_ = id; |
| 425 | } |
| 426 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 427 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 428 | return maximum_number_of_out_vregs_; |
| 429 | } |
| 430 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 431 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 432 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 433 | } |
| 434 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 435 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 436 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 437 | } |
| 438 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 439 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 440 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 441 | } |
| 442 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 443 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 444 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 445 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 446 | } |
| 447 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 448 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 449 | number_of_vregs_ = number_of_vregs; |
| 450 | } |
| 451 | |
| 452 | uint16_t GetNumberOfVRegs() const { |
| 453 | return number_of_vregs_; |
| 454 | } |
| 455 | |
| 456 | void SetNumberOfInVRegs(uint16_t value) { |
| 457 | number_of_in_vregs_ = value; |
| 458 | } |
| 459 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 460 | uint16_t GetNumberOfInVRegs() const { |
| 461 | return number_of_in_vregs_; |
| 462 | } |
| 463 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 464 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 465 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 466 | return number_of_vregs_ - number_of_in_vregs_; |
| 467 | } |
| 468 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 469 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 470 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 471 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 472 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 473 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 474 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 475 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 476 | } |
| 477 | |
| 478 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 479 | return ReverseRange(GetReversePostOrder()); |
| 480 | } |
| 481 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 482 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 483 | return linear_order_; |
| 484 | } |
| 485 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 486 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 487 | return ReverseRange(GetLinearOrder()); |
| 488 | } |
| 489 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 490 | bool HasBoundsChecks() const { |
| 491 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 492 | } |
| 493 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 494 | void SetHasBoundsChecks(bool value) { |
| 495 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 496 | } |
| 497 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 498 | bool ShouldGenerateConstructorBarrier() const { |
| 499 | return should_generate_constructor_barrier_; |
| 500 | } |
| 501 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 502 | bool IsDebuggable() const { return debuggable_; } |
| 503 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 504 | // 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] | 505 | // already, it is created and inserted into the graph. This method is only for |
| 506 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 507 | 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] | 508 | |
| 509 | // TODO: This is problematic for the consistency of reference type propagation |
| 510 | // because it can be created anytime after the pass and thus it will be left |
| 511 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 512 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 513 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 514 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 515 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 516 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 517 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 518 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 519 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 520 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 521 | 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] | 522 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 523 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 524 | 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] | 525 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 526 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 527 | HCurrentMethod* GetCurrentMethod(); |
| 528 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 529 | const DexFile& GetDexFile() const { |
| 530 | return dex_file_; |
| 531 | } |
| 532 | |
| 533 | uint32_t GetMethodIdx() const { |
| 534 | return method_idx_; |
| 535 | } |
| 536 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 537 | InvokeType GetInvokeType() const { |
| 538 | return invoke_type_; |
| 539 | } |
| 540 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 541 | InstructionSet GetInstructionSet() const { |
| 542 | return instruction_set_; |
| 543 | } |
| 544 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 545 | bool IsCompilingOsr() const { return osr_; } |
| 546 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 547 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 548 | return cha_single_implementation_list_; |
| 549 | } |
| 550 | |
| 551 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 552 | cha_single_implementation_list_.insert(method); |
| 553 | } |
| 554 | |
| 555 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 556 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 557 | } |
| 558 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 559 | bool HasTryCatch() const { return has_try_catch_; } |
| 560 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 561 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 562 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 563 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 564 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 565 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 566 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 567 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 568 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 569 | // The instruction has been inserted into the graph, either as a constant, or |
| 570 | // before cursor. |
| 571 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 572 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 573 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 574 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 575 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 576 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 577 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 578 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 579 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 580 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 581 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 582 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 583 | template <class InstructionType, typename ValueType> |
| 584 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 585 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 586 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 587 | // Try to find an existing constant of the given value. |
| 588 | InstructionType* constant = nullptr; |
| 589 | auto cached_constant = cache->find(value); |
| 590 | if (cached_constant != cache->end()) { |
| 591 | constant = cached_constant->second; |
| 592 | } |
| 593 | |
| 594 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 595 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 596 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 597 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 598 | cache->Overwrite(value, constant); |
| 599 | InsertConstant(constant); |
| 600 | } |
| 601 | return constant; |
| 602 | } |
| 603 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 604 | void InsertConstant(HConstant* instruction); |
| 605 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 606 | // Cache a float constant into the graph. This method should only be |
| 607 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 608 | void CacheFloatConstant(HFloatConstant* constant); |
| 609 | |
| 610 | // See CacheFloatConstant comment. |
| 611 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 612 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 613 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 614 | |
| 615 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 616 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 617 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 618 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 619 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 620 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 621 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 622 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 623 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 624 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 625 | HBasicBlock* entry_block_; |
| 626 | HBasicBlock* exit_block_; |
| 627 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 628 | // 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] | 629 | uint16_t maximum_number_of_out_vregs_; |
| 630 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 631 | // The number of virtual registers in this method. Contains the parameters. |
| 632 | uint16_t number_of_vregs_; |
| 633 | |
| 634 | // The number of virtual registers used by parameters of this method. |
| 635 | uint16_t number_of_in_vregs_; |
| 636 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 637 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 638 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 639 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 640 | // Has bounds checks. We can totally skip BCE if it's false. |
| 641 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 642 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 643 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 644 | // try/catch-related passes if false. |
| 645 | bool has_try_catch_; |
| 646 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 647 | // Flag whether there are any irreducible loops in the graph. |
| 648 | bool has_irreducible_loops_; |
| 649 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 650 | // Indicates whether the graph should be compiled in a way that |
| 651 | // ensures full debuggability. If false, we can apply more |
| 652 | // aggressive optimizations that may limit the level of debugging. |
| 653 | const bool debuggable_; |
| 654 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 655 | // 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] | 656 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 657 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 658 | // The dex file from which the method is from. |
| 659 | const DexFile& dex_file_; |
| 660 | |
| 661 | // The method index in the dex file. |
| 662 | const uint32_t method_idx_; |
| 663 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 664 | // If inlined, this encodes how the callee is being invoked. |
| 665 | const InvokeType invoke_type_; |
| 666 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 667 | // Whether the graph has been transformed to SSA form. Only used |
| 668 | // in debug mode to ensure we are not using properties only valid |
| 669 | // for non-SSA form (like the number of temporaries). |
| 670 | bool in_ssa_form_; |
| 671 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 672 | const bool should_generate_constructor_barrier_; |
| 673 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 674 | // Number of CHA guards in the graph. Used to short-circuit the |
| 675 | // CHA guard optimization pass when there is no CHA guard left. |
| 676 | uint32_t number_of_cha_guards_; |
| 677 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 678 | const InstructionSet instruction_set_; |
| 679 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 680 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 681 | HNullConstant* cached_null_constant_; |
| 682 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 683 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 684 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 685 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 686 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 687 | HCurrentMethod* cached_current_method_; |
| 688 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 689 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 690 | // for example for methods whose declaring class could not be resolved |
| 691 | // (such as when the superclass could not be found). |
| 692 | ArtMethod* art_method_; |
| 693 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 694 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 695 | // collection pointer to passes which may create NullConstant. |
| 696 | ReferenceTypeInfo inexact_object_rti_; |
| 697 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 698 | // Whether we are compiling this graph for on stack replacement: this will |
| 699 | // make all loops seen as irreducible and emit special stack maps to mark |
| 700 | // compiled code entries which the interpreter can directly jump to. |
| 701 | const bool osr_; |
| 702 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 703 | // List of methods that are assumed to have single implementation. |
| 704 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 705 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 706 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 707 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 708 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 709 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 710 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 711 | }; |
| 712 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 713 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 714 | public: |
| 715 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 716 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 717 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 718 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 719 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 720 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 721 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 722 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 723 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 724 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 725 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 726 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 727 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 728 | |
| 729 | void Dump(std::ostream& os); |
| 730 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 731 | HBasicBlock* GetHeader() const { |
| 732 | return header_; |
| 733 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 734 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 735 | void SetHeader(HBasicBlock* block) { |
| 736 | header_ = block; |
| 737 | } |
| 738 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 739 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 740 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 741 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 742 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 743 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 744 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 745 | } |
| 746 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 747 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 748 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 749 | } |
| 750 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 751 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 752 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 753 | } |
| 754 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 755 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 756 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 757 | } |
| 758 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 759 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 760 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 761 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 762 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 763 | } |
| 764 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 765 | // Returns the lifetime position of the back edge that has the |
| 766 | // greatest lifetime position. |
| 767 | size_t GetLifetimeEnd() const; |
| 768 | |
| 769 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 770 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 771 | } |
| 772 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 773 | // Finds blocks that are part of this loop. |
| 774 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 775 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 776 | // Returns whether this loop information contains `block`. |
| 777 | // Note that this loop information *must* be populated before entering this function. |
| 778 | bool Contains(const HBasicBlock& block) const; |
| 779 | |
| 780 | // Returns whether this loop information is an inner loop of `other`. |
| 781 | // Note that `other` *must* be populated before entering this function. |
| 782 | bool IsIn(const HLoopInformation& other) const; |
| 783 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 784 | // Returns true if instruction is not defined within this loop. |
| 785 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 786 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 787 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 788 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 789 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 790 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 791 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 792 | void ClearAllBlocks() { |
| 793 | blocks_.ClearAllBits(); |
| 794 | } |
| 795 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 796 | bool HasBackEdgeNotDominatedByHeader() const; |
| 797 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 798 | bool IsPopulated() const { |
| 799 | return blocks_.GetHighestBitSet() != -1; |
| 800 | } |
| 801 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 802 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 803 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 804 | bool HasExitEdge() const; |
| 805 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 806 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 807 | // Internal recursive implementation of `Populate`. |
| 808 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 809 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 810 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 811 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 812 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 813 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 814 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 815 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 816 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 817 | |
| 818 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 819 | }; |
| 820 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 821 | // Stores try/catch information for basic blocks. |
| 822 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 823 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 824 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 825 | public: |
| 826 | // Try block information constructor. |
| 827 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 828 | : try_entry_(&try_entry), |
| 829 | catch_dex_file_(nullptr), |
| 830 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 831 | DCHECK(try_entry_ != nullptr); |
| 832 | } |
| 833 | |
| 834 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 835 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 836 | : try_entry_(nullptr), |
| 837 | catch_dex_file_(&dex_file), |
| 838 | catch_type_index_(catch_type_index) {} |
| 839 | |
| 840 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 841 | |
| 842 | const HTryBoundary& GetTryEntry() const { |
| 843 | DCHECK(IsTryBlock()); |
| 844 | return *try_entry_; |
| 845 | } |
| 846 | |
| 847 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 848 | |
| 849 | bool IsCatchAllTypeIndex() const { |
| 850 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 851 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 852 | } |
| 853 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 854 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 855 | DCHECK(IsCatchBlock()); |
| 856 | return catch_type_index_; |
| 857 | } |
| 858 | |
| 859 | const DexFile& GetCatchDexFile() const { |
| 860 | DCHECK(IsCatchBlock()); |
| 861 | return *catch_dex_file_; |
| 862 | } |
| 863 | |
| 864 | private: |
| 865 | // One of possibly several TryBoundary instructions entering the block's try. |
| 866 | // Only set for try blocks. |
| 867 | const HTryBoundary* try_entry_; |
| 868 | |
| 869 | // Exception type information. Only set for catch blocks. |
| 870 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 871 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 872 | }; |
| 873 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 874 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 875 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 876 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 877 | // A block in a method. Contains the list of instructions represented |
| 878 | // as a double linked list. Each block knows its predecessors and |
| 879 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 880 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 881 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 882 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 883 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 884 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 885 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 886 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 887 | loop_information_(nullptr), |
| 888 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 889 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 890 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 891 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 892 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 893 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 894 | try_catch_information_(nullptr) { |
| 895 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 896 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 897 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 898 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 899 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 900 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 901 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 904 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 905 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 906 | } |
| 907 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 908 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 909 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 910 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 911 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 912 | return ContainsElement(successors_, block, start_from); |
| 913 | } |
| 914 | |
| 915 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 916 | return dominated_blocks_; |
| 917 | } |
| 918 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 919 | bool IsEntryBlock() const { |
| 920 | return graph_->GetEntryBlock() == this; |
| 921 | } |
| 922 | |
| 923 | bool IsExitBlock() const { |
| 924 | return graph_->GetExitBlock() == this; |
| 925 | } |
| 926 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 927 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 928 | bool IsSingleTryBoundary() const; |
| 929 | |
| 930 | // Returns true if this block emits nothing but a jump. |
| 931 | bool IsSingleJump() const { |
| 932 | HLoopInformation* loop_info = GetLoopInformation(); |
| 933 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 934 | // Back edges generate a suspend check. |
| 935 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 936 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 937 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 938 | void AddBackEdge(HBasicBlock* back_edge) { |
| 939 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 940 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 941 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 942 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 943 | loop_information_->AddBackEdge(back_edge); |
| 944 | } |
| 945 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 946 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 947 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 948 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 949 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 950 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 951 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 952 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 953 | HBasicBlock* GetDominator() const { return dominator_; } |
| 954 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 955 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 956 | |
| 957 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 958 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 959 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 960 | |
| 961 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 962 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 963 | } |
| 964 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 965 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 966 | |
| 967 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 968 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 971 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 972 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 973 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 974 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 975 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 976 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 977 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 978 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 979 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 980 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 981 | successors_.push_back(block); |
| 982 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 983 | } |
| 984 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 985 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 986 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 987 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 988 | new_block->predecessors_.push_back(this); |
| 989 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 992 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 993 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 994 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 995 | new_block->successors_.push_back(this); |
| 996 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 999 | // Insert `this` between `predecessor` and `successor. This method |
| 1000 | // preserves the indicies, and will update the first edge found between |
| 1001 | // `predecessor` and `successor`. |
| 1002 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1003 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1004 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1005 | successor->predecessors_[predecessor_index] = this; |
| 1006 | predecessor->successors_[successor_index] = this; |
| 1007 | successors_.push_back(successor); |
| 1008 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1009 | } |
| 1010 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1011 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1012 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1015 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1016 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1019 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1020 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1024 | predecessors_.push_back(block); |
| 1025 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1026 | } |
| 1027 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1028 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1029 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1030 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1033 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1034 | DCHECK_EQ(successors_.size(), 2u); |
| 1035 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1036 | } |
| 1037 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1038 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1039 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1040 | } |
| 1041 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1042 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1043 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1046 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1047 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1048 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1052 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1053 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1057 | // predecessors is at index `idx`. |
| 1058 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1059 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1060 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1061 | } |
| 1062 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1063 | // Create a new block between this block and its predecessors. The new block |
| 1064 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1065 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1066 | // loop and try/catch information are not updated. |
| 1067 | HBasicBlock* CreateImmediateDominator(); |
| 1068 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1069 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1070 | // created, latter block. Note that this method will add the block to the |
| 1071 | // graph, create a Goto at the end of the former block and will create an edge |
| 1072 | // 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] | 1073 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1074 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1075 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1076 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1077 | // created block. Note that this method just updates raw block information, |
| 1078 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1079 | // update the graph, reverse post order, loop information, nor make sure the |
| 1080 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1081 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1082 | |
| 1083 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1084 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1085 | |
| 1086 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1087 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1088 | // that this method does not update the graph, reverse post order, loop |
| 1089 | // information, nor make sure the blocks are consistent (for example ending |
| 1090 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1091 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1092 | |
| 1093 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1094 | // of `this` are moved to `other`. |
| 1095 | // Note that this method does not update the graph, reverse post order, loop |
| 1096 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1097 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1098 | void ReplaceWith(HBasicBlock* other); |
| 1099 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1100 | // Merges the instructions of `other` at the end of `this`. |
| 1101 | void MergeInstructionsWith(HBasicBlock* other); |
| 1102 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1103 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1104 | // order, links to predecessors, successors, dominators and deletes the block |
| 1105 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1106 | // predecessor of `other` and vice versa. |
| 1107 | void MergeWith(HBasicBlock* other); |
| 1108 | |
| 1109 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1110 | // removes it from all loops it is included in and eventually from the graph. |
| 1111 | // The block must not dominate any other block. Predecessors and successors |
| 1112 | // are safely updated. |
| 1113 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1114 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1115 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1116 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1117 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1118 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1119 | // Replace instruction `initial` with `replacement` within this block. |
| 1120 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1121 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1122 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1123 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1124 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1125 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1126 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1127 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1128 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1129 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1130 | |
| 1131 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1132 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1133 | } |
| 1134 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1135 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1136 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1137 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1138 | } |
| 1139 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1140 | bool IsFirstPredecessorBackEdge() const { |
| 1141 | DCHECK(IsLoopHeader()); |
| 1142 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1143 | } |
| 1144 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1145 | HLoopInformation* GetLoopInformation() const { |
| 1146 | return loop_information_; |
| 1147 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1148 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1149 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1150 | // 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] | 1151 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1152 | void SetInLoop(HLoopInformation* info) { |
| 1153 | if (IsLoopHeader()) { |
| 1154 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1155 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1156 | loop_information_ = info; |
| 1157 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1158 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1159 | // Note that a non loop header having a loop information means this loop information |
| 1160 | // has already been populated |
| 1161 | loop_information_ = info; |
| 1162 | } else { |
| 1163 | // Block is part of an inner loop. Do not update the loop information. |
| 1164 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1165 | // at this point, because this method is being called while populating `info`. |
| 1166 | } |
| 1167 | } |
| 1168 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1169 | // Raw update of the loop information. |
| 1170 | void SetLoopInformation(HLoopInformation* info) { |
| 1171 | loop_information_ = info; |
| 1172 | } |
| 1173 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1174 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1175 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1176 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1177 | |
| 1178 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1179 | try_catch_information_ = try_catch_information; |
| 1180 | } |
| 1181 | |
| 1182 | bool IsTryBlock() const { |
| 1183 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1184 | } |
| 1185 | |
| 1186 | bool IsCatchBlock() const { |
| 1187 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1188 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1189 | |
| 1190 | // Returns the try entry that this block's successors should have. They will |
| 1191 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1192 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1193 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1194 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1195 | bool HasThrowingInstructions() const; |
| 1196 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1197 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1198 | bool Dominates(HBasicBlock* block) const; |
| 1199 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1200 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1201 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1202 | |
| 1203 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1204 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1205 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1206 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1207 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1208 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1209 | bool HasSinglePhi() const; |
| 1210 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1211 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1212 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1213 | ArenaVector<HBasicBlock*> predecessors_; |
| 1214 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1215 | HInstructionList instructions_; |
| 1216 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1217 | HLoopInformation* loop_information_; |
| 1218 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1219 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1220 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1221 | // The dex program counter of the first instruction of this block. |
| 1222 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1223 | size_t lifetime_start_; |
| 1224 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1225 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1226 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1227 | friend class HGraph; |
| 1228 | friend class HInstruction; |
| 1229 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1230 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1231 | }; |
| 1232 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1233 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1234 | // from the innermost to the outermost. |
| 1235 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1236 | public: |
| 1237 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1238 | : current_(block.GetLoopInformation()) {} |
| 1239 | |
| 1240 | bool Done() const { return current_ == nullptr; } |
| 1241 | |
| 1242 | void Advance() { |
| 1243 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1244 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | HLoopInformation* Current() const { |
| 1248 | DCHECK(!Done()); |
| 1249 | return current_; |
| 1250 | } |
| 1251 | |
| 1252 | private: |
| 1253 | HLoopInformation* current_; |
| 1254 | |
| 1255 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1256 | }; |
| 1257 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1258 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1259 | M(Above, Condition) \ |
| 1260 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1261 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1262 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1263 | M(ArrayGet, Instruction) \ |
| 1264 | M(ArrayLength, Instruction) \ |
| 1265 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1266 | M(Below, Condition) \ |
| 1267 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1268 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1269 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1270 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1271 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1272 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1273 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1274 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1275 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1276 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1277 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1278 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1279 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1280 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1281 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1282 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1283 | M(Exit, Instruction) \ |
| 1284 | M(FloatConstant, Constant) \ |
| 1285 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1286 | M(GreaterThan, Condition) \ |
| 1287 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1288 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1289 | M(InstanceFieldGet, Instruction) \ |
| 1290 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1291 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1292 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1293 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1294 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1295 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1296 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1297 | M(InvokePolymorphic, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1298 | M(LessThan, Condition) \ |
| 1299 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1300 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1301 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1302 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1303 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1304 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1305 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1306 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1307 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1308 | M(Neg, UnaryOperation) \ |
| 1309 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1310 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1311 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1312 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1313 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1314 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1315 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1316 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1317 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1318 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1319 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1320 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1321 | M(Return, Instruction) \ |
| 1322 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1323 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1324 | M(Shl, BinaryOperation) \ |
| 1325 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1326 | M(StaticFieldGet, Instruction) \ |
| 1327 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1328 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1329 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1330 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1331 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1332 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1333 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1334 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1335 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1336 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1337 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1338 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1339 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1340 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1341 | /* |
| 1342 | * Instructions, shared across several (not all) architectures. |
| 1343 | */ |
| 1344 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1345 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1346 | #else |
| 1347 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1348 | M(BitwiseNegatedRight, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1349 | M(MultiplyAccumulate, Instruction) \ |
| 1350 | M(IntermediateAddress, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1351 | #endif |
| 1352 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1353 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1354 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1355 | #else |
| 1356 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1357 | M(ArmDexCacheArraysBase, Instruction) |
| 1358 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1359 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1360 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1361 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1362 | #else |
| 1363 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1364 | M(Arm64DataProcWithShifterOp, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1365 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1366 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1367 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1368 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1369 | #else |
| 1370 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1371 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1372 | M(MipsDexCacheArraysBase, Instruction) \ |
| 1373 | M(MipsPackedSwitch, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1374 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1375 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1376 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1377 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1378 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1379 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1380 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1381 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1382 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1383 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1384 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1385 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1386 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1387 | |
| 1388 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1389 | |
| 1390 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1391 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1392 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1393 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1394 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1395 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1396 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1397 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1398 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1399 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1400 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1401 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1402 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1403 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1404 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1405 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1406 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1407 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1408 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1409 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1410 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1411 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1412 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1413 | #undef FORWARD_DECLARATION |
| 1414 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1415 | #define DECLARE_INSTRUCTION(type) \ |
| 1416 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1417 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1418 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1419 | return other->Is##type(); \ |
| 1420 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1421 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1422 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1423 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1424 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1425 | const H##type* As##type() const { return this; } \ |
| 1426 | H##type* As##type() { return this; } |
| 1427 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1428 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1429 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1430 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1431 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1432 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1433 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1434 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1435 | // Hook for the IntrusiveForwardList<>. |
| 1436 | // TODO: Hide this better. |
| 1437 | IntrusiveForwardListHook hook; |
| 1438 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1439 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1440 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1441 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1442 | |
| 1443 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1444 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1445 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1446 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1447 | |
| 1448 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1449 | }; |
| 1450 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1451 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1452 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1453 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1454 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1455 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1456 | // by the used instructions. |
| 1457 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1458 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1459 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1460 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1461 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1462 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1463 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1464 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1465 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1466 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1467 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1471 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1472 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1473 | |
| 1474 | private: |
| 1475 | // Instruction used by the user. |
| 1476 | HInstruction* instruction_; |
| 1477 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1478 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1479 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1480 | }; |
| 1481 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1482 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1483 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1484 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1485 | struct HInputExtractor { |
| 1486 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1487 | return record.GetInstruction(); |
| 1488 | } |
| 1489 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1490 | return record.GetInstruction(); |
| 1491 | } |
| 1492 | }; |
| 1493 | |
| 1494 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1495 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1496 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1497 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1498 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1499 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1500 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1501 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1502 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1503 | * modify the value of a reference field read [although it may modify the |
| 1504 | * reference fetch prior to reading the field, which is represented by its own |
| 1505 | * write/read dependence]). The analysis makes conservative points-to |
| 1506 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1507 | * the same, and any reference read depends on any reference read without |
| 1508 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1509 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1510 | * The internal representation uses 38-bit and is described in the table below. |
| 1511 | * The first line indicates the side effect, and for field/array accesses the |
| 1512 | * second line indicates the type of the access (in the order of the |
| 1513 | * Primitive::Type enum). |
| 1514 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1515 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1516 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1517 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1518 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1519 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1520 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1521 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1522 | * |
| 1523 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1524 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1525 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1526 | class SideEffects : public ValueObject { |
| 1527 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1528 | SideEffects() : flags_(0) {} |
| 1529 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1530 | static SideEffects None() { |
| 1531 | return SideEffects(0); |
| 1532 | } |
| 1533 | |
| 1534 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1535 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1536 | } |
| 1537 | |
| 1538 | static SideEffects AllChanges() { |
| 1539 | return SideEffects(kAllChangeBits); |
| 1540 | } |
| 1541 | |
| 1542 | static SideEffects AllDependencies() { |
| 1543 | return SideEffects(kAllDependOnBits); |
| 1544 | } |
| 1545 | |
| 1546 | static SideEffects AllExceptGCDependency() { |
| 1547 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1548 | } |
| 1549 | |
| 1550 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1551 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1552 | } |
| 1553 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1554 | static SideEffects AllWrites() { |
| 1555 | return SideEffects(kAllWrites); |
| 1556 | } |
| 1557 | |
| 1558 | static SideEffects AllReads() { |
| 1559 | return SideEffects(kAllReads); |
| 1560 | } |
| 1561 | |
| 1562 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1563 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1564 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1565 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1566 | } |
| 1567 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1568 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1569 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1570 | } |
| 1571 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1572 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1573 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1574 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1575 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1579 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1582 | static SideEffects CanTriggerGC() { |
| 1583 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1584 | } |
| 1585 | |
| 1586 | static SideEffects DependsOnGC() { |
| 1587 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1588 | } |
| 1589 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1590 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1591 | SideEffects Union(SideEffects other) const { |
| 1592 | return SideEffects(flags_ | other.flags_); |
| 1593 | } |
| 1594 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1595 | SideEffects Exclusion(SideEffects other) const { |
| 1596 | return SideEffects(flags_ & ~other.flags_); |
| 1597 | } |
| 1598 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1599 | void Add(SideEffects other) { |
| 1600 | flags_ |= other.flags_; |
| 1601 | } |
| 1602 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1603 | bool Includes(SideEffects other) const { |
| 1604 | return (other.flags_ & flags_) == other.flags_; |
| 1605 | } |
| 1606 | |
| 1607 | bool HasSideEffects() const { |
| 1608 | return (flags_ & kAllChangeBits); |
| 1609 | } |
| 1610 | |
| 1611 | bool HasDependencies() const { |
| 1612 | return (flags_ & kAllDependOnBits); |
| 1613 | } |
| 1614 | |
| 1615 | // Returns true if there are no side effects or dependencies. |
| 1616 | bool DoesNothing() const { |
| 1617 | return flags_ == 0; |
| 1618 | } |
| 1619 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1620 | // Returns true if something is written. |
| 1621 | bool DoesAnyWrite() const { |
| 1622 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1623 | } |
| 1624 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1625 | // Returns true if something is read. |
| 1626 | bool DoesAnyRead() const { |
| 1627 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1628 | } |
| 1629 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1630 | // Returns true if potentially everything is written and read |
| 1631 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1632 | bool DoesAllReadWrite() const { |
| 1633 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1634 | } |
| 1635 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1636 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1637 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1640 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1641 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1642 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1643 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1647 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1648 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1649 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1650 | for (int s = kLastBit; s >= 0; s--) { |
| 1651 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1652 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1653 | // This is a bit for the GC side effect. |
| 1654 | if (current_bit_is_set) { |
| 1655 | flags += "GC"; |
| 1656 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1657 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1658 | } else { |
| 1659 | // This is a bit for the array/field analysis. |
| 1660 | // The underscore character stands for the 'can trigger GC' bit. |
| 1661 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1662 | if (current_bit_is_set) { |
| 1663 | flags += kDebug[s]; |
| 1664 | } |
| 1665 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1666 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1667 | flags += "|"; |
| 1668 | } |
| 1669 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1670 | } |
| 1671 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1672 | } |
| 1673 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1674 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1675 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1676 | private: |
| 1677 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1678 | |
| 1679 | static constexpr int kFieldWriteOffset = 0; |
| 1680 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1681 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1682 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1683 | |
| 1684 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1685 | |
| 1686 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1687 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1688 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1689 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1690 | |
| 1691 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1692 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1693 | |
| 1694 | // Aliases. |
| 1695 | |
| 1696 | static_assert(kChangeBits == kDependOnBits, |
| 1697 | "the 'change' bits should match the 'depend on' bits."); |
| 1698 | |
| 1699 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1700 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1701 | static constexpr uint64_t kAllWrites = |
| 1702 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1703 | static constexpr uint64_t kAllReads = |
| 1704 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1705 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1706 | // Translates type to bit flag. |
| 1707 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1708 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1709 | const uint64_t one = 1; |
| 1710 | const int shift = type; // 0-based consecutive enum |
| 1711 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1712 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1713 | return one << (type + offset); |
| 1714 | } |
| 1715 | |
| 1716 | // Private constructor on direct flags value. |
| 1717 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1718 | |
| 1719 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1720 | }; |
| 1721 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1722 | // 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] | 1723 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1724 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1725 | HEnvironment(ArenaAllocator* arena, |
| 1726 | size_t number_of_vregs, |
| 1727 | const DexFile& dex_file, |
| 1728 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1729 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1730 | InvokeType invoke_type, |
| 1731 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1732 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1733 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1734 | parent_(nullptr), |
| 1735 | dex_file_(dex_file), |
| 1736 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1737 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1738 | invoke_type_(invoke_type), |
| 1739 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1740 | } |
| 1741 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1742 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1743 | : HEnvironment(arena, |
| 1744 | to_copy.Size(), |
| 1745 | to_copy.GetDexFile(), |
| 1746 | to_copy.GetMethodIdx(), |
| 1747 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1748 | to_copy.GetInvokeType(), |
| 1749 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1750 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1751 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1752 | if (parent_ != nullptr) { |
| 1753 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1754 | } else { |
| 1755 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1756 | parent_->CopyFrom(parent); |
| 1757 | if (parent->GetParent() != nullptr) { |
| 1758 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1759 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1760 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1763 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1764 | void CopyFrom(HEnvironment* environment); |
| 1765 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1766 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1767 | // input to the loop phi instead. This is for inserting instructions that |
| 1768 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1769 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1770 | |
| 1771 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1772 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1776 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1779 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1780 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1781 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1782 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1783 | HEnvironment* GetParent() const { return parent_; } |
| 1784 | |
| 1785 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1786 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1790 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | uint32_t GetDexPc() const { |
| 1794 | return dex_pc_; |
| 1795 | } |
| 1796 | |
| 1797 | uint32_t GetMethodIdx() const { |
| 1798 | return method_idx_; |
| 1799 | } |
| 1800 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1801 | InvokeType GetInvokeType() const { |
| 1802 | return invoke_type_; |
| 1803 | } |
| 1804 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1805 | const DexFile& GetDexFile() const { |
| 1806 | return dex_file_; |
| 1807 | } |
| 1808 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1809 | HInstruction* GetHolder() const { |
| 1810 | return holder_; |
| 1811 | } |
| 1812 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1813 | |
| 1814 | bool IsFromInlinedInvoke() const { |
| 1815 | return GetParent() != nullptr; |
| 1816 | } |
| 1817 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1818 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1819 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1820 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1821 | HEnvironment* parent_; |
| 1822 | const DexFile& dex_file_; |
| 1823 | const uint32_t method_idx_; |
| 1824 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1825 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1826 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1827 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1828 | HInstruction* const holder_; |
| 1829 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1830 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1831 | |
| 1832 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1833 | }; |
| 1834 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1835 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1836 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1837 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1838 | : previous_(nullptr), |
| 1839 | next_(nullptr), |
| 1840 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1841 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1842 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1843 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1844 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1845 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1846 | locations_(nullptr), |
| 1847 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1848 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1849 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1850 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1851 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1852 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1853 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1854 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1855 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1856 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1857 | enum InstructionKind { |
| 1858 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1859 | }; |
| 1860 | #undef DECLARE_KIND |
| 1861 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1862 | HInstruction* GetNext() const { return next_; } |
| 1863 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1864 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1865 | HInstruction* GetNextDisregardingMoves() const; |
| 1866 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1867 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1868 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1869 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1870 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1871 | bool IsInBlock() const { return block_ != nullptr; } |
| 1872 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1873 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1874 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1875 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1876 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1877 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1878 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1879 | |
| 1880 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1881 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1882 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1883 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1884 | } |
| 1885 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1886 | HInputsRef GetInputs() { |
| 1887 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1888 | } |
| 1889 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1890 | HConstInputsRef GetInputs() const { |
| 1891 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1892 | } |
| 1893 | |
| 1894 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1895 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1896 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 1897 | bool HasInput(HInstruction* input) const { |
| 1898 | for (const HInstruction* i : GetInputs()) { |
| 1899 | if (i == input) { |
| 1900 | return true; |
| 1901 | } |
| 1902 | } |
| 1903 | return false; |
| 1904 | } |
| 1905 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1906 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1907 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1908 | } |
| 1909 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1910 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1911 | virtual const char* DebugName() const = 0; |
| 1912 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1913 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1914 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1915 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1916 | |
| 1917 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1918 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1919 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1920 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1921 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1922 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1923 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1924 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1925 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1926 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1927 | // Does not apply for all instructions, but having this at top level greatly |
| 1928 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1929 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1930 | virtual bool CanBeNull() const { |
| 1931 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1932 | return true; |
| 1933 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1934 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1935 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1936 | return false; |
| 1937 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1938 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1939 | virtual bool IsActualObject() const { |
| 1940 | return GetType() == Primitive::kPrimNot; |
| 1941 | } |
| 1942 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1943 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1944 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1945 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1946 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1947 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1948 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1949 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1950 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1951 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1952 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1953 | // Note: fixup_end remains valid across push_front(). |
| 1954 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1955 | HUseListNode<HInstruction*>* new_node = |
| 1956 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1957 | uses_.push_front(*new_node); |
| 1958 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1961 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1962 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1963 | // Note: env_fixup_end remains valid across push_front(). |
| 1964 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 1965 | HUseListNode<HEnvironment*>* new_node = |
| 1966 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 1967 | env_uses_.push_front(*new_node); |
| 1968 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1969 | } |
| 1970 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1971 | void RemoveAsUserOfInput(size_t input) { |
| 1972 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1973 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1974 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1975 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1976 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1977 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1978 | void RemoveAsUserOfAllInputs() { |
| 1979 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 1980 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1981 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1982 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 1983 | } |
| 1984 | } |
| 1985 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1986 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1987 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1988 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1989 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 1990 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 1991 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1992 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1993 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1994 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1995 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 1996 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1997 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 1998 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1999 | !CanThrow() && |
| 2000 | !IsSuspendCheck() && |
| 2001 | !IsControlFlow() && |
| 2002 | !IsNativeDebugInfo() && |
| 2003 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2004 | // If we added an explicit barrier then we should keep it. |
| 2005 | !IsMemoryBarrier(); |
| 2006 | } |
| 2007 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2008 | bool IsDeadAndRemovable() const { |
| 2009 | return IsRemovable() && !HasUses(); |
| 2010 | } |
| 2011 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2012 | // Does this instruction strictly dominate `other_instruction`? |
| 2013 | // Returns false if this instruction and `other_instruction` are the same. |
| 2014 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2015 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2016 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2017 | int GetId() const { return id_; } |
| 2018 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2019 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2020 | int GetSsaIndex() const { return ssa_index_; } |
| 2021 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2022 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2023 | |
| 2024 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2025 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2026 | // Set the `environment_` field. Raw because this method does not |
| 2027 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2028 | void SetRawEnvironment(HEnvironment* environment) { |
| 2029 | DCHECK(environment_ == nullptr); |
| 2030 | DCHECK_EQ(environment->GetHolder(), this); |
| 2031 | environment_ = environment; |
| 2032 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2033 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2034 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2035 | DCHECK(environment_ != nullptr); |
| 2036 | DCHECK_EQ(environment->GetHolder(), this); |
| 2037 | DCHECK(environment->GetParent() == nullptr); |
| 2038 | environment->parent_ = environment_; |
| 2039 | environment_ = environment; |
| 2040 | } |
| 2041 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2042 | void RemoveEnvironment(); |
| 2043 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2044 | // Set the environment of this instruction, copying it from `environment`. While |
| 2045 | // copying, the uses lists are being updated. |
| 2046 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2047 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2048 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2049 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2050 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2051 | if (environment->GetParent() != nullptr) { |
| 2052 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2053 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2054 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2055 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2056 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2057 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2058 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2059 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2060 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2061 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2062 | if (environment->GetParent() != nullptr) { |
| 2063 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2064 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2067 | // Returns the number of entries in the environment. Typically, that is the |
| 2068 | // number of dex registers in a method. It could be more in case of inlining. |
| 2069 | size_t EnvironmentSize() const; |
| 2070 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2071 | LocationSummary* GetLocations() const { return locations_; } |
| 2072 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2073 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2074 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2075 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2076 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2077 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2078 | // uses of this instruction by `other` are *not* updated. |
| 2079 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2080 | ReplaceWith(other); |
| 2081 | other->ReplaceInput(this, use_index); |
| 2082 | } |
| 2083 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2084 | // Move `this` instruction before `cursor`. |
| 2085 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2086 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2087 | // Move `this` before its first user and out of any loops. If there is no |
| 2088 | // out-of-loop user that dominates all other users, move the instruction |
| 2089 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2090 | // |
| 2091 | // This can be used only on non-throwing instructions with no side effects that |
| 2092 | // have at least one use but no environment uses. |
| 2093 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2094 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2095 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2096 | bool Is##type() const; \ |
| 2097 | const H##type* As##type() const; \ |
| 2098 | H##type* As##type(); |
| 2099 | |
| 2100 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2101 | #undef INSTRUCTION_TYPE_CHECK |
| 2102 | |
| 2103 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2104 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2105 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2106 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2107 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2108 | #undef INSTRUCTION_TYPE_CHECK |
| 2109 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2110 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2111 | // TODO: this method is used by LICM and GVN with possibly different |
| 2112 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2113 | virtual bool CanBeMoved() const { return false; } |
| 2114 | |
| 2115 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2116 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2117 | return false; |
| 2118 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2119 | |
| 2120 | // Returns whether any data encoded in the two instructions is equal. |
| 2121 | // This method does not look at the inputs. Both instructions must be |
| 2122 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2123 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2124 | return false; |
| 2125 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2126 | |
| 2127 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2128 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2129 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2130 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2131 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2132 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2133 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2134 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2135 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2136 | InstructionKind GetKind() const PURE; |
| 2137 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2138 | |
| 2139 | virtual size_t ComputeHashCode() const { |
| 2140 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2141 | for (const HInstruction* input : GetInputs()) { |
| 2142 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2143 | } |
| 2144 | return result; |
| 2145 | } |
| 2146 | |
| 2147 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2148 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2149 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2150 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2151 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2152 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2153 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2154 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2155 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2156 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2157 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2158 | |
| 2159 | // Returns whether the code generation of the instruction will require to have access |
| 2160 | // to the current method. Such instructions are: |
| 2161 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2162 | // 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] | 2163 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2164 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2165 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2166 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2169 | // Returns whether the code generation of the instruction will require to have access |
| 2170 | // to the dex cache of the current method's declaring class via the current method. |
| 2171 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2172 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2173 | // Does this instruction have any use in an environment before |
| 2174 | // control flow hits 'other'? |
| 2175 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2176 | |
| 2177 | // Remove all references to environment uses of this instruction. |
| 2178 | // The caller must ensure that this is safe to do. |
| 2179 | void RemoveEnvironmentUsers(); |
| 2180 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2181 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2182 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2183 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2184 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2185 | // If set, the machine code for this instruction is assumed to be generated by |
| 2186 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2187 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2188 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2189 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2190 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2191 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2192 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2193 | return GetInputRecords()[i]; |
| 2194 | } |
| 2195 | |
| 2196 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2197 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2198 | input_records[index] = input; |
| 2199 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2200 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2201 | uint32_t GetPackedFields() const { |
| 2202 | return packed_fields_; |
| 2203 | } |
| 2204 | |
| 2205 | template <size_t flag> |
| 2206 | bool GetPackedFlag() const { |
| 2207 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2208 | } |
| 2209 | |
| 2210 | template <size_t flag> |
| 2211 | void SetPackedFlag(bool value = true) { |
| 2212 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2213 | } |
| 2214 | |
| 2215 | template <typename BitFieldType> |
| 2216 | typename BitFieldType::value_type GetPackedField() const { |
| 2217 | return BitFieldType::Decode(packed_fields_); |
| 2218 | } |
| 2219 | |
| 2220 | template <typename BitFieldType> |
| 2221 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2222 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2223 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2224 | } |
| 2225 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2226 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2227 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2228 | auto before_use_node = uses_.before_begin(); |
| 2229 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2230 | HInstruction* user = use_node->GetUser(); |
| 2231 | size_t input_index = use_node->GetIndex(); |
| 2232 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2233 | before_use_node = use_node; |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2238 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2239 | if (next != uses_.end()) { |
| 2240 | HInstruction* next_user = next->GetUser(); |
| 2241 | size_t next_index = next->GetIndex(); |
| 2242 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2243 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2244 | } |
| 2245 | } |
| 2246 | |
| 2247 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2248 | auto before_env_use_node = env_uses_.before_begin(); |
| 2249 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2250 | HEnvironment* user = env_use_node->GetUser(); |
| 2251 | size_t input_index = env_use_node->GetIndex(); |
| 2252 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2253 | before_env_use_node = env_use_node; |
| 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2258 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2259 | if (next != env_uses_.end()) { |
| 2260 | HEnvironment* next_user = next->GetUser(); |
| 2261 | size_t next_index = next->GetIndex(); |
| 2262 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2263 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2264 | } |
| 2265 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2266 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2267 | HInstruction* previous_; |
| 2268 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2269 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2270 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2271 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2272 | // An instruction gets an id when it is added to the graph. |
| 2273 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2274 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2275 | int id_; |
| 2276 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2277 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2278 | int ssa_index_; |
| 2279 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2280 | // Packed fields. |
| 2281 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2282 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2283 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2284 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2285 | |
| 2286 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2287 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2288 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2289 | // The environment associated with this instruction. Not null if the instruction |
| 2290 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2291 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2292 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2293 | // Set by the code generator. |
| 2294 | LocationSummary* locations_; |
| 2295 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2296 | // Set by the liveness analysis. |
| 2297 | LiveInterval* live_interval_; |
| 2298 | |
| 2299 | // Set by the liveness analysis, this is the position in a linear |
| 2300 | // order of blocks where this instruction's live interval start. |
| 2301 | size_t lifetime_position_; |
| 2302 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2303 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2304 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2305 | // The reference handle part of the reference type info. |
| 2306 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2307 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2308 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2309 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2310 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2311 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2312 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2313 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2314 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2315 | |
| 2316 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2317 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2318 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2319 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2320 | // Iterates over the instructions, while preserving the next instruction |
| 2321 | // in case the current instruction gets removed from the list by the user |
| 2322 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2323 | class HInstructionIterator : public ValueObject { |
| 2324 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2325 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2326 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2327 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2330 | bool Done() const { return instruction_ == nullptr; } |
| 2331 | HInstruction* Current() const { return instruction_; } |
| 2332 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2333 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2334 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | private: |
| 2338 | HInstruction* instruction_; |
| 2339 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2340 | |
| 2341 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2342 | }; |
| 2343 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2344 | // Iterates over the instructions without saving the next instruction, |
| 2345 | // therefore handling changes in the graph potentially made by the user |
| 2346 | // of this iterator. |
| 2347 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2348 | public: |
| 2349 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2350 | : instruction_(instructions.first_instruction_) { |
| 2351 | } |
| 2352 | |
| 2353 | bool Done() const { return instruction_ == nullptr; } |
| 2354 | HInstruction* Current() const { return instruction_; } |
| 2355 | void Advance() { |
| 2356 | instruction_ = instruction_->GetNext(); |
| 2357 | } |
| 2358 | |
| 2359 | private: |
| 2360 | HInstruction* instruction_; |
| 2361 | |
| 2362 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2363 | }; |
| 2364 | |
| 2365 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2366 | class HBackwardInstructionIterator : public ValueObject { |
| 2367 | public: |
| 2368 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2369 | : instruction_(instructions.last_instruction_) { |
| 2370 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2371 | } |
| 2372 | |
| 2373 | bool Done() const { return instruction_ == nullptr; } |
| 2374 | HInstruction* Current() const { return instruction_; } |
| 2375 | void Advance() { |
| 2376 | instruction_ = next_; |
| 2377 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2378 | } |
| 2379 | |
| 2380 | private: |
| 2381 | HInstruction* instruction_; |
| 2382 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2383 | |
| 2384 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2385 | }; |
| 2386 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2387 | class HVariableInputSizeInstruction : public HInstruction { |
| 2388 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2389 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2390 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 2391 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2392 | } |
| 2393 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2394 | void AddInput(HInstruction* input); |
| 2395 | void InsertInputAt(size_t index, HInstruction* input); |
| 2396 | void RemoveInputAt(size_t index); |
| 2397 | |
| 2398 | protected: |
| 2399 | HVariableInputSizeInstruction(SideEffects side_effects, |
| 2400 | uint32_t dex_pc, |
| 2401 | ArenaAllocator* arena, |
| 2402 | size_t number_of_inputs, |
| 2403 | ArenaAllocKind kind) |
| 2404 | : HInstruction(side_effects, dex_pc), |
| 2405 | inputs_(number_of_inputs, arena->Adapter(kind)) {} |
| 2406 | |
| 2407 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
| 2408 | |
| 2409 | private: |
| 2410 | DISALLOW_COPY_AND_ASSIGN(HVariableInputSizeInstruction); |
| 2411 | }; |
| 2412 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2413 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2414 | class HTemplateInstruction: public HInstruction { |
| 2415 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2416 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2417 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2418 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2419 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2420 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2421 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2422 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2425 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2426 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2427 | |
| 2428 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2429 | }; |
| 2430 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2431 | // HTemplateInstruction specialization for N=0. |
| 2432 | template<> |
| 2433 | class HTemplateInstruction<0>: public HInstruction { |
| 2434 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2435 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2436 | : HInstruction(side_effects, dex_pc) {} |
| 2437 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2438 | virtual ~HTemplateInstruction() {} |
| 2439 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2440 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2441 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2442 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | private: |
| 2446 | friend class SsaBuilder; |
| 2447 | }; |
| 2448 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2449 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2450 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2451 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2452 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2453 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2454 | this->template SetPackedField<TypeField>(type); |
| 2455 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2456 | virtual ~HExpression() {} |
| 2457 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2458 | Primitive::Type GetType() const OVERRIDE { |
| 2459 | return TypeField::Decode(this->GetPackedFields()); |
| 2460 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2461 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2462 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2463 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2464 | static constexpr size_t kFieldTypeSize = |
| 2465 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2466 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2467 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2468 | "Too many packed fields."); |
| 2469 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2470 | }; |
| 2471 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2472 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2473 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2474 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2475 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2476 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2477 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2478 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2479 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2480 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2481 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2482 | |
| 2483 | private: |
| 2484 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2485 | }; |
| 2486 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2487 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2488 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2489 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2490 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2491 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2492 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2493 | SetRawInputAt(0, value); |
| 2494 | } |
| 2495 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2496 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2497 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2498 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2499 | |
| 2500 | private: |
| 2501 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2502 | }; |
| 2503 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2504 | class HPhi FINAL : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2505 | public: |
| 2506 | HPhi(ArenaAllocator* arena, |
| 2507 | uint32_t reg_number, |
| 2508 | size_t number_of_inputs, |
| 2509 | Primitive::Type type, |
| 2510 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2511 | : HVariableInputSizeInstruction( |
| 2512 | SideEffects::None(), |
| 2513 | dex_pc, |
| 2514 | arena, |
| 2515 | number_of_inputs, |
| 2516 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2517 | reg_number_(reg_number) { |
| 2518 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2519 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2520 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2521 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2522 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2523 | SetPackedFlag<kFlagIsLive>(true); |
| 2524 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2525 | } |
| 2526 | |
| 2527 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2528 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2529 | return Primitive::PrimitiveKind(type); |
| 2530 | } |
| 2531 | |
| 2532 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2533 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2534 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2535 | void SetType(Primitive::Type new_type) { |
| 2536 | // Make sure that only valid type changes occur. The following are allowed: |
| 2537 | // (1) int -> float/ref (primitive type propagation), |
| 2538 | // (2) long -> double (primitive type propagation). |
| 2539 | DCHECK(GetType() == new_type || |
| 2540 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2541 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2542 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2543 | SetPackedField<TypeField>(new_type); |
| 2544 | } |
| 2545 | |
| 2546 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2547 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2548 | |
| 2549 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2550 | |
| 2551 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2552 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2553 | bool IsDead() const { return !IsLive(); } |
| 2554 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2555 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2556 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2557 | return other != nullptr |
| 2558 | && other->IsPhi() |
| 2559 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2560 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2561 | } |
| 2562 | |
| 2563 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2564 | // An equivalent phi is a phi having the same dex register and type. |
| 2565 | // It assumes that phis with the same dex register are adjacent. |
| 2566 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2567 | HInstruction* next = GetNext(); |
| 2568 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2569 | if (next->GetType() == GetType()) { |
| 2570 | return next->AsPhi(); |
| 2571 | } |
| 2572 | next = next->GetNext(); |
| 2573 | } |
| 2574 | return nullptr; |
| 2575 | } |
| 2576 | |
| 2577 | DECLARE_INSTRUCTION(Phi); |
| 2578 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2579 | private: |
| 2580 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2581 | static constexpr size_t kFieldTypeSize = |
| 2582 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2583 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2584 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2585 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2586 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2587 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2588 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2589 | const uint32_t reg_number_; |
| 2590 | |
| 2591 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2592 | }; |
| 2593 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2594 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2595 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2596 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2597 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2598 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2599 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2600 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2601 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2602 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2603 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2604 | |
| 2605 | private: |
| 2606 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2607 | }; |
| 2608 | |
| 2609 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2610 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2611 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2612 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2613 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2614 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2615 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2616 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2617 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2620 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2621 | |
| 2622 | private: |
| 2623 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2624 | }; |
| 2625 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2626 | class HConstant : public HExpression<0> { |
| 2627 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2628 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2629 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2630 | |
| 2631 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2632 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2633 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2634 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2635 | // Is this constant 0 in the arithmetic sense? |
| 2636 | virtual bool IsArithmeticZero() const { return false; } |
| 2637 | // Is this constant a 0-bit pattern? |
| 2638 | virtual bool IsZeroBitPattern() const { return false; } |
| 2639 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2640 | virtual bool IsOne() const { return false; } |
| 2641 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2642 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2643 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2644 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2645 | |
| 2646 | private: |
| 2647 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2648 | }; |
| 2649 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2650 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2651 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2652 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2653 | return true; |
| 2654 | } |
| 2655 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2656 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2657 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2658 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2659 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2660 | // The null constant representation is a 0-bit pattern. |
| 2661 | virtual bool IsZeroBitPattern() const { return true; } |
| 2662 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2663 | DECLARE_INSTRUCTION(NullConstant); |
| 2664 | |
| 2665 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2666 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2667 | |
| 2668 | friend class HGraph; |
| 2669 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2670 | }; |
| 2671 | |
| 2672 | // Constants of the type int. Those can be from Dex instructions, or |
| 2673 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2674 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2675 | public: |
| 2676 | int32_t GetValue() const { return value_; } |
| 2677 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2678 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2679 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2680 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2681 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2682 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2683 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2684 | return other->AsIntConstant()->value_ == value_; |
| 2685 | } |
| 2686 | |
| 2687 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2688 | |
| 2689 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2690 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2691 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2692 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2693 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2694 | // Integer constants are used to encode Boolean values as well, |
| 2695 | // where 1 means true and 0 means false. |
| 2696 | bool IsTrue() const { return GetValue() == 1; } |
| 2697 | bool IsFalse() const { return GetValue() == 0; } |
| 2698 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2699 | DECLARE_INSTRUCTION(IntConstant); |
| 2700 | |
| 2701 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2702 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2703 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2704 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2705 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2706 | |
| 2707 | const int32_t value_; |
| 2708 | |
| 2709 | friend class HGraph; |
| 2710 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2711 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2712 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2713 | }; |
| 2714 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2715 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2716 | public: |
| 2717 | int64_t GetValue() const { return value_; } |
| 2718 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2719 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2720 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2721 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2722 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2723 | return other->AsLongConstant()->value_ == value_; |
| 2724 | } |
| 2725 | |
| 2726 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2727 | |
| 2728 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2729 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2730 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2731 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2732 | |
| 2733 | DECLARE_INSTRUCTION(LongConstant); |
| 2734 | |
| 2735 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2736 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2737 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2738 | |
| 2739 | const int64_t value_; |
| 2740 | |
| 2741 | friend class HGraph; |
| 2742 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2743 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2744 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2745 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2746 | public: |
| 2747 | float GetValue() const { return value_; } |
| 2748 | |
| 2749 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2750 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2751 | } |
| 2752 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2753 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2754 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2755 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2756 | } |
| 2757 | |
| 2758 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2759 | |
| 2760 | bool IsMinusOne() const OVERRIDE { |
| 2761 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2762 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2763 | bool IsArithmeticZero() const OVERRIDE { |
| 2764 | return std::fpclassify(value_) == FP_ZERO; |
| 2765 | } |
| 2766 | bool IsArithmeticPositiveZero() const { |
| 2767 | return IsArithmeticZero() && !std::signbit(value_); |
| 2768 | } |
| 2769 | bool IsArithmeticNegativeZero() const { |
| 2770 | return IsArithmeticZero() && std::signbit(value_); |
| 2771 | } |
| 2772 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2773 | 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] | 2774 | } |
| 2775 | bool IsOne() const OVERRIDE { |
| 2776 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2777 | } |
| 2778 | bool IsNaN() const { |
| 2779 | return std::isnan(value_); |
| 2780 | } |
| 2781 | |
| 2782 | DECLARE_INSTRUCTION(FloatConstant); |
| 2783 | |
| 2784 | private: |
| 2785 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2786 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2787 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2788 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2789 | |
| 2790 | const float value_; |
| 2791 | |
| 2792 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2793 | friend class SsaBuilder; |
| 2794 | friend class HGraph; |
| 2795 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2796 | }; |
| 2797 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2798 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2799 | public: |
| 2800 | double GetValue() const { return value_; } |
| 2801 | |
| 2802 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2803 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2804 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2805 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2806 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2807 | } |
| 2808 | |
| 2809 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2810 | |
| 2811 | bool IsMinusOne() const OVERRIDE { |
| 2812 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2813 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2814 | bool IsArithmeticZero() const OVERRIDE { |
| 2815 | return std::fpclassify(value_) == FP_ZERO; |
| 2816 | } |
| 2817 | bool IsArithmeticPositiveZero() const { |
| 2818 | return IsArithmeticZero() && !std::signbit(value_); |
| 2819 | } |
| 2820 | bool IsArithmeticNegativeZero() const { |
| 2821 | return IsArithmeticZero() && std::signbit(value_); |
| 2822 | } |
| 2823 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2824 | 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] | 2825 | } |
| 2826 | bool IsOne() const OVERRIDE { |
| 2827 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2828 | } |
| 2829 | bool IsNaN() const { |
| 2830 | return std::isnan(value_); |
| 2831 | } |
| 2832 | |
| 2833 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2834 | |
| 2835 | private: |
| 2836 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2837 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2838 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2839 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2840 | |
| 2841 | const double value_; |
| 2842 | |
| 2843 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2844 | friend class SsaBuilder; |
| 2845 | friend class HGraph; |
| 2846 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2847 | }; |
| 2848 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2849 | // Conditional branch. A block ending with an HIf instruction must have |
| 2850 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2851 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2852 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2853 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2854 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2855 | SetRawInputAt(0, input); |
| 2856 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2857 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2858 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2859 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2860 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2861 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2862 | } |
| 2863 | |
| 2864 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2865 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2866 | } |
| 2867 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2868 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2869 | |
| 2870 | private: |
| 2871 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2872 | }; |
| 2873 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2874 | |
| 2875 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2876 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2877 | // non-exceptional control flow. |
| 2878 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2879 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2880 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2881 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2882 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2883 | kEntry, |
| 2884 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2885 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2886 | }; |
| 2887 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2888 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2889 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2890 | SetPackedField<BoundaryKindField>(kind); |
| 2891 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2892 | |
| 2893 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2894 | |
| 2895 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2896 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2897 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2898 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2899 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2900 | } |
| 2901 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2902 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2903 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2904 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2905 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2906 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | // If not present already, adds `handler` to its block's list of exception |
| 2910 | // handlers. |
| 2911 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2912 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2913 | GetBlock()->AddSuccessor(handler); |
| 2914 | } |
| 2915 | } |
| 2916 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2917 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2918 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2919 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2920 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2921 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2922 | DECLARE_INSTRUCTION(TryBoundary); |
| 2923 | |
| 2924 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2925 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2926 | static constexpr size_t kFieldBoundaryKindSize = |
| 2927 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2928 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2929 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2930 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2931 | "Too many packed fields."); |
| 2932 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2933 | |
| 2934 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2935 | }; |
| 2936 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2937 | // Deoptimize to interpreter, upon checking a condition. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2938 | class HDeoptimize FINAL : public HTemplateInstruction<1> { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2939 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2940 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2941 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2942 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2943 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2944 | SetRawInputAt(0, cond); |
| 2945 | } |
| 2946 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2947 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2948 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2949 | return true; |
| 2950 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2951 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2952 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2953 | |
| 2954 | DECLARE_INSTRUCTION(Deoptimize); |
| 2955 | |
| 2956 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2957 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2958 | }; |
| 2959 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2960 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 2961 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 2962 | // if it's true, starts to do deoptimization. |
| 2963 | // It has a 4-byte slot on stack. |
| 2964 | // TODO: allocate a register for this flag. |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2965 | class HShouldDeoptimizeFlag FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2966 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2967 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 2968 | // with regard to other passes. |
| 2969 | HShouldDeoptimizeFlag(ArenaAllocator* arena, uint32_t dex_pc) |
| 2970 | : HVariableInputSizeInstruction(SideEffects::None(), dex_pc, arena, 0, kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2971 | } |
| 2972 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2973 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimInt; } |
| 2974 | |
| 2975 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 2976 | // further guard elimination/motion since a guard might have been used for justification |
| 2977 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 2978 | // to avoid other optimizations trying to move it. |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2979 | bool CanBeMoved() const OVERRIDE { return false; } |
| 2980 | |
| 2981 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 2982 | |
| 2983 | private: |
| 2984 | DISALLOW_COPY_AND_ASSIGN(HShouldDeoptimizeFlag); |
| 2985 | }; |
| 2986 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2987 | // Represents the ArtMethod that was passed as a first argument to |
| 2988 | // the method. It is used by instructions that depend on it, like |
| 2989 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2990 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2991 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2992 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2993 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2994 | |
| 2995 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2996 | |
| 2997 | private: |
| 2998 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2999 | }; |
| 3000 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3001 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3002 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3003 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3004 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3005 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3006 | kVTable, |
| 3007 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3008 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3009 | }; |
| 3010 | HClassTableGet(HInstruction* cls, |
| 3011 | Primitive::Type type, |
| 3012 | TableKind kind, |
| 3013 | size_t index, |
| 3014 | uint32_t dex_pc) |
| 3015 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3016 | index_(index) { |
| 3017 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3018 | SetRawInputAt(0, cls); |
| 3019 | } |
| 3020 | |
| 3021 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3022 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3023 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3024 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3025 | } |
| 3026 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3027 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3028 | size_t GetIndex() const { return index_; } |
| 3029 | |
| 3030 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3031 | |
| 3032 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3033 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 3034 | static constexpr size_t kFieldTableKindSize = |
| 3035 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3036 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3037 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3038 | "Too many packed fields."); |
| 3039 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3040 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3041 | // The index of the ArtMethod in the table. |
| 3042 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3043 | |
| 3044 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 3045 | }; |
| 3046 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3047 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3048 | // have one successor for each entry in the switch table, and the final successor |
| 3049 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3050 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3051 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3052 | HPackedSwitch(int32_t start_value, |
| 3053 | uint32_t num_entries, |
| 3054 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3055 | uint32_t dex_pc = kNoDexPc) |
| 3056 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 3057 | start_value_(start_value), |
| 3058 | num_entries_(num_entries) { |
| 3059 | SetRawInputAt(0, input); |
| 3060 | } |
| 3061 | |
| 3062 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3063 | |
| 3064 | int32_t GetStartValue() const { return start_value_; } |
| 3065 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3066 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3067 | |
| 3068 | HBasicBlock* GetDefaultBlock() const { |
| 3069 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3070 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3071 | } |
| 3072 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3073 | |
| 3074 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3075 | const int32_t start_value_; |
| 3076 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3077 | |
| 3078 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 3079 | }; |
| 3080 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3081 | class HUnaryOperation : public HExpression<1> { |
| 3082 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3083 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3084 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3085 | SetRawInputAt(0, input); |
| 3086 | } |
| 3087 | |
| 3088 | HInstruction* GetInput() const { return InputAt(0); } |
| 3089 | Primitive::Type GetResultType() const { return GetType(); } |
| 3090 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3091 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3092 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3093 | return true; |
| 3094 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3095 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3096 | // Try to statically evaluate `this` and return a HConstant |
| 3097 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3098 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3099 | HConstant* TryStaticEvaluation() const; |
| 3100 | |
| 3101 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3102 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3103 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3104 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3105 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3106 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3107 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3108 | |
| 3109 | private: |
| 3110 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 3111 | }; |
| 3112 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3113 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3114 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3115 | HBinaryOperation(Primitive::Type result_type, |
| 3116 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3117 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3118 | SideEffects side_effects = SideEffects::None(), |
| 3119 | uint32_t dex_pc = kNoDexPc) |
| 3120 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3121 | SetRawInputAt(0, left); |
| 3122 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3123 | } |
| 3124 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3125 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3126 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3127 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3128 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3129 | virtual bool IsCommutative() const { return false; } |
| 3130 | |
| 3131 | // Put constant on the right. |
| 3132 | // Returns whether order is changed. |
| 3133 | bool OrderInputsWithConstantOnTheRight() { |
| 3134 | HInstruction* left = InputAt(0); |
| 3135 | HInstruction* right = InputAt(1); |
| 3136 | if (left->IsConstant() && !right->IsConstant()) { |
| 3137 | ReplaceInput(right, 0); |
| 3138 | ReplaceInput(left, 1); |
| 3139 | return true; |
| 3140 | } |
| 3141 | return false; |
| 3142 | } |
| 3143 | |
| 3144 | // Order inputs by instruction id, but favor constant on the right side. |
| 3145 | // This helps GVN for commutative ops. |
| 3146 | void OrderInputs() { |
| 3147 | DCHECK(IsCommutative()); |
| 3148 | HInstruction* left = InputAt(0); |
| 3149 | HInstruction* right = InputAt(1); |
| 3150 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3151 | return; |
| 3152 | } |
| 3153 | if (OrderInputsWithConstantOnTheRight()) { |
| 3154 | return; |
| 3155 | } |
| 3156 | // Order according to instruction id. |
| 3157 | if (left->GetId() > right->GetId()) { |
| 3158 | ReplaceInput(right, 0); |
| 3159 | ReplaceInput(left, 1); |
| 3160 | } |
| 3161 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3162 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3163 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3164 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3165 | return true; |
| 3166 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3167 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3168 | // Try to statically evaluate `this` and return a HConstant |
| 3169 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3170 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3171 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3172 | |
| 3173 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3174 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3175 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3176 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3177 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3178 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3179 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3180 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3181 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3182 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3183 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3184 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3185 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3186 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3187 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3188 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3189 | // 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] | 3190 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3191 | HConstant* GetConstantRight() const; |
| 3192 | |
| 3193 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3194 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3195 | HInstruction* GetLeastConstantLeft() const; |
| 3196 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3197 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3198 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3199 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3200 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3201 | }; |
| 3202 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3203 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3204 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3205 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3206 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3207 | kGtBias, // return 1 for NaN comparisons |
| 3208 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3209 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3210 | }; |
| 3211 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3212 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3213 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3214 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3215 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3216 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3217 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3218 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3219 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3220 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3221 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3222 | // `instruction`, and disregard moves in between. |
| 3223 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3224 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3225 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3226 | |
| 3227 | virtual IfCondition GetCondition() const = 0; |
| 3228 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3229 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3230 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3231 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3232 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3233 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3234 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3235 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3236 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3237 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3238 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3239 | } |
| 3240 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3241 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3242 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3243 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3244 | if (if_cond == kCondNE) { |
| 3245 | return true; |
| 3246 | } else if (if_cond == kCondEQ) { |
| 3247 | return false; |
| 3248 | } |
| 3249 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3253 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3254 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3255 | if (if_cond == kCondEQ) { |
| 3256 | return true; |
| 3257 | } else if (if_cond == kCondNE) { |
| 3258 | return false; |
| 3259 | } |
| 3260 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3261 | } |
| 3262 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3263 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3264 | // Needed if we merge a HCompare into a HCondition. |
| 3265 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3266 | static constexpr size_t kFieldComparisonBiasSize = |
| 3267 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3268 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3269 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3270 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3271 | using ComparisonBiasField = |
| 3272 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3273 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3274 | template <typename T> |
| 3275 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3276 | |
| 3277 | template <typename T> |
| 3278 | int32_t CompareFP(T x, T y) const { |
| 3279 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3280 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3281 | // Handle the bias. |
| 3282 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3283 | } |
| 3284 | |
| 3285 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3286 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3287 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3288 | } |
| 3289 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3290 | private: |
| 3291 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3292 | }; |
| 3293 | |
| 3294 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3295 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3296 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3297 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3298 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3299 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3300 | bool IsCommutative() const OVERRIDE { return true; } |
| 3301 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3302 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3303 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3304 | return MakeConstantCondition(true, GetDexPc()); |
| 3305 | } |
| 3306 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3307 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3308 | } |
| 3309 | // In the following Evaluate methods, a HCompare instruction has |
| 3310 | // been merged into this HEqual instruction; evaluate it as |
| 3311 | // `Compare(x, y) == 0`. |
| 3312 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3313 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3314 | GetDexPc()); |
| 3315 | } |
| 3316 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3317 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3318 | } |
| 3319 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3320 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3321 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3322 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3323 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3324 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3325 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3326 | return kCondEQ; |
| 3327 | } |
| 3328 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3329 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3330 | return kCondNE; |
| 3331 | } |
| 3332 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3333 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3334 | 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] | 3335 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3336 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3337 | }; |
| 3338 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3339 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3340 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3341 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3342 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3343 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3344 | bool IsCommutative() const OVERRIDE { return true; } |
| 3345 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3346 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3347 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3348 | return MakeConstantCondition(false, GetDexPc()); |
| 3349 | } |
| 3350 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3351 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3352 | } |
| 3353 | // In the following Evaluate methods, a HCompare instruction has |
| 3354 | // been merged into this HNotEqual instruction; evaluate it as |
| 3355 | // `Compare(x, y) != 0`. |
| 3356 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3357 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3358 | } |
| 3359 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3360 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3361 | } |
| 3362 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3363 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3364 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3365 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3366 | DECLARE_INSTRUCTION(NotEqual); |
| 3367 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3368 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3369 | return kCondNE; |
| 3370 | } |
| 3371 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3372 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3373 | return kCondEQ; |
| 3374 | } |
| 3375 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3376 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3377 | 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] | 3378 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3379 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3380 | }; |
| 3381 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3382 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3383 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3384 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3385 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3386 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3387 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3388 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3389 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3390 | // In the following Evaluate methods, a HCompare instruction has |
| 3391 | // been merged into this HLessThan instruction; evaluate it as |
| 3392 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3393 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3394 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3395 | } |
| 3396 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3397 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3398 | } |
| 3399 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3400 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3401 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3402 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3403 | DECLARE_INSTRUCTION(LessThan); |
| 3404 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3405 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3406 | return kCondLT; |
| 3407 | } |
| 3408 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3409 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3410 | return kCondGE; |
| 3411 | } |
| 3412 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3413 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3414 | 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] | 3415 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3416 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3417 | }; |
| 3418 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3419 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3420 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3421 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3422 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3423 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3424 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3425 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3426 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3427 | // In the following Evaluate methods, a HCompare instruction has |
| 3428 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3429 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3430 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3431 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3432 | } |
| 3433 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3434 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3435 | } |
| 3436 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3437 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3438 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3439 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3440 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3441 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3442 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3443 | return kCondLE; |
| 3444 | } |
| 3445 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3446 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3447 | return kCondGT; |
| 3448 | } |
| 3449 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3450 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3451 | 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] | 3452 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3453 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3454 | }; |
| 3455 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3456 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3457 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3458 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3459 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3460 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3461 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3462 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3463 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3464 | // In the following Evaluate methods, a HCompare instruction has |
| 3465 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3466 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3467 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3468 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3469 | } |
| 3470 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3471 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3472 | } |
| 3473 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3474 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3475 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3476 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3477 | DECLARE_INSTRUCTION(GreaterThan); |
| 3478 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3479 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3480 | return kCondGT; |
| 3481 | } |
| 3482 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3483 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3484 | return kCondLE; |
| 3485 | } |
| 3486 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3487 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3488 | 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] | 3489 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3490 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3491 | }; |
| 3492 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3493 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3494 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3495 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3496 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3497 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3498 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3499 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3500 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3501 | // In the following Evaluate methods, a HCompare instruction has |
| 3502 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3503 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3504 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3505 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3506 | } |
| 3507 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3508 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3509 | } |
| 3510 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3511 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3512 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3513 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3514 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3515 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3516 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3517 | return kCondGE; |
| 3518 | } |
| 3519 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3520 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3521 | return kCondLT; |
| 3522 | } |
| 3523 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3524 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3525 | 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] | 3526 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3527 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3528 | }; |
| 3529 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3530 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3531 | public: |
| 3532 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3533 | : HCondition(first, second, dex_pc) {} |
| 3534 | |
| 3535 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3536 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3537 | } |
| 3538 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3539 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3540 | } |
| 3541 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3542 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3543 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3544 | UNREACHABLE(); |
| 3545 | } |
| 3546 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3547 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3548 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3549 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | DECLARE_INSTRUCTION(Below); |
| 3553 | |
| 3554 | IfCondition GetCondition() const OVERRIDE { |
| 3555 | return kCondB; |
| 3556 | } |
| 3557 | |
| 3558 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3559 | return kCondAE; |
| 3560 | } |
| 3561 | |
| 3562 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3563 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3564 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3565 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3566 | |
| 3567 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3568 | }; |
| 3569 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3570 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3571 | public: |
| 3572 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3573 | : HCondition(first, second, dex_pc) {} |
| 3574 | |
| 3575 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3576 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3577 | } |
| 3578 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3579 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3580 | } |
| 3581 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3582 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3583 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3584 | UNREACHABLE(); |
| 3585 | } |
| 3586 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3587 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3588 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3589 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3593 | |
| 3594 | IfCondition GetCondition() const OVERRIDE { |
| 3595 | return kCondBE; |
| 3596 | } |
| 3597 | |
| 3598 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3599 | return kCondA; |
| 3600 | } |
| 3601 | |
| 3602 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3603 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3604 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3605 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3606 | |
| 3607 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3608 | }; |
| 3609 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3610 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3611 | public: |
| 3612 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3613 | : HCondition(first, second, dex_pc) {} |
| 3614 | |
| 3615 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3616 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3617 | } |
| 3618 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3619 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3620 | } |
| 3621 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3622 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3623 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3624 | UNREACHABLE(); |
| 3625 | } |
| 3626 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3627 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3628 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3629 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3630 | } |
| 3631 | |
| 3632 | DECLARE_INSTRUCTION(Above); |
| 3633 | |
| 3634 | IfCondition GetCondition() const OVERRIDE { |
| 3635 | return kCondA; |
| 3636 | } |
| 3637 | |
| 3638 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3639 | return kCondBE; |
| 3640 | } |
| 3641 | |
| 3642 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3643 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3644 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3645 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3646 | |
| 3647 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3648 | }; |
| 3649 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3650 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3651 | public: |
| 3652 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3653 | : HCondition(first, second, dex_pc) {} |
| 3654 | |
| 3655 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3656 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3657 | } |
| 3658 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3659 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3660 | } |
| 3661 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3662 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3663 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3664 | UNREACHABLE(); |
| 3665 | } |
| 3666 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3667 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3668 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3669 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3673 | |
| 3674 | IfCondition GetCondition() const OVERRIDE { |
| 3675 | return kCondAE; |
| 3676 | } |
| 3677 | |
| 3678 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3679 | return kCondB; |
| 3680 | } |
| 3681 | |
| 3682 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3683 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3684 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3685 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3686 | |
| 3687 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3688 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3689 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3690 | // Instruction to check how two inputs compare to each other. |
| 3691 | // 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] | 3692 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3693 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3694 | // Note that `comparison_type` is the type of comparison performed |
| 3695 | // between the comparison's inputs, not the type of the instantiated |
| 3696 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3697 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3698 | HInstruction* first, |
| 3699 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3700 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3701 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3702 | : HBinaryOperation(Primitive::kPrimInt, |
| 3703 | first, |
| 3704 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3705 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3706 | dex_pc) { |
| 3707 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3708 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3709 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3710 | } |
| 3711 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3712 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3713 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3714 | |
| 3715 | template <typename T> |
| 3716 | int32_t ComputeFP(T x, T y) const { |
| 3717 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3718 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3719 | // Handle the bias. |
| 3720 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3721 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3722 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3723 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3724 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3725 | // reach this code path when processing a freshly built HIR |
| 3726 | // graph. However HCompare integer instructions can be synthesized |
| 3727 | // by the instruction simplifier to implement IntegerCompare and |
| 3728 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3729 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3730 | } |
| 3731 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3732 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3733 | } |
| 3734 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3735 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3736 | } |
| 3737 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3738 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3739 | } |
| 3740 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3741 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3742 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3743 | } |
| 3744 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3745 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3746 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3747 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3748 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3749 | bool IsGtBias() const { |
| 3750 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3751 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3752 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3753 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3754 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3755 | // Comparisons do not require a runtime call in any back end. |
| 3756 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3757 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3758 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3759 | DECLARE_INSTRUCTION(Compare); |
| 3760 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3761 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3762 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3763 | static constexpr size_t kFieldComparisonBiasSize = |
| 3764 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3765 | static constexpr size_t kNumberOfComparePackedBits = |
| 3766 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3767 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3768 | using ComparisonBiasField = |
| 3769 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3770 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3771 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3772 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3773 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3774 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3775 | } |
| 3776 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3777 | private: |
| 3778 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3779 | }; |
| 3780 | |
Nicolas Geoffray | 2b615ba | 2017-01-06 14:40:07 +0000 | [diff] [blame] | 3781 | class HNewInstance FINAL : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3782 | public: |
| 3783 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3784 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3785 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3786 | const DexFile& dex_file, |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3787 | bool needs_access_check, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3788 | bool finalizable, |
| 3789 | QuickEntrypointEnum entrypoint) |
| 3790 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3791 | type_index_(type_index), |
| 3792 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3793 | entrypoint_(entrypoint) { |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3794 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3795 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3796 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3797 | } |
| 3798 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3799 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3800 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3801 | |
| 3802 | // Calls runtime so needs an environment. |
| 3803 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3804 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3805 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3806 | bool CanThrow() const OVERRIDE { return true; } |
| 3807 | |
| 3808 | // Needs to call into runtime to make sure it's instantiable/accessible. |
| 3809 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3810 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3811 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3812 | |
| 3813 | bool CanBeNull() const OVERRIDE { return false; } |
| 3814 | |
| 3815 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3816 | |
| 3817 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3818 | entrypoint_ = entrypoint; |
| 3819 | } |
| 3820 | |
| 3821 | bool IsStringAlloc() const; |
| 3822 | |
| 3823 | DECLARE_INSTRUCTION(NewInstance); |
| 3824 | |
| 3825 | private: |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3826 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfExpressionPackedBits; |
| 3827 | static constexpr size_t kFlagFinalizable = kFlagNeedsAccessCheck + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3828 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3829 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3830 | "Too many packed fields."); |
| 3831 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3832 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3833 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3834 | QuickEntrypointEnum entrypoint_; |
| 3835 | |
| 3836 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3837 | }; |
| 3838 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3839 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3840 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3841 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3842 | }; |
| 3843 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3844 | enum IntrinsicSideEffects { |
| 3845 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3846 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3847 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3848 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3849 | }; |
| 3850 | |
| 3851 | enum IntrinsicExceptions { |
| 3852 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3853 | kCanThrow // Intrinsic may throw exceptions. |
| 3854 | }; |
| 3855 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3856 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3857 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3858 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3859 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3860 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3861 | SetRawInputAt(index, argument); |
| 3862 | } |
| 3863 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3864 | // Return the number of arguments. This number can be lower than |
| 3865 | // the number of inputs returned by InputCount(), as some invoke |
| 3866 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3867 | // inputs at the end of their list of inputs. |
| 3868 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3869 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3870 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3871 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3872 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3873 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3874 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3875 | InvokeType GetInvokeType() const { |
| 3876 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3877 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3878 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3879 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3880 | return intrinsic_; |
| 3881 | } |
| 3882 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3883 | void SetIntrinsic(Intrinsics intrinsic, |
| 3884 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3885 | IntrinsicSideEffects side_effects, |
| 3886 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3887 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3888 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3889 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3890 | } |
| 3891 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 3892 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 3893 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3894 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3895 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 3896 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3897 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3898 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3899 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3900 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3901 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3902 | uint32_t* GetIntrinsicOptimizations() { |
| 3903 | return &intrinsic_optimizations_; |
| 3904 | } |
| 3905 | |
| 3906 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3907 | return &intrinsic_optimizations_; |
| 3908 | } |
| 3909 | |
| 3910 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3911 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3912 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
| 3913 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3914 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3915 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3916 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3917 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 3918 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3919 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3920 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3921 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3922 | static constexpr size_t kFieldReturnTypeSize = |
| 3923 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3924 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3925 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3926 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3927 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3928 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3929 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3930 | HInvoke(ArenaAllocator* arena, |
| 3931 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3932 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3933 | Primitive::Type return_type, |
| 3934 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3935 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3936 | ArtMethod* resolved_method, |
| 3937 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3938 | : HVariableInputSizeInstruction( |
| 3939 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 3940 | dex_pc, |
| 3941 | arena, |
| 3942 | number_of_arguments + number_of_other_inputs, |
| 3943 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3944 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3945 | resolved_method_(resolved_method), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3946 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3947 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3948 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3949 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3950 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3951 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3952 | } |
| 3953 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3954 | uint32_t number_of_arguments_; |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3955 | ArtMethod* const resolved_method_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3956 | const uint32_t dex_method_index_; |
| 3957 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3958 | |
| 3959 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3960 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3961 | |
| 3962 | private: |
| 3963 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3964 | }; |
| 3965 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3966 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3967 | public: |
| 3968 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3969 | uint32_t number_of_arguments, |
| 3970 | Primitive::Type return_type, |
| 3971 | uint32_t dex_pc, |
| 3972 | uint32_t dex_method_index, |
| 3973 | InvokeType invoke_type) |
| 3974 | : HInvoke(arena, |
| 3975 | number_of_arguments, |
| 3976 | 0u /* number_of_other_inputs */, |
| 3977 | return_type, |
| 3978 | dex_pc, |
| 3979 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3980 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3981 | invoke_type) { |
| 3982 | } |
| 3983 | |
| 3984 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3985 | |
| 3986 | private: |
| 3987 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3988 | }; |
| 3989 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3990 | class HInvokePolymorphic FINAL : public HInvoke { |
| 3991 | public: |
| 3992 | HInvokePolymorphic(ArenaAllocator* arena, |
| 3993 | uint32_t number_of_arguments, |
| 3994 | Primitive::Type return_type, |
| 3995 | uint32_t dex_pc, |
| 3996 | uint32_t dex_method_index) |
| 3997 | : HInvoke(arena, |
| 3998 | number_of_arguments, |
| 3999 | 0u /* number_of_other_inputs */, |
| 4000 | return_type, |
| 4001 | dex_pc, |
| 4002 | dex_method_index, |
| 4003 | nullptr, |
| 4004 | kVirtual) {} |
| 4005 | |
| 4006 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4007 | |
| 4008 | private: |
| 4009 | DISALLOW_COPY_AND_ASSIGN(HInvokePolymorphic); |
| 4010 | }; |
| 4011 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4012 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4013 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4014 | // Requirements of this method call regarding the class |
| 4015 | // initialization (clinit) check of its declaring class. |
| 4016 | enum class ClinitCheckRequirement { |
| 4017 | kNone, // Class already initialized. |
| 4018 | kExplicit, // Static call having explicit clinit check as last input. |
| 4019 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4020 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4021 | }; |
| 4022 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4023 | // Determines how to load the target ArtMethod*. |
| 4024 | enum class MethodLoadKind { |
| 4025 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4026 | kStringInit, |
| 4027 | |
| 4028 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4029 | kRecursive, |
| 4030 | |
| 4031 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4032 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 4033 | kDirectAddress, |
| 4034 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4035 | // 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] | 4036 | // Used when we need to use the dex cache, for example for invoke-static that |
| 4037 | // may cause class initialization (the entry may point to a resolution method), |
| 4038 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 4039 | kDexCachePcRelative, |
| 4040 | |
| 4041 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 4042 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 4043 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 4044 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4045 | kDexCacheViaMethod, |
| 4046 | }; |
| 4047 | |
| 4048 | // Determines the location of the code pointer. |
| 4049 | enum class CodePtrLocation { |
| 4050 | // Recursive call, use local PC-relative call instruction. |
| 4051 | kCallSelf, |
| 4052 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4053 | // Use code pointer from the ArtMethod*. |
| 4054 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4055 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4056 | kCallArtMethod, |
| 4057 | }; |
| 4058 | |
| 4059 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4060 | MethodLoadKind method_load_kind; |
| 4061 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4062 | // The method load data holds |
| 4063 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4064 | // Note that there are multiple string init methods, each having its own offset. |
| 4065 | // - the method address for kDirectAddress |
| 4066 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4067 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4068 | }; |
| 4069 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4070 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 4071 | uint32_t number_of_arguments, |
| 4072 | Primitive::Type return_type, |
| 4073 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4074 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4075 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4076 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4077 | InvokeType invoke_type, |
| 4078 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4079 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4080 | : HInvoke(arena, |
| 4081 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4082 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4083 | // potentially one other if the clinit check is explicit, and potentially |
| 4084 | // one other if the method is a string factory. |
| 4085 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4086 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4087 | return_type, |
| 4088 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4089 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4090 | resolved_method, |
| 4091 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4092 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4093 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4094 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4095 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4096 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4097 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4098 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4099 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4100 | |
| 4101 | // Using the current method is the default and once we find a better |
| 4102 | // method load kind, we should not go back to using the current method. |
| 4103 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4104 | |
| 4105 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4106 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4107 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4108 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4109 | dispatch_info_ = dispatch_info; |
| 4110 | } |
| 4111 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4112 | void AddSpecialInput(HInstruction* input) { |
| 4113 | // We allow only one special input. |
| 4114 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4115 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4116 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4117 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4118 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4119 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4120 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4121 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4122 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4123 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4124 | DCHECK(!input_records.empty()); |
| 4125 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4126 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4127 | // Note: `last_input` may be null during arguments setup. |
| 4128 | if (last_input != nullptr) { |
| 4129 | // `last_input` is the last input of a static invoke marked as having |
| 4130 | // an explicit clinit check. It must either be: |
| 4131 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4132 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4133 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4134 | } |
| 4135 | } |
| 4136 | return input_records; |
| 4137 | } |
| 4138 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4139 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4140 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4141 | // TODO: for intrinsics we can generate implicit null checks. |
| 4142 | return false; |
| 4143 | } |
| 4144 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4145 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4146 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4147 | } |
| 4148 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4149 | // Get the index of the special input, if any. |
| 4150 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4151 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4152 | // method pointer; otherwise there may be one platform-specific special input, |
| 4153 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4154 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4155 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4156 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4157 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4158 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4159 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4160 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4161 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4162 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4163 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4164 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 4165 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4166 | bool HasCurrentMethodInput() const { |
| 4167 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4168 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4169 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4170 | return true; |
| 4171 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4172 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4173 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4174 | return false; |
| 4175 | } |
| 4176 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4177 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4178 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4179 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4180 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | uint64_t GetMethodAddress() const { |
| 4184 | DCHECK(HasMethodAddress()); |
| 4185 | return dispatch_info_.method_load_data; |
| 4186 | } |
| 4187 | |
| 4188 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4189 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4190 | return dispatch_info_.method_load_data; |
| 4191 | } |
| 4192 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4193 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4194 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4195 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4196 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4197 | // Is this instruction a call to a static method? |
| 4198 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4199 | return GetInvokeType() == kStatic; |
| 4200 | } |
| 4201 | |
| 4202 | MethodReference GetTargetMethod() const { |
| 4203 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4204 | } |
| 4205 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4206 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4207 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4208 | // instruction; only relevant for static calls with explicit clinit check. |
| 4209 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4210 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4211 | size_t last_input_index = inputs_.size() - 1u; |
| 4212 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4213 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4214 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4215 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4216 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4217 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4218 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | // 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] | 4222 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4223 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4224 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4225 | } |
| 4226 | |
| 4227 | // Is this a call to a static method whose declaring class has an |
| 4228 | // implicit intialization check requirement? |
| 4229 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4230 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4231 | } |
| 4232 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4233 | // Does this method load kind need the current method as an input? |
| 4234 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4235 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4236 | } |
| 4237 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4238 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4239 | |
| 4240 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4241 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4242 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4243 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4244 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4245 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4246 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4247 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4248 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4249 | kFieldClinitCheckRequirement, |
| 4250 | kFieldClinitCheckRequirementSize>; |
| 4251 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4252 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4253 | MethodReference target_method_; |
| 4254 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4255 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4256 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4257 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4258 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4259 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4260 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4261 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4262 | public: |
| 4263 | HInvokeVirtual(ArenaAllocator* arena, |
| 4264 | uint32_t number_of_arguments, |
| 4265 | Primitive::Type return_type, |
| 4266 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4267 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4268 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4269 | uint32_t vtable_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4270 | : HInvoke(arena, |
| 4271 | number_of_arguments, |
| 4272 | 0u, |
| 4273 | return_type, |
| 4274 | dex_pc, |
| 4275 | dex_method_index, |
| 4276 | resolved_method, |
| 4277 | kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4278 | vtable_index_(vtable_index) {} |
| 4279 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4280 | bool CanBeNull() const OVERRIDE { |
| 4281 | switch (GetIntrinsic()) { |
| 4282 | case Intrinsics::kThreadCurrentThread: |
| 4283 | case Intrinsics::kStringBufferAppend: |
| 4284 | case Intrinsics::kStringBufferToString: |
| 4285 | case Intrinsics::kStringBuilderAppend: |
| 4286 | case Intrinsics::kStringBuilderToString: |
| 4287 | return false; |
| 4288 | default: |
| 4289 | return HInvoke::CanBeNull(); |
| 4290 | } |
| 4291 | } |
| 4292 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4293 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4294 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4295 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4296 | } |
| 4297 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4298 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4299 | |
| 4300 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4301 | |
| 4302 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4303 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4304 | const uint32_t vtable_index_; |
| 4305 | |
| 4306 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4307 | }; |
| 4308 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4309 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4310 | public: |
| 4311 | HInvokeInterface(ArenaAllocator* arena, |
| 4312 | uint32_t number_of_arguments, |
| 4313 | Primitive::Type return_type, |
| 4314 | uint32_t dex_pc, |
| 4315 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4316 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4317 | uint32_t imt_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4318 | : HInvoke(arena, |
| 4319 | number_of_arguments, |
| 4320 | 0u, |
| 4321 | return_type, |
| 4322 | dex_pc, |
| 4323 | dex_method_index, |
| 4324 | resolved_method, |
| 4325 | kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4326 | imt_index_(imt_index) {} |
| 4327 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4328 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4329 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4330 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4331 | } |
| 4332 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4333 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4334 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4335 | |
| 4336 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4337 | |
| 4338 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4339 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4340 | const uint32_t imt_index_; |
| 4341 | |
| 4342 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4343 | }; |
| 4344 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4345 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4346 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4347 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4348 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4349 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4350 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4351 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4352 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4353 | |
| 4354 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4355 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4356 | } |
| 4357 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4358 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4359 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4360 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4361 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4362 | } |
| 4363 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4364 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4365 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4366 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4367 | DECLARE_INSTRUCTION(Neg); |
| 4368 | |
| 4369 | private: |
| 4370 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4371 | }; |
| 4372 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4373 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4374 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4375 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4376 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4377 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4378 | dex::TypeIndex type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4379 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4380 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4381 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4382 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4383 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4384 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4385 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4386 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4387 | } |
| 4388 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4389 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4390 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4391 | |
| 4392 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4393 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4394 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4395 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4396 | bool CanThrow() const OVERRIDE { return true; } |
| 4397 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4398 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4399 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4400 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4401 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4402 | DECLARE_INSTRUCTION(NewArray); |
| 4403 | |
| 4404 | private: |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4405 | const dex::TypeIndex type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4406 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4407 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4408 | |
| 4409 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4410 | }; |
| 4411 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4412 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4413 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4414 | HAdd(Primitive::Type result_type, |
| 4415 | HInstruction* left, |
| 4416 | HInstruction* right, |
| 4417 | uint32_t dex_pc = kNoDexPc) |
| 4418 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4419 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4420 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4421 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4422 | 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] | 4423 | |
| 4424 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4425 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4426 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4427 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4428 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4429 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4430 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4431 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4432 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4433 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4434 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4435 | } |
| 4436 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4437 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4438 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4439 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4440 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4441 | DECLARE_INSTRUCTION(Add); |
| 4442 | |
| 4443 | private: |
| 4444 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4445 | }; |
| 4446 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4447 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4448 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4449 | HSub(Primitive::Type result_type, |
| 4450 | HInstruction* left, |
| 4451 | HInstruction* right, |
| 4452 | uint32_t dex_pc = kNoDexPc) |
| 4453 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4454 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4455 | 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] | 4456 | |
| 4457 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4458 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4459 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4460 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4461 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4462 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4463 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4464 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4465 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4466 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4467 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4468 | } |
| 4469 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4470 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4471 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4472 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4473 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4474 | DECLARE_INSTRUCTION(Sub); |
| 4475 | |
| 4476 | private: |
| 4477 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4478 | }; |
| 4479 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4480 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4481 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4482 | HMul(Primitive::Type result_type, |
| 4483 | HInstruction* left, |
| 4484 | HInstruction* right, |
| 4485 | uint32_t dex_pc = kNoDexPc) |
| 4486 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4487 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4488 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4489 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4490 | 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] | 4491 | |
| 4492 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4493 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4494 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4495 | } |
| 4496 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4497 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4498 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4499 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4500 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4501 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4502 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4503 | } |
| 4504 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4505 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4506 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4507 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4508 | |
| 4509 | DECLARE_INSTRUCTION(Mul); |
| 4510 | |
| 4511 | private: |
| 4512 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4513 | }; |
| 4514 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4515 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4516 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4517 | HDiv(Primitive::Type result_type, |
| 4518 | HInstruction* left, |
| 4519 | HInstruction* right, |
| 4520 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4521 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4522 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4523 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4524 | T ComputeIntegral(T x, T y) const { |
| 4525 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4526 | // Our graph structure ensures we never have 0 for `y` during |
| 4527 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4528 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4529 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4530 | return (y == -1) ? -x : x / y; |
| 4531 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4532 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4533 | template <typename T> |
| 4534 | T ComputeFP(T x, T y) const { |
| 4535 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4536 | return x / y; |
| 4537 | } |
| 4538 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4539 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4540 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4541 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4542 | } |
| 4543 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4544 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4545 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4546 | } |
| 4547 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4548 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4549 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4550 | } |
| 4551 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4552 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4553 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4554 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4555 | |
| 4556 | DECLARE_INSTRUCTION(Div); |
| 4557 | |
| 4558 | private: |
| 4559 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4560 | }; |
| 4561 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4562 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4563 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4564 | HRem(Primitive::Type result_type, |
| 4565 | HInstruction* left, |
| 4566 | HInstruction* right, |
| 4567 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4568 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4569 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4570 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4571 | T ComputeIntegral(T x, T y) const { |
| 4572 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4573 | // Our graph structure ensures we never have 0 for `y` during |
| 4574 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4575 | DCHECK_NE(y, 0); |
| 4576 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4577 | return (y == -1) ? 0 : x % y; |
| 4578 | } |
| 4579 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4580 | template <typename T> |
| 4581 | T ComputeFP(T x, T y) const { |
| 4582 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4583 | return std::fmod(x, y); |
| 4584 | } |
| 4585 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4586 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4587 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4588 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4589 | } |
| 4590 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4591 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4592 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4593 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4594 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4595 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4596 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4597 | } |
| 4598 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4599 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4600 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4601 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4602 | |
| 4603 | DECLARE_INSTRUCTION(Rem); |
| 4604 | |
| 4605 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4606 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4607 | }; |
| 4608 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4609 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4610 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4611 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4612 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4613 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4614 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4615 | SetRawInputAt(0, value); |
| 4616 | } |
| 4617 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4618 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4619 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4620 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4621 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4622 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4623 | return true; |
| 4624 | } |
| 4625 | |
| 4626 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4627 | bool CanThrow() const OVERRIDE { return true; } |
| 4628 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4629 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4630 | |
| 4631 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4632 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4633 | }; |
| 4634 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4635 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4636 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4637 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4638 | HInstruction* value, |
| 4639 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4640 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4641 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4642 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4643 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4644 | } |
| 4645 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4646 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4647 | 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] | 4648 | return value << (distance & max_shift_distance); |
| 4649 | } |
| 4650 | |
| 4651 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4652 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4653 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), 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, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4656 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4657 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4658 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4659 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4660 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4661 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4662 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4663 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4664 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4665 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4666 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4667 | UNREACHABLE(); |
| 4668 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4669 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4670 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4671 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4672 | UNREACHABLE(); |
| 4673 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4674 | |
| 4675 | DECLARE_INSTRUCTION(Shl); |
| 4676 | |
| 4677 | private: |
| 4678 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4679 | }; |
| 4680 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4681 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4682 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4683 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4684 | HInstruction* value, |
| 4685 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4686 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4687 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4688 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4689 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4690 | } |
| 4691 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4692 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4693 | 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] | 4694 | return value >> (distance & max_shift_distance); |
| 4695 | } |
| 4696 | |
| 4697 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4698 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4699 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4700 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4701 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4702 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4703 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4704 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4705 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4706 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4707 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4708 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4709 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4710 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4711 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4712 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4713 | UNREACHABLE(); |
| 4714 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4715 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4716 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4717 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4718 | UNREACHABLE(); |
| 4719 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4720 | |
| 4721 | DECLARE_INSTRUCTION(Shr); |
| 4722 | |
| 4723 | private: |
| 4724 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4725 | }; |
| 4726 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4727 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4728 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4729 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4730 | HInstruction* value, |
| 4731 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4732 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4733 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4734 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4735 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4738 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4739 | 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] | 4740 | typedef typename std::make_unsigned<T>::type V; |
| 4741 | V ux = static_cast<V>(value); |
| 4742 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4743 | } |
| 4744 | |
| 4745 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4746 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4747 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4748 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4749 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4750 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4751 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4752 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4753 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4754 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4755 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4756 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4757 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4758 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4759 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4760 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4761 | UNREACHABLE(); |
| 4762 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4763 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4764 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4765 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4766 | UNREACHABLE(); |
| 4767 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4768 | |
| 4769 | DECLARE_INSTRUCTION(UShr); |
| 4770 | |
| 4771 | private: |
| 4772 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4773 | }; |
| 4774 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4775 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4776 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4777 | HAnd(Primitive::Type result_type, |
| 4778 | HInstruction* left, |
| 4779 | HInstruction* right, |
| 4780 | uint32_t dex_pc = kNoDexPc) |
| 4781 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4782 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4783 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4784 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4785 | 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] | 4786 | |
| 4787 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4788 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4789 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4790 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4791 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4792 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4793 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4794 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4795 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4796 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4797 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4798 | UNREACHABLE(); |
| 4799 | } |
| 4800 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4801 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4802 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4803 | UNREACHABLE(); |
| 4804 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4805 | |
| 4806 | DECLARE_INSTRUCTION(And); |
| 4807 | |
| 4808 | private: |
| 4809 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4810 | }; |
| 4811 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4812 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4813 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4814 | HOr(Primitive::Type result_type, |
| 4815 | HInstruction* left, |
| 4816 | HInstruction* right, |
| 4817 | uint32_t dex_pc = kNoDexPc) |
| 4818 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4819 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4820 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4821 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4822 | 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] | 4823 | |
| 4824 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4825 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4826 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4827 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4828 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4829 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4830 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4831 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4832 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4833 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4834 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4835 | UNREACHABLE(); |
| 4836 | } |
| 4837 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4838 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4839 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4840 | UNREACHABLE(); |
| 4841 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4842 | |
| 4843 | DECLARE_INSTRUCTION(Or); |
| 4844 | |
| 4845 | private: |
| 4846 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4847 | }; |
| 4848 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4849 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4850 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4851 | HXor(Primitive::Type result_type, |
| 4852 | HInstruction* left, |
| 4853 | HInstruction* right, |
| 4854 | uint32_t dex_pc = kNoDexPc) |
| 4855 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4856 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4857 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4858 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4859 | 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] | 4860 | |
| 4861 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4862 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4863 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4864 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4865 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4866 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4867 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4868 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4869 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4870 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4871 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4872 | UNREACHABLE(); |
| 4873 | } |
| 4874 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4875 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4876 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4877 | UNREACHABLE(); |
| 4878 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4879 | |
| 4880 | DECLARE_INSTRUCTION(Xor); |
| 4881 | |
| 4882 | private: |
| 4883 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4884 | }; |
| 4885 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4886 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4887 | public: |
| 4888 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4889 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4890 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4891 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4892 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4893 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4894 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4895 | 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] | 4896 | typedef typename std::make_unsigned<T>::type V; |
| 4897 | V ux = static_cast<V>(value); |
| 4898 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4899 | return static_cast<T>(ux); |
| 4900 | } else { |
| 4901 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4902 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4903 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4904 | } |
| 4905 | } |
| 4906 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4907 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4908 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4909 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4910 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4911 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4912 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4913 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4914 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4915 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4916 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4917 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4918 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4919 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4920 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4921 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4922 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4923 | UNREACHABLE(); |
| 4924 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4925 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4926 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4927 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4928 | UNREACHABLE(); |
| 4929 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4930 | |
| 4931 | DECLARE_INSTRUCTION(Ror); |
| 4932 | |
| 4933 | private: |
| 4934 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4935 | }; |
| 4936 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4937 | // The value of a parameter in this method. Its location depends on |
| 4938 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4939 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4940 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4941 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4942 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4943 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4944 | Primitive::Type parameter_type, |
| 4945 | bool is_this = false) |
| 4946 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4947 | dex_file_(dex_file), |
| 4948 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4949 | index_(index) { |
| 4950 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4951 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4952 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4953 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4954 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4955 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4956 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4957 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4958 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4959 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4960 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4961 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4962 | DECLARE_INSTRUCTION(ParameterValue); |
| 4963 | |
| 4964 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4965 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4966 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4967 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4968 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4969 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4970 | "Too many packed fields."); |
| 4971 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4972 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4973 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4974 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4975 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4976 | const uint8_t index_; |
| 4977 | |
| 4978 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4979 | }; |
| 4980 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4981 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4982 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4983 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4984 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4985 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4986 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4987 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4988 | return true; |
| 4989 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4990 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4991 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4992 | |
| 4993 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4994 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4995 | } |
| 4996 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4997 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4998 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4999 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5000 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5001 | UNREACHABLE(); |
| 5002 | } |
| 5003 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5004 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5005 | UNREACHABLE(); |
| 5006 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5007 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5008 | DECLARE_INSTRUCTION(Not); |
| 5009 | |
| 5010 | private: |
| 5011 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 5012 | }; |
| 5013 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5014 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5015 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5016 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5017 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5018 | |
| 5019 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5020 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5021 | return true; |
| 5022 | } |
| 5023 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5024 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5025 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5026 | return !x; |
| 5027 | } |
| 5028 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5029 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5030 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5031 | } |
| 5032 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5033 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5034 | UNREACHABLE(); |
| 5035 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5036 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5037 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5038 | UNREACHABLE(); |
| 5039 | } |
| 5040 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5041 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5042 | UNREACHABLE(); |
| 5043 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5044 | |
| 5045 | DECLARE_INSTRUCTION(BooleanNot); |
| 5046 | |
| 5047 | private: |
| 5048 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 5049 | }; |
| 5050 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5051 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5052 | public: |
| 5053 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 5054 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5055 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5056 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5057 | // Invariant: We should never generate a conversion to a Boolean value. |
| 5058 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5059 | } |
| 5060 | |
| 5061 | HInstruction* GetInput() const { return InputAt(0); } |
| 5062 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 5063 | Primitive::Type GetResultType() const { return GetType(); } |
| 5064 | |
| 5065 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5066 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5067 | return true; |
| 5068 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5069 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5070 | // Try to statically evaluate the conversion and return a HConstant |
| 5071 | // containing the result. If the input cannot be converted, return nullptr. |
| 5072 | HConstant* TryStaticEvaluation() const; |
| 5073 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5074 | DECLARE_INSTRUCTION(TypeConversion); |
| 5075 | |
| 5076 | private: |
| 5077 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 5078 | }; |
| 5079 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5080 | static constexpr uint32_t kNoRegNumber = -1; |
| 5081 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5082 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5083 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5084 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 5085 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5086 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5087 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5088 | SetRawInputAt(0, value); |
| 5089 | } |
| 5090 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5091 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5092 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5093 | return true; |
| 5094 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5095 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5096 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5097 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5098 | bool CanThrow() const OVERRIDE { return true; } |
| 5099 | |
| 5100 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5101 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5102 | |
| 5103 | DECLARE_INSTRUCTION(NullCheck); |
| 5104 | |
| 5105 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5106 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 5107 | }; |
| 5108 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5109 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5110 | // that information to avoid requiring the mutator lock every time we need it. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5111 | class FieldInfo : public ValueObject { |
| 5112 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5113 | FieldInfo(ArtField* field, |
| 5114 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5115 | Primitive::Type field_type, |
| 5116 | bool is_volatile, |
| 5117 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5118 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5119 | const DexFile& dex_file) |
| 5120 | : field_(field), |
| 5121 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5122 | field_type_(field_type), |
| 5123 | is_volatile_(is_volatile), |
| 5124 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5125 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5126 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5127 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5128 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5129 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5130 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5131 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5132 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5133 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5134 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5135 | |
| 5136 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5137 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5138 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5139 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5140 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5141 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5142 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5143 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5144 | }; |
| 5145 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5146 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5147 | public: |
| 5148 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5149 | ArtField* field, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5150 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5151 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5152 | bool is_volatile, |
| 5153 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5154 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5155 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5156 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5157 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5158 | field_info_(field, |
| 5159 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5160 | field_type, |
| 5161 | is_volatile, |
| 5162 | field_idx, |
| 5163 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5164 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5165 | SetRawInputAt(0, value); |
| 5166 | } |
| 5167 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5168 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5169 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5170 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5171 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5172 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5173 | } |
| 5174 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5175 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5176 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5180 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5181 | } |
| 5182 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5183 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5184 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5185 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5186 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5187 | |
| 5188 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5189 | |
| 5190 | private: |
| 5191 | const FieldInfo field_info_; |
| 5192 | |
| 5193 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5194 | }; |
| 5195 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5196 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5197 | public: |
| 5198 | HInstanceFieldSet(HInstruction* object, |
| 5199 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5200 | ArtField* field, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5201 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5202 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5203 | bool is_volatile, |
| 5204 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5205 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5206 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5207 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5208 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5209 | field_info_(field, |
| 5210 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5211 | field_type, |
| 5212 | is_volatile, |
| 5213 | field_idx, |
| 5214 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5215 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5216 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5217 | SetRawInputAt(0, object); |
| 5218 | SetRawInputAt(1, value); |
| 5219 | } |
| 5220 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5221 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5222 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5223 | } |
| 5224 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5225 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5226 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5227 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5228 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5229 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5230 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5231 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5232 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5233 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5234 | |
| 5235 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5236 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5237 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5238 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5239 | "Too many packed fields."); |
| 5240 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5241 | const FieldInfo field_info_; |
| 5242 | |
| 5243 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5244 | }; |
| 5245 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5246 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5247 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5248 | HArrayGet(HInstruction* array, |
| 5249 | HInstruction* index, |
| 5250 | Primitive::Type type, |
| 5251 | uint32_t dex_pc, |
| 5252 | bool is_string_char_at = false) |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5253 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5254 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5255 | SetRawInputAt(0, array); |
| 5256 | SetRawInputAt(1, index); |
| 5257 | } |
| 5258 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5259 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5260 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5261 | return true; |
| 5262 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5263 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5264 | // TODO: We can be smarter here. |
| 5265 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5266 | // which generates the implicit null check. There are cases when these can be removed |
| 5267 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5268 | // implicit check here (as long as the address falls in the first page). |
| 5269 | return false; |
| 5270 | } |
| 5271 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5272 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5273 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5274 | if (kIsDebugBuild && result) { |
| 5275 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5276 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5277 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5278 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5279 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5280 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5281 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5282 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5283 | } |
| 5284 | } |
| 5285 | return result; |
| 5286 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5287 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5288 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5289 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5290 | HInstruction* GetArray() const { return InputAt(0); } |
| 5291 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5292 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5293 | DECLARE_INSTRUCTION(ArrayGet); |
| 5294 | |
| 5295 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5296 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5297 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5298 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5299 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5300 | // a flag, so that code generators don't need to do the locking. |
| 5301 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5302 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5303 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5304 | "Too many packed fields."); |
| 5305 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5306 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5307 | }; |
| 5308 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5309 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5310 | public: |
| 5311 | HArraySet(HInstruction* array, |
| 5312 | HInstruction* index, |
| 5313 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5314 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5315 | uint32_t dex_pc) |
| 5316 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5317 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5318 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5319 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5320 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5321 | SetRawInputAt(0, array); |
| 5322 | SetRawInputAt(1, index); |
| 5323 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5324 | // Make a best guess now, may be refined during SSA building. |
| 5325 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5326 | } |
| 5327 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5328 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5329 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5330 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5331 | } |
| 5332 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5333 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5334 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5335 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5336 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5337 | // TODO: Same as for ArrayGet. |
| 5338 | return false; |
| 5339 | } |
| 5340 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5341 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5342 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5343 | } |
| 5344 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5345 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5346 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5347 | } |
| 5348 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5349 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5350 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5351 | } |
| 5352 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5353 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5354 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5355 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5356 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5357 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5358 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5359 | HInstruction* GetArray() const { return InputAt(0); } |
| 5360 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5361 | HInstruction* GetValue() const { return InputAt(2); } |
| 5362 | |
| 5363 | Primitive::Type GetComponentType() const { |
| 5364 | // The Dex format does not type floating point index operations. Since the |
| 5365 | // `expected_component_type_` is set during building and can therefore not |
| 5366 | // be correct, we also check what is the value type. If it is a floating |
| 5367 | // point type, we must use that type. |
| 5368 | Primitive::Type value_type = GetValue()->GetType(); |
| 5369 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5370 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5371 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5372 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5373 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5374 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5375 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5376 | } |
| 5377 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5378 | void ComputeSideEffects() { |
| 5379 | Primitive::Type type = GetComponentType(); |
| 5380 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5381 | SideEffectsForArchRuntimeCalls(type))); |
| 5382 | } |
| 5383 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5384 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5385 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5386 | } |
| 5387 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5388 | DECLARE_INSTRUCTION(ArraySet); |
| 5389 | |
| 5390 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5391 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5392 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5393 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5394 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5395 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5396 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5397 | // Cached information for the reference_type_info_ so that codegen |
| 5398 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5399 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5400 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5401 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5402 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5403 | using ExpectedComponentTypeField = |
| 5404 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5405 | |
| 5406 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5407 | }; |
| 5408 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5409 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5410 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5411 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5412 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5413 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5414 | // Note that arrays do not change length, so the instruction does not |
| 5415 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5416 | SetRawInputAt(0, array); |
| 5417 | } |
| 5418 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5419 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5420 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5421 | return true; |
| 5422 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5423 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5424 | return obj == InputAt(0); |
| 5425 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5426 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5427 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5428 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5429 | DECLARE_INSTRUCTION(ArrayLength); |
| 5430 | |
| 5431 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5432 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5433 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5434 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5435 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5436 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5437 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5438 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5439 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5440 | "Too many packed fields."); |
| 5441 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5442 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5443 | }; |
| 5444 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5445 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5446 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5447 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5448 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5449 | HBoundsCheck(HInstruction* index, |
| 5450 | HInstruction* length, |
| 5451 | uint32_t dex_pc, |
| 5452 | uint32_t string_char_at_method_index = DexFile::kDexNoIndex) |
| 5453 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc), |
| 5454 | string_char_at_method_index_(string_char_at_method_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5455 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5456 | SetRawInputAt(0, index); |
| 5457 | SetRawInputAt(1, length); |
| 5458 | } |
| 5459 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5460 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5461 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5462 | return true; |
| 5463 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5464 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5465 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5466 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5467 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5468 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5469 | bool IsStringCharAt() const { return GetStringCharAtMethodIndex() != DexFile::kDexNoIndex; } |
| 5470 | uint32_t GetStringCharAtMethodIndex() const { return string_char_at_method_index_; } |
| 5471 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5472 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5473 | |
| 5474 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5475 | |
| 5476 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5477 | // We treat a String as an array, creating the HBoundsCheck from String.charAt() |
| 5478 | // intrinsic in the instruction simplifier. We want to include the String.charAt() |
| 5479 | // in the stack trace if we actually throw the StringIndexOutOfBoundsException, |
| 5480 | // so we need to create an HEnvironment which will be translated to an InlineInfo |
| 5481 | // indicating the extra stack frame. Since we add this HEnvironment quite late, |
| 5482 | // in the PrepareForRegisterAllocation pass, we need to remember the method index |
| 5483 | // from the invoke as we don't want to look again at the dex bytecode. |
| 5484 | uint32_t string_char_at_method_index_; // DexFile::kDexNoIndex if regular array. |
| 5485 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5486 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5487 | }; |
| 5488 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5489 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5490 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5491 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5492 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5493 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5494 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5495 | return true; |
| 5496 | } |
| 5497 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5498 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5499 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5500 | |
| 5501 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5502 | |
| 5503 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5504 | // Only used for code generation, in order to share the same slow path between back edges |
| 5505 | // of a same loop. |
| 5506 | SlowPathCode* slow_path_; |
| 5507 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5508 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5509 | }; |
| 5510 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5511 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5512 | // It ensures that we can generate line number and local variables at this point. |
| 5513 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5514 | public: |
| 5515 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5516 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5517 | |
| 5518 | bool NeedsEnvironment() const OVERRIDE { |
| 5519 | return true; |
| 5520 | } |
| 5521 | |
| 5522 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5523 | |
| 5524 | private: |
| 5525 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5526 | }; |
| 5527 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5528 | /** |
| 5529 | * Instruction to load a Class object. |
| 5530 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5531 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5532 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5533 | // Determines how to load the Class. |
| 5534 | enum class LoadKind { |
| 5535 | // Use the Class* from the method's own ArtMethod*. |
| 5536 | kReferrersClass, |
| 5537 | |
| 5538 | // Use boot image Class* address that will be known at link time. |
| 5539 | // Used for boot image classes referenced by boot image code in non-PIC mode. |
| 5540 | kBootImageLinkTimeAddress, |
| 5541 | |
| 5542 | // Use PC-relative boot image Class* address that will be known at link time. |
| 5543 | // Used for boot image classes referenced by boot image code in PIC mode. |
| 5544 | kBootImageLinkTimePcRelative, |
| 5545 | |
| 5546 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5547 | // Used for boot image classes referenced by apps in AOT- and JIT-compiled code. |
| 5548 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5549 | // GetIncludePatchInformation(). |
| 5550 | kBootImageAddress, |
| 5551 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5552 | // Load from the root table associated with the JIT compiled method. |
| 5553 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5554 | |
| 5555 | // Load from resolved types array in the dex cache using a PC-relative load. |
| 5556 | // Used for classes outside boot image when we know that we can access |
| 5557 | // the dex cache arrays using a PC-relative load. |
| 5558 | kDexCachePcRelative, |
| 5559 | |
| 5560 | // Load from resolved types array accessed through the class loaded from |
| 5561 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5562 | // all other types are unavailable. |
| 5563 | kDexCacheViaMethod, |
| 5564 | |
| 5565 | kLast = kDexCacheViaMethod |
| 5566 | }; |
| 5567 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5568 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5569 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5570 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5571 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5572 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5573 | bool needs_access_check) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5574 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5575 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5576 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5577 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5578 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5579 | // Referrers class should not need access check. We never inline unverified |
| 5580 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5581 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5582 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5583 | SetPackedField<LoadKindField>( |
| 5584 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kDexCacheViaMethod); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5585 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5586 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5587 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5588 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5592 | DCHECK(HasAddress(load_kind)); |
| 5593 | load_data_.address = address; |
| 5594 | SetLoadKindInternal(load_kind); |
| 5595 | } |
| 5596 | |
| 5597 | void SetLoadKindWithTypeReference(LoadKind load_kind, |
| 5598 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5599 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5600 | DCHECK(HasTypeReference(load_kind)); |
| 5601 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5602 | DCHECK_EQ(type_index_, type_index); |
| 5603 | SetLoadKindInternal(load_kind); |
| 5604 | } |
| 5605 | |
| 5606 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5607 | const DexFile& dex_file, |
| 5608 | uint32_t element_index) { |
| 5609 | DCHECK(HasDexCacheReference(load_kind)); |
| 5610 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5611 | load_data_.dex_cache_element_index = element_index; |
| 5612 | SetLoadKindInternal(load_kind); |
| 5613 | } |
| 5614 | |
| 5615 | LoadKind GetLoadKind() const { |
| 5616 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5617 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5618 | |
| 5619 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5620 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5621 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5622 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5623 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5624 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5625 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5626 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5627 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5628 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5629 | } |
| 5630 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5631 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5632 | // The entrypoint the code generator is going to call does not do |
| 5633 | // clinit of the class. |
| 5634 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5635 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
| 5638 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5639 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5640 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5641 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5642 | } |
| 5643 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5644 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5645 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5646 | } |
| 5647 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5648 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5649 | return loaded_class_rti_; |
| 5650 | } |
| 5651 | |
| 5652 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5653 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5654 | DCHECK(rti.IsExact()); |
| 5655 | loaded_class_rti_ = rti; |
| 5656 | } |
| 5657 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5658 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5659 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5660 | |
| 5661 | uint32_t GetDexCacheElementOffset() const; |
| 5662 | |
| 5663 | uint64_t GetAddress() const { |
| 5664 | DCHECK(HasAddress(GetLoadKind())); |
| 5665 | return load_data_.address; |
| 5666 | } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5667 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5668 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5669 | return !IsReferrersClass(); |
| 5670 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5671 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5672 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5673 | return SideEffects::CanTriggerGC(); |
| 5674 | } |
| 5675 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5676 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5677 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5678 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5679 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5680 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5681 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5682 | void MarkInDexCache() { |
| 5683 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5684 | DCHECK(!NeedsEnvironment()); |
| 5685 | RemoveEnvironment(); |
| 5686 | SetSideEffects(SideEffects::None()); |
| 5687 | } |
| 5688 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5689 | void MarkInBootImage() { |
| 5690 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 5691 | } |
| 5692 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5693 | void AddSpecialInput(HInstruction* special_input); |
| 5694 | |
| 5695 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5696 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5697 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5698 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 5699 | } |
| 5700 | |
| 5701 | Primitive::Type GetType() const OVERRIDE { |
| 5702 | return Primitive::kPrimNot; |
| 5703 | } |
| 5704 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5705 | DECLARE_INSTRUCTION(LoadClass); |
| 5706 | |
| 5707 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5708 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5709 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5710 | static constexpr size_t kFlagIsInBootImage = kFlagIsInDexCache + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5711 | // Whether this instruction must generate the initialization check. |
| 5712 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5713 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5714 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 5715 | static constexpr size_t kFieldLoadKindSize = |
| 5716 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5717 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5718 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5719 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 5720 | |
| 5721 | static bool HasTypeReference(LoadKind load_kind) { |
| 5722 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5723 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5724 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5725 | load_kind == LoadKind::kReferrersClass; |
| 5726 | } |
| 5727 | |
| 5728 | static bool HasAddress(LoadKind load_kind) { |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5729 | return load_kind == LoadKind::kBootImageAddress || |
| 5730 | load_kind == LoadKind::kJitTableAddress; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5731 | } |
| 5732 | |
| 5733 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5734 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5735 | } |
| 5736 | |
| 5737 | void SetLoadKindInternal(LoadKind load_kind); |
| 5738 | |
| 5739 | // The special input is the HCurrentMethod for kDexCacheViaMethod or kReferrersClass. |
| 5740 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5741 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
| 5742 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5743 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5744 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5745 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5746 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5747 | union { |
| 5748 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5749 | 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] | 5750 | } load_data_; |
| 5751 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5752 | ReferenceTypeInfo loaded_class_rti_; |
| 5753 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5754 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5755 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5756 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 5757 | |
| 5758 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5759 | inline uint32_t HLoadClass::GetDexCacheElementOffset() const { |
| 5760 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5761 | return load_data_.dex_cache_element_index; |
| 5762 | } |
| 5763 | |
| 5764 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5765 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5766 | // The special input is used for PC-relative loads on some architectures, |
| 5767 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5768 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5769 | GetLoadKind() == LoadKind::kDexCachePcRelative || |
| 5770 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5771 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5772 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5773 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 5774 | special_input->AddUseAt(this, 0); |
| 5775 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5776 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5777 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5778 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5779 | // Determines how to load the String. |
| 5780 | enum class LoadKind { |
| 5781 | // Use boot image String* address that will be known at link time. |
| 5782 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5783 | kBootImageLinkTimeAddress, |
| 5784 | |
| 5785 | // Use PC-relative boot image String* address that will be known at link time. |
| 5786 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5787 | kBootImageLinkTimePcRelative, |
| 5788 | |
| 5789 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5790 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5791 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5792 | // GetIncludePatchInformation(). |
| 5793 | kBootImageAddress, |
| 5794 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5795 | // Load from an entry in the .bss section using a PC-relative load. |
| 5796 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 5797 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5798 | |
| 5799 | // Load from resolved strings array accessed through the class loaded from |
| 5800 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5801 | // all other types are unavailable. |
| 5802 | kDexCacheViaMethod, |
| 5803 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5804 | // Load from the root table associated with the JIT compiled method. |
| 5805 | kJitTableAddress, |
| 5806 | |
| 5807 | kLast = kJitTableAddress, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5808 | }; |
| 5809 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5810 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5811 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5812 | const DexFile& dex_file, |
| 5813 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5814 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5815 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5816 | string_index_(string_index), |
| 5817 | dex_file_(dex_file) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5818 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5819 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5820 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5821 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5822 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5823 | LoadKind GetLoadKind() const { |
| 5824 | return GetPackedField<LoadKindField>(); |
| 5825 | } |
| 5826 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5827 | const DexFile& GetDexFile() const { |
| 5828 | return dex_file_; |
| 5829 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5830 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5831 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5832 | return string_index_; |
| 5833 | } |
| 5834 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5835 | Handle<mirror::String> GetString() const { |
| 5836 | return string_; |
| 5837 | } |
| 5838 | |
| 5839 | void SetString(Handle<mirror::String> str) { |
| 5840 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5841 | } |
| 5842 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5843 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5844 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5845 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5846 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5847 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5848 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5849 | // Will call the runtime if we need to load the string through |
| 5850 | // the dex cache and the string is not guaranteed to be there yet. |
| 5851 | bool NeedsEnvironment() const OVERRIDE { |
| 5852 | LoadKind load_kind = GetLoadKind(); |
| 5853 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5854 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5855 | load_kind == LoadKind::kBootImageAddress || |
| 5856 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5857 | return false; |
| 5858 | } |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 5859 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5860 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5861 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5862 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5863 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5864 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5865 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5866 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5867 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5868 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5869 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5870 | return SideEffects::CanTriggerGC(); |
| 5871 | } |
| 5872 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5873 | void AddSpecialInput(HInstruction* special_input); |
| 5874 | |
| 5875 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5876 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5877 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5878 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5879 | } |
| 5880 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5881 | Primitive::Type GetType() const OVERRIDE { |
| 5882 | return Primitive::kPrimNot; |
| 5883 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5884 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5885 | DECLARE_INSTRUCTION(LoadString); |
| 5886 | |
| 5887 | private: |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 5888 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5889 | static constexpr size_t kFieldLoadKindSize = |
| 5890 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5891 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5892 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5893 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5894 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5895 | void SetLoadKindInternal(LoadKind load_kind); |
| 5896 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5897 | // The special input is the HCurrentMethod for kDexCacheViaMethod. |
| 5898 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5899 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5900 | HUserRecord<HInstruction*> special_input_; |
| 5901 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5902 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5903 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5904 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5905 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5906 | |
| 5907 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5908 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5909 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5910 | |
| 5911 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5912 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5913 | // The special input is used for PC-relative loads on some architectures, |
| 5914 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5915 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5916 | GetLoadKind() == LoadKind::kBssEntry || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5917 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5918 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5919 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5920 | // so use the GetInputRecords() from the base class to set the input record. |
| 5921 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5922 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5923 | special_input->AddUseAt(this, 0); |
| 5924 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5925 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5926 | /** |
| 5927 | * Performs an initialization check on its Class object input. |
| 5928 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5929 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5930 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5931 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5932 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5933 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5934 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5935 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5936 | SetRawInputAt(0, constant); |
| 5937 | } |
| 5938 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5939 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5940 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5941 | return true; |
| 5942 | } |
| 5943 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5944 | bool NeedsEnvironment() const OVERRIDE { |
| 5945 | // May call runtime to initialize the class. |
| 5946 | return true; |
| 5947 | } |
| 5948 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5949 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5950 | |
| 5951 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5952 | |
| 5953 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5954 | |
| 5955 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5956 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5957 | }; |
| 5958 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5959 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5960 | public: |
| 5961 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5962 | ArtField* field, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5963 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5964 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5965 | bool is_volatile, |
| 5966 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5967 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5968 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5969 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5970 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5971 | field_info_(field, |
| 5972 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5973 | field_type, |
| 5974 | is_volatile, |
| 5975 | field_idx, |
| 5976 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5977 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5978 | SetRawInputAt(0, cls); |
| 5979 | } |
| 5980 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5981 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5982 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5983 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5984 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5985 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5986 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5987 | } |
| 5988 | |
| 5989 | size_t ComputeHashCode() const OVERRIDE { |
| 5990 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5991 | } |
| 5992 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5993 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5994 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5995 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5996 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5997 | |
| 5998 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5999 | |
| 6000 | private: |
| 6001 | const FieldInfo field_info_; |
| 6002 | |
| 6003 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 6004 | }; |
| 6005 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6006 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6007 | public: |
| 6008 | HStaticFieldSet(HInstruction* cls, |
| 6009 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6010 | ArtField* field, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6011 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6012 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6013 | bool is_volatile, |
| 6014 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6015 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6016 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6017 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 6018 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6019 | field_info_(field, |
| 6020 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6021 | field_type, |
| 6022 | is_volatile, |
| 6023 | field_idx, |
| 6024 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6025 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6026 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6027 | SetRawInputAt(0, cls); |
| 6028 | SetRawInputAt(1, value); |
| 6029 | } |
| 6030 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6031 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6032 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 6033 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6034 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6035 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6036 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6037 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6038 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6039 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6040 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6041 | |
| 6042 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6043 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6044 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6045 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6046 | "Too many packed fields."); |
| 6047 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6048 | const FieldInfo field_info_; |
| 6049 | |
| 6050 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 6051 | }; |
| 6052 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6053 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6054 | public: |
| 6055 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 6056 | Primitive::Type field_type, |
| 6057 | uint32_t field_index, |
| 6058 | uint32_t dex_pc) |
| 6059 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6060 | field_index_(field_index) { |
| 6061 | SetRawInputAt(0, obj); |
| 6062 | } |
| 6063 | |
| 6064 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6065 | bool CanThrow() const OVERRIDE { return true; } |
| 6066 | |
| 6067 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6068 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6069 | |
| 6070 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6071 | |
| 6072 | private: |
| 6073 | const uint32_t field_index_; |
| 6074 | |
| 6075 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 6076 | }; |
| 6077 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6078 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6079 | public: |
| 6080 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6081 | HInstruction* value, |
| 6082 | Primitive::Type field_type, |
| 6083 | uint32_t field_index, |
| 6084 | uint32_t dex_pc) |
| 6085 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6086 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6087 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6088 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6089 | SetRawInputAt(0, obj); |
| 6090 | SetRawInputAt(1, value); |
| 6091 | } |
| 6092 | |
| 6093 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6094 | bool CanThrow() const OVERRIDE { return true; } |
| 6095 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6096 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6097 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6098 | |
| 6099 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6100 | |
| 6101 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6102 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6103 | static constexpr size_t kFieldFieldTypeSize = |
| 6104 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6105 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6106 | kFieldFieldType + kFieldFieldTypeSize; |
| 6107 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6108 | "Too many packed fields."); |
| 6109 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6110 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6111 | const uint32_t field_index_; |
| 6112 | |
| 6113 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 6114 | }; |
| 6115 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6116 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6117 | public: |
| 6118 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 6119 | uint32_t field_index, |
| 6120 | uint32_t dex_pc) |
| 6121 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6122 | field_index_(field_index) { |
| 6123 | } |
| 6124 | |
| 6125 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6126 | bool CanThrow() const OVERRIDE { return true; } |
| 6127 | |
| 6128 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6129 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6130 | |
| 6131 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6132 | |
| 6133 | private: |
| 6134 | const uint32_t field_index_; |
| 6135 | |
| 6136 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 6137 | }; |
| 6138 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6139 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6140 | public: |
| 6141 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 6142 | Primitive::Type field_type, |
| 6143 | uint32_t field_index, |
| 6144 | uint32_t dex_pc) |
| 6145 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6146 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6147 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6148 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6149 | SetRawInputAt(0, value); |
| 6150 | } |
| 6151 | |
| 6152 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6153 | bool CanThrow() const OVERRIDE { return true; } |
| 6154 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6155 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6156 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6157 | |
| 6158 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6159 | |
| 6160 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6161 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6162 | static constexpr size_t kFieldFieldTypeSize = |
| 6163 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6164 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6165 | kFieldFieldType + kFieldFieldTypeSize; |
| 6166 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6167 | "Too many packed fields."); |
| 6168 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6169 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6170 | const uint32_t field_index_; |
| 6171 | |
| 6172 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6173 | }; |
| 6174 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6175 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6176 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6177 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6178 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6179 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6180 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6181 | bool CanBeNull() const OVERRIDE { return false; } |
| 6182 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6183 | DECLARE_INSTRUCTION(LoadException); |
| 6184 | |
| 6185 | private: |
| 6186 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6187 | }; |
| 6188 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6189 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6190 | // 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] | 6191 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6192 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6193 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6194 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6195 | |
| 6196 | DECLARE_INSTRUCTION(ClearException); |
| 6197 | |
| 6198 | private: |
| 6199 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6200 | }; |
| 6201 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6202 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6203 | public: |
| 6204 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6205 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6206 | SetRawInputAt(0, exception); |
| 6207 | } |
| 6208 | |
| 6209 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6210 | |
| 6211 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6212 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6213 | bool CanThrow() const OVERRIDE { return true; } |
| 6214 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6215 | |
| 6216 | DECLARE_INSTRUCTION(Throw); |
| 6217 | |
| 6218 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6219 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6220 | }; |
| 6221 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6222 | /** |
| 6223 | * Implementation strategies for the code generator of a HInstanceOf |
| 6224 | * or `HCheckCast`. |
| 6225 | */ |
| 6226 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6227 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6228 | kExactCheck, // Can do a single class compare. |
| 6229 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6230 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6231 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6232 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6233 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6234 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6235 | }; |
| 6236 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6237 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6238 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6239 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6240 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6241 | HInstanceOf(HInstruction* object, |
| 6242 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6243 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6244 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6245 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6246 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6247 | dex_pc) { |
| 6248 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6249 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6250 | SetRawInputAt(0, object); |
| 6251 | SetRawInputAt(1, constant); |
| 6252 | } |
| 6253 | |
| 6254 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6255 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6256 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6257 | return true; |
| 6258 | } |
| 6259 | |
| 6260 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6261 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6262 | } |
| 6263 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6264 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6265 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6266 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6267 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6268 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6269 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6270 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6271 | // Mips currently does runtime calls for any other checks. |
| 6272 | return check_kind != TypeCheckKind::kExactCheck; |
| 6273 | } |
| 6274 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6275 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6276 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6277 | } |
| 6278 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6279 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6280 | |
| 6281 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6282 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6283 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6284 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6285 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6286 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6287 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6288 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6289 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6290 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6291 | }; |
| 6292 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6293 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6294 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6295 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6296 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6297 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6298 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6299 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6300 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6301 | SetRawInputAt(0, input); |
| 6302 | } |
| 6303 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6304 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6305 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6306 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6307 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6308 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6309 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6310 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6311 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6312 | } |
| 6313 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6314 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6315 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6316 | DECLARE_INSTRUCTION(BoundType); |
| 6317 | |
| 6318 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6319 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6320 | // is false then CanBeNull() cannot be true). |
| 6321 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6322 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6323 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6324 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6325 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6326 | // 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] | 6327 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6328 | // It is used to bound the type in cases like: |
| 6329 | // if (x instanceof ClassX) { |
| 6330 | // // uper_bound_ will be ClassX |
| 6331 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6332 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6333 | |
| 6334 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6335 | }; |
| 6336 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6337 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6338 | public: |
| 6339 | HCheckCast(HInstruction* object, |
| 6340 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6341 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6342 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6343 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6344 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6345 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6346 | SetRawInputAt(0, object); |
| 6347 | SetRawInputAt(1, constant); |
| 6348 | } |
| 6349 | |
| 6350 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6351 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6352 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6353 | return true; |
| 6354 | } |
| 6355 | |
| 6356 | bool NeedsEnvironment() const OVERRIDE { |
| 6357 | // Instruction may throw a CheckCastError. |
| 6358 | return true; |
| 6359 | } |
| 6360 | |
| 6361 | bool CanThrow() const OVERRIDE { return true; } |
| 6362 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6363 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6364 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6365 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6366 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6367 | |
| 6368 | DECLARE_INSTRUCTION(CheckCast); |
| 6369 | |
| 6370 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6371 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6372 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6373 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6374 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6375 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6376 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6377 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6378 | |
| 6379 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6380 | }; |
| 6381 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6382 | /** |
| 6383 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6384 | * @details We define the combined barrier types that are actually required |
| 6385 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6386 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6387 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6388 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6389 | * The current recipe is as follows: |
| 6390 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6391 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6392 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6393 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6394 | * class has final fields. |
| 6395 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6396 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6397 | */ |
| 6398 | enum MemBarrierKind { |
| 6399 | kAnyStore, |
| 6400 | kLoadAny, |
| 6401 | kStoreStore, |
| 6402 | kAnyAny, |
| 6403 | kNTStoreStore, |
| 6404 | kLastBarrierKind = kNTStoreStore |
| 6405 | }; |
| 6406 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6407 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6408 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6409 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6410 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6411 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6412 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6413 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6414 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6415 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6416 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6417 | |
| 6418 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6419 | |
| 6420 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6421 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6422 | static constexpr size_t kFieldBarrierKindSize = |
| 6423 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6424 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6425 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6426 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6427 | "Too many packed fields."); |
| 6428 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6429 | |
| 6430 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6431 | }; |
| 6432 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6433 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6434 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6435 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6436 | kEnter, |
| 6437 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6438 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6439 | }; |
| 6440 | |
| 6441 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6442 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6443 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6444 | dex_pc) { |
| 6445 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6446 | SetRawInputAt(0, object); |
| 6447 | } |
| 6448 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6449 | // Instruction may go into runtime, so we need an environment. |
| 6450 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6451 | |
| 6452 | bool CanThrow() const OVERRIDE { |
| 6453 | // Verifier guarantees that monitor-exit cannot throw. |
| 6454 | // This is important because it allows the HGraphBuilder to remove |
| 6455 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6456 | return IsEnter(); |
| 6457 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6458 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6459 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6460 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6461 | |
| 6462 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6463 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6464 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6465 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6466 | static constexpr size_t kFieldOperationKindSize = |
| 6467 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6468 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6469 | kFieldOperationKind + kFieldOperationKindSize; |
| 6470 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6471 | "Too many packed fields."); |
| 6472 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6473 | |
| 6474 | private: |
| 6475 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6476 | }; |
| 6477 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6478 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6479 | public: |
| 6480 | HSelect(HInstruction* condition, |
| 6481 | HInstruction* true_value, |
| 6482 | HInstruction* false_value, |
| 6483 | uint32_t dex_pc) |
| 6484 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6485 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6486 | |
| 6487 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6488 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6489 | // that architectures which implement HSelect as a conditional move also |
| 6490 | // will not need to invert the condition. |
| 6491 | SetRawInputAt(0, false_value); |
| 6492 | SetRawInputAt(1, true_value); |
| 6493 | SetRawInputAt(2, condition); |
| 6494 | } |
| 6495 | |
| 6496 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6497 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6498 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6499 | |
| 6500 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6501 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6502 | return true; |
| 6503 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6504 | |
| 6505 | bool CanBeNull() const OVERRIDE { |
| 6506 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6507 | } |
| 6508 | |
| 6509 | DECLARE_INSTRUCTION(Select); |
| 6510 | |
| 6511 | private: |
| 6512 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6513 | }; |
| 6514 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6515 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6516 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6517 | MoveOperands(Location source, |
| 6518 | Location destination, |
| 6519 | Primitive::Type type, |
| 6520 | HInstruction* instruction) |
| 6521 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6522 | |
| 6523 | Location GetSource() const { return source_; } |
| 6524 | Location GetDestination() const { return destination_; } |
| 6525 | |
| 6526 | void SetSource(Location value) { source_ = value; } |
| 6527 | void SetDestination(Location value) { destination_ = value; } |
| 6528 | |
| 6529 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6530 | // destination (but not the source). |
| 6531 | Location MarkPending() { |
| 6532 | DCHECK(!IsPending()); |
| 6533 | Location dest = destination_; |
| 6534 | destination_ = Location::NoLocation(); |
| 6535 | return dest; |
| 6536 | } |
| 6537 | |
| 6538 | void ClearPending(Location dest) { |
| 6539 | DCHECK(IsPending()); |
| 6540 | destination_ = dest; |
| 6541 | } |
| 6542 | |
| 6543 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6544 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6545 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6546 | } |
| 6547 | |
| 6548 | // True if this blocks a move from the given location. |
| 6549 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6550 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6551 | } |
| 6552 | |
| 6553 | // A move is redundant if it's been eliminated, if its source and |
| 6554 | // destination are the same, or if its destination is unneeded. |
| 6555 | bool IsRedundant() const { |
| 6556 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6557 | } |
| 6558 | |
| 6559 | // We clear both operands to indicate move that's been eliminated. |
| 6560 | void Eliminate() { |
| 6561 | source_ = destination_ = Location::NoLocation(); |
| 6562 | } |
| 6563 | |
| 6564 | bool IsEliminated() const { |
| 6565 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6566 | return source_.IsInvalid(); |
| 6567 | } |
| 6568 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6569 | Primitive::Type GetType() const { return type_; } |
| 6570 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6571 | bool Is64BitMove() const { |
| 6572 | return Primitive::Is64BitType(type_); |
| 6573 | } |
| 6574 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6575 | HInstruction* GetInstruction() const { return instruction_; } |
| 6576 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6577 | private: |
| 6578 | Location source_; |
| 6579 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6580 | // The type this move is for. |
| 6581 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6582 | // The instruction this move is assocatied with. Null when this move is |
| 6583 | // for moving an input in the expected locations of user (including a phi user). |
| 6584 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6585 | // in the same parallel move. |
| 6586 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6587 | }; |
| 6588 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6589 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6590 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6591 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6592 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6593 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6594 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6595 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6596 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6597 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6598 | moves_.reserve(kDefaultNumberOfMoves); |
| 6599 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6600 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6601 | void AddMove(Location source, |
| 6602 | Location destination, |
| 6603 | Primitive::Type type, |
| 6604 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6605 | DCHECK(source.IsValid()); |
| 6606 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6607 | if (kIsDebugBuild) { |
| 6608 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6609 | for (const MoveOperands& move : moves_) { |
| 6610 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6611 | // Special case the situation where the move is for the spill slot |
| 6612 | // of the instruction. |
| 6613 | if ((GetPrevious() == instruction) |
| 6614 | || ((GetPrevious() == nullptr) |
| 6615 | && instruction->IsPhi() |
| 6616 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6617 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6618 | << "Doing parallel moves for the same instruction."; |
| 6619 | } else { |
| 6620 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6621 | } |
| 6622 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6623 | } |
| 6624 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6625 | for (const MoveOperands& move : moves_) { |
| 6626 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6627 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6628 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6629 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6630 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6631 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6632 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6633 | } |
| 6634 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6635 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6636 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6637 | } |
| 6638 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6639 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6640 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6641 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6642 | |
| 6643 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6644 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6645 | |
| 6646 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6647 | }; |
| 6648 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6649 | } // namespace art |
| 6650 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6651 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6652 | #include "nodes_shared.h" |
| 6653 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6654 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6655 | #include "nodes_arm.h" |
| 6656 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6657 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6658 | #include "nodes_arm64.h" |
| 6659 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6660 | #ifdef ART_ENABLE_CODEGEN_mips |
| 6661 | #include "nodes_mips.h" |
| 6662 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6663 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6664 | #include "nodes_x86.h" |
| 6665 | #endif |
| 6666 | |
| 6667 | namespace art { |
| 6668 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6669 | class HGraphVisitor : public ValueObject { |
| 6670 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6671 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6672 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6673 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6674 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6675 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6676 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6677 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6678 | void VisitInsertionOrder(); |
| 6679 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6680 | // Visit the graph following dominator tree reverse post-order. |
| 6681 | void VisitReversePostOrder(); |
| 6682 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6683 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6684 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6685 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6686 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6687 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6688 | |
| 6689 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6690 | |
| 6691 | #undef DECLARE_VISIT_INSTRUCTION |
| 6692 | |
| 6693 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6694 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6695 | |
| 6696 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6697 | }; |
| 6698 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6699 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6700 | public: |
| 6701 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6702 | virtual ~HGraphDelegateVisitor() {} |
| 6703 | |
| 6704 | // Visit functions that delegate to to super class. |
| 6705 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6706 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6707 | |
| 6708 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6709 | |
| 6710 | #undef DECLARE_VISIT_INSTRUCTION |
| 6711 | |
| 6712 | private: |
| 6713 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6714 | }; |
| 6715 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6716 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6717 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6718 | // block id. |
| 6719 | class HBlocksInLoopIterator : public ValueObject { |
| 6720 | public: |
| 6721 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6722 | : blocks_in_loop_(info.GetBlocks()), |
| 6723 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6724 | index_(0) { |
| 6725 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6726 | Advance(); |
| 6727 | } |
| 6728 | } |
| 6729 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6730 | bool Done() const { return index_ == blocks_.size(); } |
| 6731 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6732 | void Advance() { |
| 6733 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6734 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6735 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6736 | break; |
| 6737 | } |
| 6738 | } |
| 6739 | } |
| 6740 | |
| 6741 | private: |
| 6742 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6743 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6744 | size_t index_; |
| 6745 | |
| 6746 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6747 | }; |
| 6748 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6749 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6750 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6751 | // post order. |
| 6752 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6753 | public: |
| 6754 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6755 | : blocks_in_loop_(info.GetBlocks()), |
| 6756 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6757 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6758 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6759 | Advance(); |
| 6760 | } |
| 6761 | } |
| 6762 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6763 | bool Done() const { return index_ == blocks_.size(); } |
| 6764 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6765 | void Advance() { |
| 6766 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6767 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6768 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6769 | break; |
| 6770 | } |
| 6771 | } |
| 6772 | } |
| 6773 | |
| 6774 | private: |
| 6775 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6776 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6777 | size_t index_; |
| 6778 | |
| 6779 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6780 | }; |
| 6781 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6782 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6783 | if (constant->IsIntConstant()) { |
| 6784 | return constant->AsIntConstant()->GetValue(); |
| 6785 | } else if (constant->IsLongConstant()) { |
| 6786 | return constant->AsLongConstant()->GetValue(); |
| 6787 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6788 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6789 | return 0; |
| 6790 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6791 | } |
| 6792 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6793 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6794 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6795 | inline const H##type* HInstruction::As##type() const { \ |
| 6796 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6797 | } \ |
| 6798 | inline H##type* HInstruction::As##type() { \ |
| 6799 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6800 | } |
| 6801 | |
| 6802 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6803 | #undef INSTRUCTION_TYPE_CHECK |
| 6804 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6805 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6806 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6807 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6808 | size_t number_of_new_blocks, |
| 6809 | size_t after) { |
| 6810 | DCHECK_LT(after, blocks->size()); |
| 6811 | size_t old_size = blocks->size(); |
| 6812 | size_t new_size = old_size + number_of_new_blocks; |
| 6813 | blocks->resize(new_size); |
| 6814 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6815 | } |
| 6816 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6817 | } // namespace art |
| 6818 | |
| 6819 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |