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), |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 326 | has_simd_(false), |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 327 | has_loops_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 328 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 329 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 330 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 331 | dex_file_(dex_file), |
| 332 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 333 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 334 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 335 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 336 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 337 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 338 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 339 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 340 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 341 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 342 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 343 | cached_current_method_(nullptr), |
Nicolas Geoffray | 53fec08 | 2017-03-27 12:56:16 +0100 | [diff] [blame] | 344 | art_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 345 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 346 | osr_(osr), |
| 347 | cha_single_implementation_list_(arena->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 348 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 349 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 350 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 351 | // 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] | 352 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 353 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 354 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 355 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 356 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 357 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 358 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 359 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 360 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 361 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 362 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 363 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 364 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 365 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 366 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 367 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 368 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 369 | void ComputeDominanceInformation(); |
| 370 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 371 | void ClearLoopInformation(); |
| 372 | void FindBackEdges(ArenaBitVector* visited); |
| 373 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 374 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 375 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 376 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 377 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 378 | // 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] | 379 | // 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] | 380 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 381 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 382 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 383 | // order and loop information. |
| 384 | void ComputeTryBlockInformation(); |
| 385 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 386 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 387 | // Returns the instruction to replace the invoke expression or null if the |
| 388 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 389 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 390 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 391 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 392 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 393 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 394 | // should be the new back edge. |
| 395 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 396 | HBasicBlock* reference, |
| 397 | bool replace_if_back_edge); |
| 398 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 399 | // Need to add a couple of blocks to test if the loop body is entered and |
| 400 | // put deoptimization instructions, etc. |
| 401 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 402 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame^] | 403 | // Adds a new loop directly after the loop with the given header and exit. |
| 404 | // Returns the new preheader. |
| 405 | HBasicBlock* TransformLoopForVectorization(HBasicBlock* header, |
| 406 | HBasicBlock* body, |
| 407 | HBasicBlock* exit); |
| 408 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 409 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 410 | // other blocks and has no instructions or phis. |
| 411 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 412 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 413 | // Splits the edge between `block` and `successor` while preserving the |
| 414 | // indices in the predecessor/successor lists. If there are multiple edges |
| 415 | // between the blocks, the lowest indices are used. |
| 416 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 417 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 418 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 419 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 420 | void SimplifyLoop(HBasicBlock* header); |
| 421 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 422 | int32_t GetNextInstructionId() { |
| 423 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 424 | return current_instruction_id_++; |
| 425 | } |
| 426 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 427 | int32_t GetCurrentInstructionId() const { |
| 428 | return current_instruction_id_; |
| 429 | } |
| 430 | |
| 431 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 432 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 433 | current_instruction_id_ = id; |
| 434 | } |
| 435 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 436 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 437 | return maximum_number_of_out_vregs_; |
| 438 | } |
| 439 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 440 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 441 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 442 | } |
| 443 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 444 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 445 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 446 | } |
| 447 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 448 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 449 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 450 | } |
| 451 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 452 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 453 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 454 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 455 | } |
| 456 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 457 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 458 | number_of_vregs_ = number_of_vregs; |
| 459 | } |
| 460 | |
| 461 | uint16_t GetNumberOfVRegs() const { |
| 462 | return number_of_vregs_; |
| 463 | } |
| 464 | |
| 465 | void SetNumberOfInVRegs(uint16_t value) { |
| 466 | number_of_in_vregs_ = value; |
| 467 | } |
| 468 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 469 | uint16_t GetNumberOfInVRegs() const { |
| 470 | return number_of_in_vregs_; |
| 471 | } |
| 472 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 473 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 474 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 475 | return number_of_vregs_ - number_of_in_vregs_; |
| 476 | } |
| 477 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 478 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 479 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 480 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 481 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 482 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 483 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 484 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 485 | } |
| 486 | |
| 487 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 488 | return ReverseRange(GetReversePostOrder()); |
| 489 | } |
| 490 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 491 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 492 | return linear_order_; |
| 493 | } |
| 494 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 495 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 496 | return ReverseRange(GetLinearOrder()); |
| 497 | } |
| 498 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 499 | bool HasBoundsChecks() const { |
| 500 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 503 | void SetHasBoundsChecks(bool value) { |
| 504 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 505 | } |
| 506 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 507 | bool ShouldGenerateConstructorBarrier() const { |
| 508 | return should_generate_constructor_barrier_; |
| 509 | } |
| 510 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 511 | bool IsDebuggable() const { return debuggable_; } |
| 512 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 513 | // 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] | 514 | // already, it is created and inserted into the graph. This method is only for |
| 515 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 516 | 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] | 517 | |
| 518 | // TODO: This is problematic for the consistency of reference type propagation |
| 519 | // because it can be created anytime after the pass and thus it will be left |
| 520 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 521 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 522 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 523 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 524 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 525 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 526 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 527 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 528 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 529 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 530 | 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] | 531 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 532 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 533 | 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] | 534 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 535 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 536 | HCurrentMethod* GetCurrentMethod(); |
| 537 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 538 | const DexFile& GetDexFile() const { |
| 539 | return dex_file_; |
| 540 | } |
| 541 | |
| 542 | uint32_t GetMethodIdx() const { |
| 543 | return method_idx_; |
| 544 | } |
| 545 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 546 | InvokeType GetInvokeType() const { |
| 547 | return invoke_type_; |
| 548 | } |
| 549 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 550 | InstructionSet GetInstructionSet() const { |
| 551 | return instruction_set_; |
| 552 | } |
| 553 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 554 | bool IsCompilingOsr() const { return osr_; } |
| 555 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 556 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 557 | return cha_single_implementation_list_; |
| 558 | } |
| 559 | |
| 560 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 561 | cha_single_implementation_list_.insert(method); |
| 562 | } |
| 563 | |
| 564 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 565 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 566 | } |
| 567 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 568 | bool HasTryCatch() const { return has_try_catch_; } |
| 569 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 570 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 571 | bool HasSIMD() const { return has_simd_; } |
| 572 | void SetHasSIMD(bool value) { has_simd_ = value; } |
| 573 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 574 | bool HasLoops() const { return has_loops_; } |
| 575 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 576 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 577 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 578 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 579 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 580 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 581 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 582 | |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 583 | // Returns an instruction with the opposite Boolean value from 'cond'. |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 584 | // The instruction has been inserted into the graph, either as a constant, or |
| 585 | // before cursor. |
| 586 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 587 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 588 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 589 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 590 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 591 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 592 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 593 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 594 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 595 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 596 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 597 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 598 | template <class InstructionType, typename ValueType> |
| 599 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 600 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 601 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 602 | // Try to find an existing constant of the given value. |
| 603 | InstructionType* constant = nullptr; |
| 604 | auto cached_constant = cache->find(value); |
| 605 | if (cached_constant != cache->end()) { |
| 606 | constant = cached_constant->second; |
| 607 | } |
| 608 | |
| 609 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 610 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 611 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 612 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 613 | cache->Overwrite(value, constant); |
| 614 | InsertConstant(constant); |
| 615 | } |
| 616 | return constant; |
| 617 | } |
| 618 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 619 | void InsertConstant(HConstant* instruction); |
| 620 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 621 | // Cache a float constant into the graph. This method should only be |
| 622 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 623 | void CacheFloatConstant(HFloatConstant* constant); |
| 624 | |
| 625 | // See CacheFloatConstant comment. |
| 626 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 627 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 628 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 629 | |
| 630 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 631 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 632 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 633 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 634 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 635 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 636 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 637 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 638 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 639 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 640 | HBasicBlock* entry_block_; |
| 641 | HBasicBlock* exit_block_; |
| 642 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 643 | // 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] | 644 | uint16_t maximum_number_of_out_vregs_; |
| 645 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 646 | // The number of virtual registers in this method. Contains the parameters. |
| 647 | uint16_t number_of_vregs_; |
| 648 | |
| 649 | // The number of virtual registers used by parameters of this method. |
| 650 | uint16_t number_of_in_vregs_; |
| 651 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 652 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 653 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 654 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 655 | // Flag whether there are bounds checks in the graph. We can skip |
| 656 | // BCE if it's false. It's only best effort to keep it up to date in |
| 657 | // the presence of code elimination so there might be false positives. |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 658 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 659 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 660 | // Flag whether there are try/catch blocks in the graph. We will skip |
| 661 | // try/catch-related passes if it's false. It's only best effort to keep |
| 662 | // it up to date in the presence of code elimination so there might be |
| 663 | // false positives. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 664 | bool has_try_catch_; |
| 665 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 666 | // Flag whether SIMD instructions appear in the graph. If true, the |
| 667 | // code generators may have to be more careful spilling the wider |
| 668 | // contents of SIMD registers. |
| 669 | bool has_simd_; |
| 670 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 671 | // Flag whether there are any loops in the graph. We can skip loop |
| 672 | // optimization if it's false. It's only best effort to keep it up |
| 673 | // to date in the presence of code elimination so there might be false |
| 674 | // positives. |
| 675 | bool has_loops_; |
| 676 | |
| 677 | // Flag whether there are any irreducible loops in the graph. It's only |
| 678 | // best effort to keep it up to date in the presence of code elimination |
| 679 | // so there might be false positives. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 680 | bool has_irreducible_loops_; |
| 681 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 682 | // Indicates whether the graph should be compiled in a way that |
| 683 | // ensures full debuggability. If false, we can apply more |
| 684 | // aggressive optimizations that may limit the level of debugging. |
| 685 | const bool debuggable_; |
| 686 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 687 | // 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] | 688 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 689 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 690 | // The dex file from which the method is from. |
| 691 | const DexFile& dex_file_; |
| 692 | |
| 693 | // The method index in the dex file. |
| 694 | const uint32_t method_idx_; |
| 695 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 696 | // If inlined, this encodes how the callee is being invoked. |
| 697 | const InvokeType invoke_type_; |
| 698 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 699 | // Whether the graph has been transformed to SSA form. Only used |
| 700 | // in debug mode to ensure we are not using properties only valid |
| 701 | // for non-SSA form (like the number of temporaries). |
| 702 | bool in_ssa_form_; |
| 703 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 704 | const bool should_generate_constructor_barrier_; |
| 705 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 706 | // Number of CHA guards in the graph. Used to short-circuit the |
| 707 | // CHA guard optimization pass when there is no CHA guard left. |
| 708 | uint32_t number_of_cha_guards_; |
| 709 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 710 | const InstructionSet instruction_set_; |
| 711 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 712 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 713 | HNullConstant* cached_null_constant_; |
| 714 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 715 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 716 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 717 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 718 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 719 | HCurrentMethod* cached_current_method_; |
| 720 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 721 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 722 | // for example for methods whose declaring class could not be resolved |
| 723 | // (such as when the superclass could not be found). |
| 724 | ArtMethod* art_method_; |
| 725 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 726 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 727 | // collection pointer to passes which may create NullConstant. |
| 728 | ReferenceTypeInfo inexact_object_rti_; |
| 729 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 730 | // Whether we are compiling this graph for on stack replacement: this will |
| 731 | // make all loops seen as irreducible and emit special stack maps to mark |
| 732 | // compiled code entries which the interpreter can directly jump to. |
| 733 | const bool osr_; |
| 734 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 735 | // List of methods that are assumed to have single implementation. |
| 736 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 737 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 738 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 739 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 740 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 741 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 742 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 743 | }; |
| 744 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 745 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 746 | public: |
| 747 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 748 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 749 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 750 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 751 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 752 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 753 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 754 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 755 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 756 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 757 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 758 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 759 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 760 | |
| 761 | void Dump(std::ostream& os); |
| 762 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 763 | HBasicBlock* GetHeader() const { |
| 764 | return header_; |
| 765 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 766 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 767 | void SetHeader(HBasicBlock* block) { |
| 768 | header_ = block; |
| 769 | } |
| 770 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 771 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 772 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 773 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 774 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 775 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 776 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 779 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 780 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 781 | } |
| 782 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 783 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 784 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 785 | } |
| 786 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 787 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 788 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 791 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 792 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 793 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 794 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 795 | } |
| 796 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 797 | // Returns the lifetime position of the back edge that has the |
| 798 | // greatest lifetime position. |
| 799 | size_t GetLifetimeEnd() const; |
| 800 | |
| 801 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 802 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 803 | } |
| 804 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 805 | // Finds blocks that are part of this loop. |
| 806 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 807 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 808 | // Returns whether this loop information contains `block`. |
| 809 | // Note that this loop information *must* be populated before entering this function. |
| 810 | bool Contains(const HBasicBlock& block) const; |
| 811 | |
| 812 | // Returns whether this loop information is an inner loop of `other`. |
| 813 | // Note that `other` *must* be populated before entering this function. |
| 814 | bool IsIn(const HLoopInformation& other) const; |
| 815 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 816 | // Returns true if instruction is not defined within this loop. |
| 817 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 818 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 819 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 820 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 821 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 822 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 823 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 824 | void ClearAllBlocks() { |
| 825 | blocks_.ClearAllBits(); |
| 826 | } |
| 827 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 828 | bool HasBackEdgeNotDominatedByHeader() const; |
| 829 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 830 | bool IsPopulated() const { |
| 831 | return blocks_.GetHighestBitSet() != -1; |
| 832 | } |
| 833 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 834 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 835 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 836 | bool HasExitEdge() const; |
| 837 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 838 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 839 | // Internal recursive implementation of `Populate`. |
| 840 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 841 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 842 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 843 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 844 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 845 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 846 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 847 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 848 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 849 | |
| 850 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 851 | }; |
| 852 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 853 | // Stores try/catch information for basic blocks. |
| 854 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 855 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 856 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 857 | public: |
| 858 | // Try block information constructor. |
| 859 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 860 | : try_entry_(&try_entry), |
| 861 | catch_dex_file_(nullptr), |
| 862 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 863 | DCHECK(try_entry_ != nullptr); |
| 864 | } |
| 865 | |
| 866 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 867 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 868 | : try_entry_(nullptr), |
| 869 | catch_dex_file_(&dex_file), |
| 870 | catch_type_index_(catch_type_index) {} |
| 871 | |
| 872 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 873 | |
| 874 | const HTryBoundary& GetTryEntry() const { |
| 875 | DCHECK(IsTryBlock()); |
| 876 | return *try_entry_; |
| 877 | } |
| 878 | |
| 879 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 880 | |
| 881 | bool IsCatchAllTypeIndex() const { |
| 882 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 883 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 884 | } |
| 885 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 886 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 887 | DCHECK(IsCatchBlock()); |
| 888 | return catch_type_index_; |
| 889 | } |
| 890 | |
| 891 | const DexFile& GetCatchDexFile() const { |
| 892 | DCHECK(IsCatchBlock()); |
| 893 | return *catch_dex_file_; |
| 894 | } |
| 895 | |
| 896 | private: |
| 897 | // One of possibly several TryBoundary instructions entering the block's try. |
| 898 | // Only set for try blocks. |
| 899 | const HTryBoundary* try_entry_; |
| 900 | |
| 901 | // Exception type information. Only set for catch blocks. |
| 902 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 903 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 904 | }; |
| 905 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 906 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 907 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 908 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 909 | // A block in a method. Contains the list of instructions represented |
| 910 | // as a double linked list. Each block knows its predecessors and |
| 911 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 912 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 913 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 914 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 915 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 916 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 917 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 918 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 919 | loop_information_(nullptr), |
| 920 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 921 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 922 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 923 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 924 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 925 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 926 | try_catch_information_(nullptr) { |
| 927 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 928 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 929 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 930 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 931 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 932 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 933 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 934 | } |
| 935 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 936 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 937 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 938 | } |
| 939 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 940 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 941 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 942 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 943 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 944 | return ContainsElement(successors_, block, start_from); |
| 945 | } |
| 946 | |
| 947 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 948 | return dominated_blocks_; |
| 949 | } |
| 950 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 951 | bool IsEntryBlock() const { |
| 952 | return graph_->GetEntryBlock() == this; |
| 953 | } |
| 954 | |
| 955 | bool IsExitBlock() const { |
| 956 | return graph_->GetExitBlock() == this; |
| 957 | } |
| 958 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 959 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 960 | bool IsSingleTryBoundary() const; |
| 961 | |
| 962 | // Returns true if this block emits nothing but a jump. |
| 963 | bool IsSingleJump() const { |
| 964 | HLoopInformation* loop_info = GetLoopInformation(); |
| 965 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 966 | // Back edges generate a suspend check. |
| 967 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 968 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 969 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 970 | void AddBackEdge(HBasicBlock* back_edge) { |
| 971 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 972 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 973 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 974 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 975 | loop_information_->AddBackEdge(back_edge); |
| 976 | } |
| 977 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 978 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 979 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 980 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 981 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 982 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 983 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 984 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 985 | HBasicBlock* GetDominator() const { return dominator_; } |
| 986 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 987 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 988 | |
| 989 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 990 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 991 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 992 | |
| 993 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 994 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 995 | } |
| 996 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 997 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 998 | |
| 999 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1000 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1003 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1004 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1005 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1006 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1007 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1008 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1009 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1010 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1011 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1012 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1013 | successors_.push_back(block); |
| 1014 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1017 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1018 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1019 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1020 | new_block->predecessors_.push_back(this); |
| 1021 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1024 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1025 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1026 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1027 | new_block->successors_.push_back(this); |
| 1028 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1031 | // Insert `this` between `predecessor` and `successor. This method |
| 1032 | // preserves the indicies, and will update the first edge found between |
| 1033 | // `predecessor` and `successor`. |
| 1034 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1035 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1036 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1037 | successor->predecessors_[predecessor_index] = this; |
| 1038 | predecessor->successors_[successor_index] = this; |
| 1039 | successors_.push_back(successor); |
| 1040 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1041 | } |
| 1042 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1043 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1044 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1047 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1048 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1051 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1052 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1056 | predecessors_.push_back(block); |
| 1057 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1060 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1061 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1062 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1063 | } |
| 1064 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1065 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1066 | DCHECK_EQ(successors_.size(), 2u); |
| 1067 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1070 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1071 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1072 | } |
| 1073 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1074 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1075 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1076 | } |
| 1077 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1078 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1079 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1080 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1084 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1085 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1089 | // predecessors is at index `idx`. |
| 1090 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1091 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1092 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1093 | } |
| 1094 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1095 | // Create a new block between this block and its predecessors. The new block |
| 1096 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1097 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1098 | // loop and try/catch information are not updated. |
| 1099 | HBasicBlock* CreateImmediateDominator(); |
| 1100 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1101 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1102 | // created, latter block. Note that this method will add the block to the |
| 1103 | // graph, create a Goto at the end of the former block and will create an edge |
| 1104 | // 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] | 1105 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1106 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1107 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1108 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1109 | // created block. Note that this method just updates raw block information, |
| 1110 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1111 | // update the graph, reverse post order, loop information, nor make sure the |
| 1112 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1113 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1114 | |
| 1115 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1116 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1117 | |
| 1118 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1119 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1120 | // that this method does not update the graph, reverse post order, loop |
| 1121 | // information, nor make sure the blocks are consistent (for example ending |
| 1122 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1123 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1124 | |
| 1125 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1126 | // of `this` are moved to `other`. |
| 1127 | // Note that this method does not update the graph, reverse post order, loop |
| 1128 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1129 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1130 | void ReplaceWith(HBasicBlock* other); |
| 1131 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1132 | // Merges the instructions of `other` at the end of `this`. |
| 1133 | void MergeInstructionsWith(HBasicBlock* other); |
| 1134 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1135 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1136 | // order, links to predecessors, successors, dominators and deletes the block |
| 1137 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1138 | // predecessor of `other` and vice versa. |
| 1139 | void MergeWith(HBasicBlock* other); |
| 1140 | |
| 1141 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1142 | // removes it from all loops it is included in and eventually from the graph. |
| 1143 | // The block must not dominate any other block. Predecessors and successors |
| 1144 | // are safely updated. |
| 1145 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1146 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1147 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1148 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1149 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1150 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1151 | // Replace instruction `initial` with `replacement` within this block. |
| 1152 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1153 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1154 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1155 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1156 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1157 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1158 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1159 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1160 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1161 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1162 | |
| 1163 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1164 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1165 | } |
| 1166 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1167 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1168 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1169 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1170 | } |
| 1171 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1172 | bool IsFirstPredecessorBackEdge() const { |
| 1173 | DCHECK(IsLoopHeader()); |
| 1174 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1175 | } |
| 1176 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1177 | HLoopInformation* GetLoopInformation() const { |
| 1178 | return loop_information_; |
| 1179 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1180 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1181 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1182 | // 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] | 1183 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1184 | void SetInLoop(HLoopInformation* info) { |
| 1185 | if (IsLoopHeader()) { |
| 1186 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1187 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1188 | loop_information_ = info; |
| 1189 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1190 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1191 | // Note that a non loop header having a loop information means this loop information |
| 1192 | // has already been populated |
| 1193 | loop_information_ = info; |
| 1194 | } else { |
| 1195 | // Block is part of an inner loop. Do not update the loop information. |
| 1196 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1197 | // at this point, because this method is being called while populating `info`. |
| 1198 | } |
| 1199 | } |
| 1200 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1201 | // Raw update of the loop information. |
| 1202 | void SetLoopInformation(HLoopInformation* info) { |
| 1203 | loop_information_ = info; |
| 1204 | } |
| 1205 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1206 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1207 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1208 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1209 | |
| 1210 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1211 | try_catch_information_ = try_catch_information; |
| 1212 | } |
| 1213 | |
| 1214 | bool IsTryBlock() const { |
| 1215 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1216 | } |
| 1217 | |
| 1218 | bool IsCatchBlock() const { |
| 1219 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1220 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1221 | |
| 1222 | // Returns the try entry that this block's successors should have. They will |
| 1223 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1224 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1225 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1226 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1227 | bool HasThrowingInstructions() const; |
| 1228 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1229 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1230 | bool Dominates(HBasicBlock* block) const; |
| 1231 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1232 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1233 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1234 | |
| 1235 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1236 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1237 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1238 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1239 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1240 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1241 | bool HasSinglePhi() const; |
| 1242 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1243 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1244 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1245 | ArenaVector<HBasicBlock*> predecessors_; |
| 1246 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1247 | HInstructionList instructions_; |
| 1248 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1249 | HLoopInformation* loop_information_; |
| 1250 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1251 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1252 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1253 | // The dex program counter of the first instruction of this block. |
| 1254 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1255 | size_t lifetime_start_; |
| 1256 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1257 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1258 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1259 | friend class HGraph; |
| 1260 | friend class HInstruction; |
| 1261 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1262 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1263 | }; |
| 1264 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1265 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1266 | // from the innermost to the outermost. |
| 1267 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1268 | public: |
| 1269 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1270 | : current_(block.GetLoopInformation()) {} |
| 1271 | |
| 1272 | bool Done() const { return current_ == nullptr; } |
| 1273 | |
| 1274 | void Advance() { |
| 1275 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1276 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | HLoopInformation* Current() const { |
| 1280 | DCHECK(!Done()); |
| 1281 | return current_; |
| 1282 | } |
| 1283 | |
| 1284 | private: |
| 1285 | HLoopInformation* current_; |
| 1286 | |
| 1287 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1288 | }; |
| 1289 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1290 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1291 | M(Above, Condition) \ |
| 1292 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1293 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1294 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1295 | M(ArrayGet, Instruction) \ |
| 1296 | M(ArrayLength, Instruction) \ |
| 1297 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1298 | M(Below, Condition) \ |
| 1299 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1300 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1301 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1302 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1303 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1304 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1305 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1306 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1307 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1308 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1309 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1310 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1311 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1312 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1313 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1314 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1315 | M(Exit, Instruction) \ |
| 1316 | M(FloatConstant, Constant) \ |
| 1317 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1318 | M(GreaterThan, Condition) \ |
| 1319 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1320 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1321 | M(InstanceFieldGet, Instruction) \ |
| 1322 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1323 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1324 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1325 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1326 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1327 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1328 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1329 | M(InvokePolymorphic, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1330 | M(LessThan, Condition) \ |
| 1331 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1332 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1333 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1334 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1335 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1336 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1337 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1338 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1339 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1340 | M(Neg, UnaryOperation) \ |
| 1341 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1342 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1343 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1344 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1345 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1346 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1347 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1348 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1349 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1350 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1351 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1352 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1353 | M(Return, Instruction) \ |
| 1354 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1355 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1356 | M(Shl, BinaryOperation) \ |
| 1357 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1358 | M(StaticFieldGet, Instruction) \ |
| 1359 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1360 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1361 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1362 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1363 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1364 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1365 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1366 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1367 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1368 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1369 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1370 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1371 | M(Xor, BinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame^] | 1372 | M(VecReplicateScalar, VecUnaryOperation) \ |
| 1373 | M(VecSetScalars, VecUnaryOperation) \ |
| 1374 | M(VecSumReduce, VecUnaryOperation) \ |
| 1375 | M(VecCnv, VecUnaryOperation) \ |
| 1376 | M(VecNeg, VecUnaryOperation) \ |
| 1377 | M(VecNot, VecUnaryOperation) \ |
| 1378 | M(VecAdd, VecBinaryOperation) \ |
| 1379 | M(VecSub, VecBinaryOperation) \ |
| 1380 | M(VecMul, VecBinaryOperation) \ |
| 1381 | M(VecDiv, VecBinaryOperation) \ |
| 1382 | M(VecAnd, VecBinaryOperation) \ |
| 1383 | M(VecAndNot, VecBinaryOperation) \ |
| 1384 | M(VecOr, VecBinaryOperation) \ |
| 1385 | M(VecXor, VecBinaryOperation) \ |
| 1386 | M(VecShl, VecBinaryOperation) \ |
| 1387 | M(VecShr, VecBinaryOperation) \ |
| 1388 | M(VecUShr, VecBinaryOperation) \ |
| 1389 | M(VecLoad, VecMemoryOperation) \ |
| 1390 | M(VecStore, VecMemoryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1391 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1392 | /* |
| 1393 | * Instructions, shared across several (not all) architectures. |
| 1394 | */ |
| 1395 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1396 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1397 | #else |
| 1398 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1399 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1400 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1401 | M(MultiplyAccumulate, Instruction) \ |
| 1402 | M(IntermediateAddress, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1403 | #endif |
| 1404 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1405 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1406 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1407 | #else |
| 1408 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1409 | M(ArmDexCacheArraysBase, Instruction) |
| 1410 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1411 | |
| 1412 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1413 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1414 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1415 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1416 | #else |
| 1417 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1418 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1419 | M(MipsDexCacheArraysBase, Instruction) \ |
| 1420 | M(MipsPackedSwitch, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1421 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1422 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1423 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1424 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1425 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1426 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1427 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1428 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1429 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1430 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1431 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1432 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1433 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1434 | |
| 1435 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1436 | |
| 1437 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1438 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1439 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1440 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1441 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1442 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1443 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1444 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1445 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1446 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1447 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1448 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1449 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1450 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1451 | M(BinaryOperation, Instruction) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame^] | 1452 | M(Invoke, Instruction) \ |
| 1453 | M(VecOperation, Instruction) \ |
| 1454 | M(VecUnaryOperation, VecOperation) \ |
| 1455 | M(VecBinaryOperation, VecOperation) \ |
| 1456 | M(VecMemoryOperation, VecOperation) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1457 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1458 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1459 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1460 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1461 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1462 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1463 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1464 | #undef FORWARD_DECLARATION |
| 1465 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1466 | #define DECLARE_INSTRUCTION(type) \ |
| 1467 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1468 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1469 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1470 | return other->Is##type(); \ |
| 1471 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1472 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1473 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1474 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1475 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1476 | const H##type* As##type() const { return this; } \ |
| 1477 | H##type* As##type() { return this; } |
| 1478 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1479 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1480 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1481 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1482 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1483 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1484 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1485 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1486 | // Hook for the IntrusiveForwardList<>. |
| 1487 | // TODO: Hide this better. |
| 1488 | IntrusiveForwardListHook hook; |
| 1489 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1490 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1491 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1492 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1493 | |
| 1494 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1495 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1496 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1497 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1498 | |
| 1499 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1500 | }; |
| 1501 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1502 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1503 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1504 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1505 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1506 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1507 | // by the used instructions. |
| 1508 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1509 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1510 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1511 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1512 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1513 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1514 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1515 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1516 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1517 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1518 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1522 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1523 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1524 | |
| 1525 | private: |
| 1526 | // Instruction used by the user. |
| 1527 | HInstruction* instruction_; |
| 1528 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1529 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1530 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1531 | }; |
| 1532 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1533 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1534 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1535 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1536 | struct HInputExtractor { |
| 1537 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1538 | return record.GetInstruction(); |
| 1539 | } |
| 1540 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1541 | return record.GetInstruction(); |
| 1542 | } |
| 1543 | }; |
| 1544 | |
| 1545 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1546 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1547 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1548 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1549 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1550 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1551 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1552 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1553 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1554 | * modify the value of a reference field read [although it may modify the |
| 1555 | * reference fetch prior to reading the field, which is represented by its own |
| 1556 | * write/read dependence]). The analysis makes conservative points-to |
| 1557 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1558 | * the same, and any reference read depends on any reference read without |
| 1559 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1560 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1561 | * The internal representation uses 38-bit and is described in the table below. |
| 1562 | * The first line indicates the side effect, and for field/array accesses the |
| 1563 | * second line indicates the type of the access (in the order of the |
| 1564 | * Primitive::Type enum). |
| 1565 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1566 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1567 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1568 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1569 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1570 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1571 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1572 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1573 | * |
| 1574 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1575 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1576 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1577 | class SideEffects : public ValueObject { |
| 1578 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1579 | SideEffects() : flags_(0) {} |
| 1580 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1581 | static SideEffects None() { |
| 1582 | return SideEffects(0); |
| 1583 | } |
| 1584 | |
| 1585 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1586 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1587 | } |
| 1588 | |
| 1589 | static SideEffects AllChanges() { |
| 1590 | return SideEffects(kAllChangeBits); |
| 1591 | } |
| 1592 | |
| 1593 | static SideEffects AllDependencies() { |
| 1594 | return SideEffects(kAllDependOnBits); |
| 1595 | } |
| 1596 | |
| 1597 | static SideEffects AllExceptGCDependency() { |
| 1598 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1599 | } |
| 1600 | |
| 1601 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1602 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1603 | } |
| 1604 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1605 | static SideEffects AllWrites() { |
| 1606 | return SideEffects(kAllWrites); |
| 1607 | } |
| 1608 | |
| 1609 | static SideEffects AllReads() { |
| 1610 | return SideEffects(kAllReads); |
| 1611 | } |
| 1612 | |
| 1613 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1614 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1615 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1616 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1617 | } |
| 1618 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1619 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1620 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1621 | } |
| 1622 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1623 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1624 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1625 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1626 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1630 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1633 | static SideEffects CanTriggerGC() { |
| 1634 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1635 | } |
| 1636 | |
| 1637 | static SideEffects DependsOnGC() { |
| 1638 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1639 | } |
| 1640 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1641 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1642 | SideEffects Union(SideEffects other) const { |
| 1643 | return SideEffects(flags_ | other.flags_); |
| 1644 | } |
| 1645 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1646 | SideEffects Exclusion(SideEffects other) const { |
| 1647 | return SideEffects(flags_ & ~other.flags_); |
| 1648 | } |
| 1649 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1650 | void Add(SideEffects other) { |
| 1651 | flags_ |= other.flags_; |
| 1652 | } |
| 1653 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1654 | bool Includes(SideEffects other) const { |
| 1655 | return (other.flags_ & flags_) == other.flags_; |
| 1656 | } |
| 1657 | |
| 1658 | bool HasSideEffects() const { |
| 1659 | return (flags_ & kAllChangeBits); |
| 1660 | } |
| 1661 | |
| 1662 | bool HasDependencies() const { |
| 1663 | return (flags_ & kAllDependOnBits); |
| 1664 | } |
| 1665 | |
| 1666 | // Returns true if there are no side effects or dependencies. |
| 1667 | bool DoesNothing() const { |
| 1668 | return flags_ == 0; |
| 1669 | } |
| 1670 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1671 | // Returns true if something is written. |
| 1672 | bool DoesAnyWrite() const { |
| 1673 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1674 | } |
| 1675 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1676 | // Returns true if something is read. |
| 1677 | bool DoesAnyRead() const { |
| 1678 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1679 | } |
| 1680 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1681 | // Returns true if potentially everything is written and read |
| 1682 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1683 | bool DoesAllReadWrite() const { |
| 1684 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1685 | } |
| 1686 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1687 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1688 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1691 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1692 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1693 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1694 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1698 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1699 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1700 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1701 | for (int s = kLastBit; s >= 0; s--) { |
| 1702 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1703 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1704 | // This is a bit for the GC side effect. |
| 1705 | if (current_bit_is_set) { |
| 1706 | flags += "GC"; |
| 1707 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1708 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1709 | } else { |
| 1710 | // This is a bit for the array/field analysis. |
| 1711 | // The underscore character stands for the 'can trigger GC' bit. |
| 1712 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1713 | if (current_bit_is_set) { |
| 1714 | flags += kDebug[s]; |
| 1715 | } |
| 1716 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1717 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1718 | flags += "|"; |
| 1719 | } |
| 1720 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1721 | } |
| 1722 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1723 | } |
| 1724 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1725 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1726 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1727 | private: |
| 1728 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1729 | |
| 1730 | static constexpr int kFieldWriteOffset = 0; |
| 1731 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1732 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1733 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1734 | |
| 1735 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1736 | |
| 1737 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1738 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1739 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1740 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1741 | |
| 1742 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1743 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1744 | |
| 1745 | // Aliases. |
| 1746 | |
| 1747 | static_assert(kChangeBits == kDependOnBits, |
| 1748 | "the 'change' bits should match the 'depend on' bits."); |
| 1749 | |
| 1750 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1751 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1752 | static constexpr uint64_t kAllWrites = |
| 1753 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1754 | static constexpr uint64_t kAllReads = |
| 1755 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1756 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1757 | // Translates type to bit flag. |
| 1758 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1759 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1760 | const uint64_t one = 1; |
| 1761 | const int shift = type; // 0-based consecutive enum |
| 1762 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1763 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1764 | return one << (type + offset); |
| 1765 | } |
| 1766 | |
| 1767 | // Private constructor on direct flags value. |
| 1768 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1769 | |
| 1770 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1771 | }; |
| 1772 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1773 | // 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] | 1774 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1775 | public: |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1776 | ALWAYS_INLINE HEnvironment(ArenaAllocator* arena, |
| 1777 | size_t number_of_vregs, |
| 1778 | ArtMethod* method, |
| 1779 | uint32_t dex_pc, |
| 1780 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1781 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1782 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1783 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1784 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1785 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1786 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1787 | } |
| 1788 | |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1789 | ALWAYS_INLINE HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1790 | : HEnvironment(arena, |
| 1791 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1792 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1793 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1794 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1795 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1796 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1797 | if (parent_ != nullptr) { |
| 1798 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1799 | } else { |
| 1800 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1801 | parent_->CopyFrom(parent); |
| 1802 | if (parent->GetParent() != nullptr) { |
| 1803 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1804 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1805 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1806 | } |
| 1807 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1808 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1809 | void CopyFrom(HEnvironment* environment); |
| 1810 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1811 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1812 | // input to the loop phi instead. This is for inserting instructions that |
| 1813 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1814 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1815 | |
| 1816 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1817 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1821 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1822 | } |
| 1823 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1824 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1825 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1826 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1827 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1828 | HEnvironment* GetParent() const { return parent_; } |
| 1829 | |
| 1830 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1831 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1835 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | uint32_t GetDexPc() const { |
| 1839 | return dex_pc_; |
| 1840 | } |
| 1841 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1842 | ArtMethod* GetMethod() const { |
| 1843 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1844 | } |
| 1845 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1846 | HInstruction* GetHolder() const { |
| 1847 | return holder_; |
| 1848 | } |
| 1849 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1850 | |
| 1851 | bool IsFromInlinedInvoke() const { |
| 1852 | return GetParent() != nullptr; |
| 1853 | } |
| 1854 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1855 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1856 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1857 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1858 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1859 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1860 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1861 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1862 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1863 | HInstruction* const holder_; |
| 1864 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1865 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1866 | |
| 1867 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1868 | }; |
| 1869 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1870 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1871 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1872 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1873 | : previous_(nullptr), |
| 1874 | next_(nullptr), |
| 1875 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1876 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1877 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1878 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1879 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1880 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1881 | locations_(nullptr), |
| 1882 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1883 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1884 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1885 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1886 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1887 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1888 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1889 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1890 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1891 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1892 | enum InstructionKind { |
| 1893 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1894 | }; |
| 1895 | #undef DECLARE_KIND |
| 1896 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1897 | HInstruction* GetNext() const { return next_; } |
| 1898 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1899 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1900 | HInstruction* GetNextDisregardingMoves() const; |
| 1901 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1902 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1903 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1904 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1905 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1906 | bool IsInBlock() const { return block_ != nullptr; } |
| 1907 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1908 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1909 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1910 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1911 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1912 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1913 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1914 | |
| 1915 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1916 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1917 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1918 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1919 | } |
| 1920 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1921 | HInputsRef GetInputs() { |
| 1922 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1923 | } |
| 1924 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1925 | HConstInputsRef GetInputs() const { |
| 1926 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1930 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1931 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 1932 | bool HasInput(HInstruction* input) const { |
| 1933 | for (const HInstruction* i : GetInputs()) { |
| 1934 | if (i == input) { |
| 1935 | return true; |
| 1936 | } |
| 1937 | } |
| 1938 | return false; |
| 1939 | } |
| 1940 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1941 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1942 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1943 | } |
| 1944 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1945 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1946 | virtual const char* DebugName() const = 0; |
| 1947 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1948 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1949 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1950 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1951 | |
| 1952 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1953 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1954 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1955 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 1956 | // Can the instruction throw? |
| 1957 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 1958 | // could throw OOME, but it is still OK to remove them if they are unused. |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1959 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1960 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1961 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1962 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1963 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1964 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1965 | // Does not apply for all instructions, but having this at top level greatly |
| 1966 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1967 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1968 | virtual bool CanBeNull() const { |
| 1969 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1970 | return true; |
| 1971 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1972 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1973 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1974 | return false; |
| 1975 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1976 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1977 | virtual bool IsActualObject() const { |
| 1978 | return GetType() == Primitive::kPrimNot; |
| 1979 | } |
| 1980 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1981 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1982 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1983 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1984 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1985 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1986 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1987 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1988 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1989 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1990 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1991 | // Note: fixup_end remains valid across push_front(). |
| 1992 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1993 | HUseListNode<HInstruction*>* new_node = |
| 1994 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1995 | uses_.push_front(*new_node); |
| 1996 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1997 | } |
| 1998 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1999 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2000 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2001 | // Note: env_fixup_end remains valid across push_front(). |
| 2002 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2003 | HUseListNode<HEnvironment*>* new_node = |
| 2004 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 2005 | env_uses_.push_front(*new_node); |
| 2006 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2007 | } |
| 2008 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2009 | void RemoveAsUserOfInput(size_t input) { |
| 2010 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2011 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2012 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2013 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2014 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2015 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2016 | void RemoveAsUserOfAllInputs() { |
| 2017 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2018 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2019 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2020 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2021 | } |
| 2022 | } |
| 2023 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2024 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2025 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2026 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2027 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2028 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2029 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2030 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2031 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2032 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2033 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2034 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2035 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2036 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2037 | !CanThrow() && |
| 2038 | !IsSuspendCheck() && |
| 2039 | !IsControlFlow() && |
| 2040 | !IsNativeDebugInfo() && |
| 2041 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2042 | // If we added an explicit barrier then we should keep it. |
| 2043 | !IsMemoryBarrier(); |
| 2044 | } |
| 2045 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2046 | bool IsDeadAndRemovable() const { |
| 2047 | return IsRemovable() && !HasUses(); |
| 2048 | } |
| 2049 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2050 | // Does this instruction strictly dominate `other_instruction`? |
| 2051 | // Returns false if this instruction and `other_instruction` are the same. |
| 2052 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2053 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2054 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2055 | int GetId() const { return id_; } |
| 2056 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2057 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2058 | int GetSsaIndex() const { return ssa_index_; } |
| 2059 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2060 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2061 | |
| 2062 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2063 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2064 | // Set the `environment_` field. Raw because this method does not |
| 2065 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2066 | void SetRawEnvironment(HEnvironment* environment) { |
| 2067 | DCHECK(environment_ == nullptr); |
| 2068 | DCHECK_EQ(environment->GetHolder(), this); |
| 2069 | environment_ = environment; |
| 2070 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2071 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2072 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2073 | DCHECK(environment_ != nullptr); |
| 2074 | DCHECK_EQ(environment->GetHolder(), this); |
| 2075 | DCHECK(environment->GetParent() == nullptr); |
| 2076 | environment->parent_ = environment_; |
| 2077 | environment_ = environment; |
| 2078 | } |
| 2079 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2080 | void RemoveEnvironment(); |
| 2081 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2082 | // Set the environment of this instruction, copying it from `environment`. While |
| 2083 | // copying, the uses lists are being updated. |
| 2084 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2085 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2086 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2087 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2088 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2089 | if (environment->GetParent() != nullptr) { |
| 2090 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2091 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2092 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2093 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2094 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2095 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2096 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2097 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2098 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2099 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2100 | if (environment->GetParent() != nullptr) { |
| 2101 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2102 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2105 | // Returns the number of entries in the environment. Typically, that is the |
| 2106 | // number of dex registers in a method. It could be more in case of inlining. |
| 2107 | size_t EnvironmentSize() const; |
| 2108 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2109 | LocationSummary* GetLocations() const { return locations_; } |
| 2110 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2111 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2112 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2113 | void ReplaceUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2114 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2115 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2116 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2117 | // uses of this instruction by `other` are *not* updated. |
| 2118 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2119 | ReplaceWith(other); |
| 2120 | other->ReplaceInput(this, use_index); |
| 2121 | } |
| 2122 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2123 | // Move `this` instruction before `cursor` |
| 2124 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2125 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2126 | // Move `this` before its first user and out of any loops. If there is no |
| 2127 | // out-of-loop user that dominates all other users, move the instruction |
| 2128 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2129 | // |
| 2130 | // This can be used only on non-throwing instructions with no side effects that |
| 2131 | // have at least one use but no environment uses. |
| 2132 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2133 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2134 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2135 | bool Is##type() const; \ |
| 2136 | const H##type* As##type() const; \ |
| 2137 | H##type* As##type(); |
| 2138 | |
| 2139 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2140 | #undef INSTRUCTION_TYPE_CHECK |
| 2141 | |
| 2142 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2143 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2144 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2145 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2146 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2147 | #undef INSTRUCTION_TYPE_CHECK |
| 2148 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2149 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2150 | // TODO: this method is used by LICM and GVN with possibly different |
| 2151 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2152 | virtual bool CanBeMoved() const { return false; } |
| 2153 | |
| 2154 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2155 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2156 | return false; |
| 2157 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2158 | |
| 2159 | // Returns whether any data encoded in the two instructions is equal. |
| 2160 | // This method does not look at the inputs. Both instructions must be |
| 2161 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2162 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2163 | return false; |
| 2164 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2165 | |
| 2166 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2167 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2168 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2169 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2170 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2171 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2172 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2173 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2174 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2175 | InstructionKind GetKind() const PURE; |
| 2176 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2177 | |
| 2178 | virtual size_t ComputeHashCode() const { |
| 2179 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2180 | for (const HInstruction* input : GetInputs()) { |
| 2181 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2182 | } |
| 2183 | return result; |
| 2184 | } |
| 2185 | |
| 2186 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2187 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2188 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2189 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2190 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2191 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2192 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2193 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2194 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2195 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2196 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2197 | |
| 2198 | // Returns whether the code generation of the instruction will require to have access |
| 2199 | // to the current method. Such instructions are: |
| 2200 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2201 | // 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] | 2202 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2203 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2204 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2205 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2206 | } |
| 2207 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2208 | // Returns whether the code generation of the instruction will require to have access |
| 2209 | // to the dex cache of the current method's declaring class via the current method. |
| 2210 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2211 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2212 | // Does this instruction have any use in an environment before |
| 2213 | // control flow hits 'other'? |
| 2214 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2215 | |
| 2216 | // Remove all references to environment uses of this instruction. |
| 2217 | // The caller must ensure that this is safe to do. |
| 2218 | void RemoveEnvironmentUsers(); |
| 2219 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2220 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2221 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2222 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2223 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2224 | // If set, the machine code for this instruction is assumed to be generated by |
| 2225 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2226 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2227 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2228 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2229 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2230 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2231 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2232 | return GetInputRecords()[i]; |
| 2233 | } |
| 2234 | |
| 2235 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2236 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2237 | input_records[index] = input; |
| 2238 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2239 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2240 | uint32_t GetPackedFields() const { |
| 2241 | return packed_fields_; |
| 2242 | } |
| 2243 | |
| 2244 | template <size_t flag> |
| 2245 | bool GetPackedFlag() const { |
| 2246 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2247 | } |
| 2248 | |
| 2249 | template <size_t flag> |
| 2250 | void SetPackedFlag(bool value = true) { |
| 2251 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2252 | } |
| 2253 | |
| 2254 | template <typename BitFieldType> |
| 2255 | typename BitFieldType::value_type GetPackedField() const { |
| 2256 | return BitFieldType::Decode(packed_fields_); |
| 2257 | } |
| 2258 | |
| 2259 | template <typename BitFieldType> |
| 2260 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2261 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2262 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2263 | } |
| 2264 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2265 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2266 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2267 | auto before_use_node = uses_.before_begin(); |
| 2268 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2269 | HInstruction* user = use_node->GetUser(); |
| 2270 | size_t input_index = use_node->GetIndex(); |
| 2271 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2272 | before_use_node = use_node; |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2277 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2278 | if (next != uses_.end()) { |
| 2279 | HInstruction* next_user = next->GetUser(); |
| 2280 | size_t next_index = next->GetIndex(); |
| 2281 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2282 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2283 | } |
| 2284 | } |
| 2285 | |
| 2286 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2287 | auto before_env_use_node = env_uses_.before_begin(); |
| 2288 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2289 | HEnvironment* user = env_use_node->GetUser(); |
| 2290 | size_t input_index = env_use_node->GetIndex(); |
| 2291 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2292 | before_env_use_node = env_use_node; |
| 2293 | } |
| 2294 | } |
| 2295 | |
| 2296 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2297 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2298 | if (next != env_uses_.end()) { |
| 2299 | HEnvironment* next_user = next->GetUser(); |
| 2300 | size_t next_index = next->GetIndex(); |
| 2301 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2302 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2303 | } |
| 2304 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2305 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2306 | HInstruction* previous_; |
| 2307 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2308 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2309 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2310 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2311 | // An instruction gets an id when it is added to the graph. |
| 2312 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2313 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2314 | int id_; |
| 2315 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2316 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2317 | int ssa_index_; |
| 2318 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2319 | // Packed fields. |
| 2320 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2321 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2322 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2323 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2324 | |
| 2325 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2326 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2327 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2328 | // The environment associated with this instruction. Not null if the instruction |
| 2329 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2330 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2331 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2332 | // Set by the code generator. |
| 2333 | LocationSummary* locations_; |
| 2334 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2335 | // Set by the liveness analysis. |
| 2336 | LiveInterval* live_interval_; |
| 2337 | |
| 2338 | // Set by the liveness analysis, this is the position in a linear |
| 2339 | // order of blocks where this instruction's live interval start. |
| 2340 | size_t lifetime_position_; |
| 2341 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2342 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2343 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2344 | // The reference handle part of the reference type info. |
| 2345 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2346 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2347 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2348 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2349 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2350 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2351 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2352 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2353 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2354 | |
| 2355 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2356 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2357 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2358 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2359 | // Iterates over the instructions, while preserving the next instruction |
| 2360 | // in case the current instruction gets removed from the list by the user |
| 2361 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2362 | class HInstructionIterator : public ValueObject { |
| 2363 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2364 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2365 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2366 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2367 | } |
| 2368 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2369 | bool Done() const { return instruction_ == nullptr; } |
| 2370 | HInstruction* Current() const { return instruction_; } |
| 2371 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2372 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2373 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | private: |
| 2377 | HInstruction* instruction_; |
| 2378 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2379 | |
| 2380 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2381 | }; |
| 2382 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2383 | // Iterates over the instructions without saving the next instruction, |
| 2384 | // therefore handling changes in the graph potentially made by the user |
| 2385 | // of this iterator. |
| 2386 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2387 | public: |
| 2388 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2389 | : instruction_(instructions.first_instruction_) { |
| 2390 | } |
| 2391 | |
| 2392 | bool Done() const { return instruction_ == nullptr; } |
| 2393 | HInstruction* Current() const { return instruction_; } |
| 2394 | void Advance() { |
| 2395 | instruction_ = instruction_->GetNext(); |
| 2396 | } |
| 2397 | |
| 2398 | private: |
| 2399 | HInstruction* instruction_; |
| 2400 | |
| 2401 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2402 | }; |
| 2403 | |
| 2404 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2405 | class HBackwardInstructionIterator : public ValueObject { |
| 2406 | public: |
| 2407 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2408 | : instruction_(instructions.last_instruction_) { |
| 2409 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2410 | } |
| 2411 | |
| 2412 | bool Done() const { return instruction_ == nullptr; } |
| 2413 | HInstruction* Current() const { return instruction_; } |
| 2414 | void Advance() { |
| 2415 | instruction_ = next_; |
| 2416 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2417 | } |
| 2418 | |
| 2419 | private: |
| 2420 | HInstruction* instruction_; |
| 2421 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2422 | |
| 2423 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2424 | }; |
| 2425 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2426 | class HVariableInputSizeInstruction : public HInstruction { |
| 2427 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2428 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2429 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 2430 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2431 | } |
| 2432 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2433 | void AddInput(HInstruction* input); |
| 2434 | void InsertInputAt(size_t index, HInstruction* input); |
| 2435 | void RemoveInputAt(size_t index); |
| 2436 | |
| 2437 | protected: |
| 2438 | HVariableInputSizeInstruction(SideEffects side_effects, |
| 2439 | uint32_t dex_pc, |
| 2440 | ArenaAllocator* arena, |
| 2441 | size_t number_of_inputs, |
| 2442 | ArenaAllocKind kind) |
| 2443 | : HInstruction(side_effects, dex_pc), |
| 2444 | inputs_(number_of_inputs, arena->Adapter(kind)) {} |
| 2445 | |
| 2446 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
| 2447 | |
| 2448 | private: |
| 2449 | DISALLOW_COPY_AND_ASSIGN(HVariableInputSizeInstruction); |
| 2450 | }; |
| 2451 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2452 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2453 | class HTemplateInstruction: public HInstruction { |
| 2454 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2455 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2456 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2457 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2458 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2459 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2460 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2461 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2464 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2465 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2466 | |
| 2467 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2468 | }; |
| 2469 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2470 | // HTemplateInstruction specialization for N=0. |
| 2471 | template<> |
| 2472 | class HTemplateInstruction<0>: public HInstruction { |
| 2473 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2474 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2475 | : HInstruction(side_effects, dex_pc) {} |
| 2476 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2477 | virtual ~HTemplateInstruction() {} |
| 2478 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2479 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2480 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2481 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | private: |
| 2485 | friend class SsaBuilder; |
| 2486 | }; |
| 2487 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2488 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2489 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2490 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2491 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2492 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2493 | this->template SetPackedField<TypeField>(type); |
| 2494 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2495 | virtual ~HExpression() {} |
| 2496 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2497 | Primitive::Type GetType() const OVERRIDE { |
| 2498 | return TypeField::Decode(this->GetPackedFields()); |
| 2499 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2500 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2501 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2502 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2503 | static constexpr size_t kFieldTypeSize = |
| 2504 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2505 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2506 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2507 | "Too many packed fields."); |
| 2508 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2509 | }; |
| 2510 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2511 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2512 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2513 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2514 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2515 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2516 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2517 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2518 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2519 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2520 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2521 | |
| 2522 | private: |
| 2523 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2524 | }; |
| 2525 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2526 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2527 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2528 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2529 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2530 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2531 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2532 | SetRawInputAt(0, value); |
| 2533 | } |
| 2534 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2535 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2536 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2537 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2538 | |
| 2539 | private: |
| 2540 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2541 | }; |
| 2542 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2543 | class HPhi FINAL : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2544 | public: |
| 2545 | HPhi(ArenaAllocator* arena, |
| 2546 | uint32_t reg_number, |
| 2547 | size_t number_of_inputs, |
| 2548 | Primitive::Type type, |
| 2549 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2550 | : HVariableInputSizeInstruction( |
| 2551 | SideEffects::None(), |
| 2552 | dex_pc, |
| 2553 | arena, |
| 2554 | number_of_inputs, |
| 2555 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2556 | reg_number_(reg_number) { |
| 2557 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2558 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2559 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2560 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2561 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2562 | SetPackedFlag<kFlagIsLive>(true); |
| 2563 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2564 | } |
| 2565 | |
| 2566 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2567 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2568 | return Primitive::PrimitiveKind(type); |
| 2569 | } |
| 2570 | |
| 2571 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2572 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2573 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2574 | void SetType(Primitive::Type new_type) { |
| 2575 | // Make sure that only valid type changes occur. The following are allowed: |
| 2576 | // (1) int -> float/ref (primitive type propagation), |
| 2577 | // (2) long -> double (primitive type propagation). |
| 2578 | DCHECK(GetType() == new_type || |
| 2579 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2580 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2581 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2582 | SetPackedField<TypeField>(new_type); |
| 2583 | } |
| 2584 | |
| 2585 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2586 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2587 | |
| 2588 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2589 | |
| 2590 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2591 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2592 | bool IsDead() const { return !IsLive(); } |
| 2593 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2594 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2595 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2596 | return other != nullptr |
| 2597 | && other->IsPhi() |
| 2598 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2599 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2600 | } |
| 2601 | |
| 2602 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2603 | // An equivalent phi is a phi having the same dex register and type. |
| 2604 | // It assumes that phis with the same dex register are adjacent. |
| 2605 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2606 | HInstruction* next = GetNext(); |
| 2607 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2608 | if (next->GetType() == GetType()) { |
| 2609 | return next->AsPhi(); |
| 2610 | } |
| 2611 | next = next->GetNext(); |
| 2612 | } |
| 2613 | return nullptr; |
| 2614 | } |
| 2615 | |
| 2616 | DECLARE_INSTRUCTION(Phi); |
| 2617 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2618 | private: |
| 2619 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2620 | static constexpr size_t kFieldTypeSize = |
| 2621 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2622 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2623 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2624 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2625 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2626 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2627 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2628 | const uint32_t reg_number_; |
| 2629 | |
| 2630 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2631 | }; |
| 2632 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2633 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2634 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2635 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2636 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2637 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2638 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2639 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2640 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2641 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2642 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2643 | |
| 2644 | private: |
| 2645 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2646 | }; |
| 2647 | |
| 2648 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2649 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2650 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2651 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2652 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2653 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2654 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2655 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2656 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2657 | } |
| 2658 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2659 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2660 | |
| 2661 | private: |
| 2662 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2663 | }; |
| 2664 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2665 | class HConstant : public HExpression<0> { |
| 2666 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2667 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2668 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2669 | |
| 2670 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2671 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2672 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2673 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2674 | // Is this constant 0 in the arithmetic sense? |
| 2675 | virtual bool IsArithmeticZero() const { return false; } |
| 2676 | // Is this constant a 0-bit pattern? |
| 2677 | virtual bool IsZeroBitPattern() const { return false; } |
| 2678 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2679 | virtual bool IsOne() const { return false; } |
| 2680 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2681 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2682 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2683 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2684 | |
| 2685 | private: |
| 2686 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2687 | }; |
| 2688 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2689 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2690 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2691 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2692 | return true; |
| 2693 | } |
| 2694 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2695 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2696 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2697 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2698 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2699 | // The null constant representation is a 0-bit pattern. |
| 2700 | virtual bool IsZeroBitPattern() const { return true; } |
| 2701 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2702 | DECLARE_INSTRUCTION(NullConstant); |
| 2703 | |
| 2704 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2705 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2706 | |
| 2707 | friend class HGraph; |
| 2708 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2709 | }; |
| 2710 | |
| 2711 | // Constants of the type int. Those can be from Dex instructions, or |
| 2712 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2713 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2714 | public: |
| 2715 | int32_t GetValue() const { return value_; } |
| 2716 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2717 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2718 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2719 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 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->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2723 | return other->AsIntConstant()->value_ == value_; |
| 2724 | } |
| 2725 | |
| 2726 | size_t ComputeHashCode() const OVERRIDE { return 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 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2733 | // Integer constants are used to encode Boolean values as well, |
| 2734 | // where 1 means true and 0 means false. |
| 2735 | bool IsTrue() const { return GetValue() == 1; } |
| 2736 | bool IsFalse() const { return GetValue() == 0; } |
| 2737 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2738 | DECLARE_INSTRUCTION(IntConstant); |
| 2739 | |
| 2740 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2741 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2742 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2743 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2744 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2745 | |
| 2746 | const int32_t value_; |
| 2747 | |
| 2748 | friend class HGraph; |
| 2749 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2750 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2751 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2752 | }; |
| 2753 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2754 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2755 | public: |
| 2756 | int64_t GetValue() const { return value_; } |
| 2757 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2758 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2759 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2760 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2761 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2762 | return other->AsLongConstant()->value_ == value_; |
| 2763 | } |
| 2764 | |
| 2765 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2766 | |
| 2767 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2768 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2769 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2770 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2771 | |
| 2772 | DECLARE_INSTRUCTION(LongConstant); |
| 2773 | |
| 2774 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2775 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2776 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2777 | |
| 2778 | const int64_t value_; |
| 2779 | |
| 2780 | friend class HGraph; |
| 2781 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2782 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2783 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2784 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2785 | public: |
| 2786 | float GetValue() const { return value_; } |
| 2787 | |
| 2788 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2789 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2790 | } |
| 2791 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2792 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2793 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2794 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2795 | } |
| 2796 | |
| 2797 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2798 | |
| 2799 | bool IsMinusOne() const OVERRIDE { |
| 2800 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2801 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2802 | bool IsArithmeticZero() const OVERRIDE { |
| 2803 | return std::fpclassify(value_) == FP_ZERO; |
| 2804 | } |
| 2805 | bool IsArithmeticPositiveZero() const { |
| 2806 | return IsArithmeticZero() && !std::signbit(value_); |
| 2807 | } |
| 2808 | bool IsArithmeticNegativeZero() const { |
| 2809 | return IsArithmeticZero() && std::signbit(value_); |
| 2810 | } |
| 2811 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2812 | 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] | 2813 | } |
| 2814 | bool IsOne() const OVERRIDE { |
| 2815 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2816 | } |
| 2817 | bool IsNaN() const { |
| 2818 | return std::isnan(value_); |
| 2819 | } |
| 2820 | |
| 2821 | DECLARE_INSTRUCTION(FloatConstant); |
| 2822 | |
| 2823 | private: |
| 2824 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2825 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2826 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2827 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2828 | |
| 2829 | const float value_; |
| 2830 | |
| 2831 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2832 | friend class SsaBuilder; |
| 2833 | friend class HGraph; |
| 2834 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2835 | }; |
| 2836 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2837 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2838 | public: |
| 2839 | double GetValue() const { return value_; } |
| 2840 | |
| 2841 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2842 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2843 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2844 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2845 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2846 | } |
| 2847 | |
| 2848 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2849 | |
| 2850 | bool IsMinusOne() const OVERRIDE { |
| 2851 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2852 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2853 | bool IsArithmeticZero() const OVERRIDE { |
| 2854 | return std::fpclassify(value_) == FP_ZERO; |
| 2855 | } |
| 2856 | bool IsArithmeticPositiveZero() const { |
| 2857 | return IsArithmeticZero() && !std::signbit(value_); |
| 2858 | } |
| 2859 | bool IsArithmeticNegativeZero() const { |
| 2860 | return IsArithmeticZero() && std::signbit(value_); |
| 2861 | } |
| 2862 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2863 | 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] | 2864 | } |
| 2865 | bool IsOne() const OVERRIDE { |
| 2866 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2867 | } |
| 2868 | bool IsNaN() const { |
| 2869 | return std::isnan(value_); |
| 2870 | } |
| 2871 | |
| 2872 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2873 | |
| 2874 | private: |
| 2875 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2876 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2877 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2878 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2879 | |
| 2880 | const double value_; |
| 2881 | |
| 2882 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2883 | friend class SsaBuilder; |
| 2884 | friend class HGraph; |
| 2885 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2886 | }; |
| 2887 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2888 | // Conditional branch. A block ending with an HIf instruction must have |
| 2889 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2890 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2891 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2892 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2893 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2894 | SetRawInputAt(0, input); |
| 2895 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2896 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2897 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2898 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2899 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2900 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2904 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2905 | } |
| 2906 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2907 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2908 | |
| 2909 | private: |
| 2910 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2911 | }; |
| 2912 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2913 | |
| 2914 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2915 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2916 | // non-exceptional control flow. |
| 2917 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2918 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2919 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2920 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2921 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2922 | kEntry, |
| 2923 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2924 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2925 | }; |
| 2926 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2927 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2928 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2929 | SetPackedField<BoundaryKindField>(kind); |
| 2930 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2931 | |
| 2932 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2933 | |
| 2934 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2935 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2936 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2937 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2938 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2939 | } |
| 2940 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2941 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2942 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2943 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2944 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2945 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | // If not present already, adds `handler` to its block's list of exception |
| 2949 | // handlers. |
| 2950 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2951 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2952 | GetBlock()->AddSuccessor(handler); |
| 2953 | } |
| 2954 | } |
| 2955 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2956 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2957 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2958 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2959 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2960 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2961 | DECLARE_INSTRUCTION(TryBoundary); |
| 2962 | |
| 2963 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2964 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2965 | static constexpr size_t kFieldBoundaryKindSize = |
| 2966 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2967 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2968 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2969 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2970 | "Too many packed fields."); |
| 2971 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2972 | |
| 2973 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2974 | }; |
| 2975 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2976 | // Deoptimize to interpreter, upon checking a condition. |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2977 | class HDeoptimize FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2978 | public: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2979 | enum class Kind { |
| 2980 | kBCE, |
| 2981 | kInline, |
| 2982 | kLast = kInline |
| 2983 | }; |
| 2984 | |
| 2985 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 2986 | // across. |
| 2987 | HDeoptimize(ArenaAllocator* arena, HInstruction* cond, Kind kind, uint32_t dex_pc) |
| 2988 | : HVariableInputSizeInstruction( |
| 2989 | SideEffects::All(), |
| 2990 | dex_pc, |
| 2991 | arena, |
| 2992 | /* number_of_inputs */ 1, |
| 2993 | kArenaAllocMisc) { |
| 2994 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 2995 | SetPackedField<DeoptimizeKindField>(kind); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2996 | SetRawInputAt(0, cond); |
| 2997 | } |
| 2998 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2999 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3000 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3001 | // instead of `guard`. |
| 3002 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3003 | // at the point of the `HDeoptimize`. |
| 3004 | HDeoptimize(ArenaAllocator* arena, |
| 3005 | HInstruction* cond, |
| 3006 | HInstruction* guard, |
| 3007 | Kind kind, |
| 3008 | uint32_t dex_pc) |
| 3009 | : HVariableInputSizeInstruction( |
| 3010 | SideEffects::CanTriggerGC(), |
| 3011 | dex_pc, |
| 3012 | arena, |
| 3013 | /* number_of_inputs */ 2, |
| 3014 | kArenaAllocMisc) { |
| 3015 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3016 | SetPackedField<DeoptimizeKindField>(kind); |
| 3017 | SetRawInputAt(0, cond); |
| 3018 | SetRawInputAt(1, guard); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3019 | } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3020 | |
| 3021 | bool CanBeMoved() const OVERRIDE { return GetPackedFlag<kFieldCanBeMoved>(); } |
| 3022 | |
| 3023 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 3024 | return (other->CanBeMoved() == CanBeMoved()) && (other->AsDeoptimize()->GetKind() == GetKind()); |
| 3025 | } |
| 3026 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3027 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3028 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3029 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3030 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3031 | Kind GetKind() const { return GetPackedField<DeoptimizeKindField>(); } |
| 3032 | |
| 3033 | Primitive::Type GetType() const OVERRIDE { |
| 3034 | return GuardsAnInput() ? GuardedInput()->GetType() : Primitive::kPrimVoid; |
| 3035 | } |
| 3036 | |
| 3037 | bool GuardsAnInput() const { |
| 3038 | return InputCount() == 2; |
| 3039 | } |
| 3040 | |
| 3041 | HInstruction* GuardedInput() const { |
| 3042 | DCHECK(GuardsAnInput()); |
| 3043 | return InputAt(1); |
| 3044 | } |
| 3045 | |
| 3046 | void RemoveGuard() { |
| 3047 | RemoveInputAt(1); |
| 3048 | } |
| 3049 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3050 | DECLARE_INSTRUCTION(Deoptimize); |
| 3051 | |
| 3052 | private: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3053 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3054 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3055 | static constexpr size_t kFieldDeoptimizeKindSize = |
| 3056 | MinimumBitsToStore(static_cast<size_t>(Kind::kLast)); |
| 3057 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3058 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3059 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3060 | "Too many packed fields."); |
| 3061 | using DeoptimizeKindField = BitField<Kind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
| 3062 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3063 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 3064 | }; |
| 3065 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3066 | std::ostream& operator<<(std::ostream& os, const HDeoptimize::Kind& rhs); |
| 3067 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3068 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3069 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3070 | // if it's true, starts to do deoptimization. |
| 3071 | // It has a 4-byte slot on stack. |
| 3072 | // TODO: allocate a register for this flag. |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3073 | class HShouldDeoptimizeFlag FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3074 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3075 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3076 | // with regard to other passes. |
| 3077 | HShouldDeoptimizeFlag(ArenaAllocator* arena, uint32_t dex_pc) |
| 3078 | : HVariableInputSizeInstruction(SideEffects::None(), dex_pc, arena, 0, kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3081 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimInt; } |
| 3082 | |
| 3083 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3084 | // further guard elimination/motion since a guard might have been used for justification |
| 3085 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3086 | // to avoid other optimizations trying to move it. |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3087 | bool CanBeMoved() const OVERRIDE { return false; } |
| 3088 | |
| 3089 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3090 | |
| 3091 | private: |
| 3092 | DISALLOW_COPY_AND_ASSIGN(HShouldDeoptimizeFlag); |
| 3093 | }; |
| 3094 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3095 | // Represents the ArtMethod that was passed as a first argument to |
| 3096 | // the method. It is used by instructions that depend on it, like |
| 3097 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3098 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3099 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3100 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3101 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3102 | |
| 3103 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3104 | |
| 3105 | private: |
| 3106 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 3107 | }; |
| 3108 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3109 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3110 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3111 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3112 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3113 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3114 | kVTable, |
| 3115 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3116 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3117 | }; |
| 3118 | HClassTableGet(HInstruction* cls, |
| 3119 | Primitive::Type type, |
| 3120 | TableKind kind, |
| 3121 | size_t index, |
| 3122 | uint32_t dex_pc) |
| 3123 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3124 | index_(index) { |
| 3125 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3126 | SetRawInputAt(0, cls); |
| 3127 | } |
| 3128 | |
| 3129 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3130 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3131 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3132 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3133 | } |
| 3134 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3135 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3136 | size_t GetIndex() const { return index_; } |
| 3137 | |
| 3138 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3139 | |
| 3140 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3141 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 3142 | static constexpr size_t kFieldTableKindSize = |
| 3143 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3144 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3145 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3146 | "Too many packed fields."); |
| 3147 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3148 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3149 | // The index of the ArtMethod in the table. |
| 3150 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3151 | |
| 3152 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 3153 | }; |
| 3154 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3155 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3156 | // have one successor for each entry in the switch table, and the final successor |
| 3157 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3158 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3159 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3160 | HPackedSwitch(int32_t start_value, |
| 3161 | uint32_t num_entries, |
| 3162 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3163 | uint32_t dex_pc = kNoDexPc) |
| 3164 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 3165 | start_value_(start_value), |
| 3166 | num_entries_(num_entries) { |
| 3167 | SetRawInputAt(0, input); |
| 3168 | } |
| 3169 | |
| 3170 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3171 | |
| 3172 | int32_t GetStartValue() const { return start_value_; } |
| 3173 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3174 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3175 | |
| 3176 | HBasicBlock* GetDefaultBlock() const { |
| 3177 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3178 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3179 | } |
| 3180 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3181 | |
| 3182 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3183 | const int32_t start_value_; |
| 3184 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3185 | |
| 3186 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 3187 | }; |
| 3188 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3189 | class HUnaryOperation : public HExpression<1> { |
| 3190 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3191 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3192 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3193 | SetRawInputAt(0, input); |
| 3194 | } |
| 3195 | |
| 3196 | HInstruction* GetInput() const { return InputAt(0); } |
| 3197 | Primitive::Type GetResultType() const { return GetType(); } |
| 3198 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3199 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3200 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3201 | return true; |
| 3202 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3203 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3204 | // Try to statically evaluate `this` and return a HConstant |
| 3205 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3206 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3207 | HConstant* TryStaticEvaluation() const; |
| 3208 | |
| 3209 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3210 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3211 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3212 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3213 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3214 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3215 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3216 | |
| 3217 | private: |
| 3218 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 3219 | }; |
| 3220 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3221 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3222 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3223 | HBinaryOperation(Primitive::Type result_type, |
| 3224 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3225 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3226 | SideEffects side_effects = SideEffects::None(), |
| 3227 | uint32_t dex_pc = kNoDexPc) |
| 3228 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3229 | SetRawInputAt(0, left); |
| 3230 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3231 | } |
| 3232 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3233 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3234 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3235 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3236 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3237 | virtual bool IsCommutative() const { return false; } |
| 3238 | |
| 3239 | // Put constant on the right. |
| 3240 | // Returns whether order is changed. |
| 3241 | bool OrderInputsWithConstantOnTheRight() { |
| 3242 | HInstruction* left = InputAt(0); |
| 3243 | HInstruction* right = InputAt(1); |
| 3244 | if (left->IsConstant() && !right->IsConstant()) { |
| 3245 | ReplaceInput(right, 0); |
| 3246 | ReplaceInput(left, 1); |
| 3247 | return true; |
| 3248 | } |
| 3249 | return false; |
| 3250 | } |
| 3251 | |
| 3252 | // Order inputs by instruction id, but favor constant on the right side. |
| 3253 | // This helps GVN for commutative ops. |
| 3254 | void OrderInputs() { |
| 3255 | DCHECK(IsCommutative()); |
| 3256 | HInstruction* left = InputAt(0); |
| 3257 | HInstruction* right = InputAt(1); |
| 3258 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3259 | return; |
| 3260 | } |
| 3261 | if (OrderInputsWithConstantOnTheRight()) { |
| 3262 | return; |
| 3263 | } |
| 3264 | // Order according to instruction id. |
| 3265 | if (left->GetId() > right->GetId()) { |
| 3266 | ReplaceInput(right, 0); |
| 3267 | ReplaceInput(left, 1); |
| 3268 | } |
| 3269 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3270 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3271 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3272 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3273 | return true; |
| 3274 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3275 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3276 | // Try to statically evaluate `this` and return a HConstant |
| 3277 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3278 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3279 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3280 | |
| 3281 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3282 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3283 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3284 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3285 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3286 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3287 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3288 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3289 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3290 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3291 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3292 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3293 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3294 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3295 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3296 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3297 | // 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] | 3298 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3299 | HConstant* GetConstantRight() const; |
| 3300 | |
| 3301 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3302 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3303 | HInstruction* GetLeastConstantLeft() const; |
| 3304 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3305 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3306 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3307 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3308 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3309 | }; |
| 3310 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3311 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3312 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3313 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3314 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3315 | kGtBias, // return 1 for NaN comparisons |
| 3316 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3317 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3318 | }; |
| 3319 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3320 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3321 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3322 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3323 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3324 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3325 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3326 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3327 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3328 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3329 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3330 | // `instruction`, and disregard moves in between. |
| 3331 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3332 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3333 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3334 | |
| 3335 | virtual IfCondition GetCondition() const = 0; |
| 3336 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3337 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3338 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3339 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3340 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3341 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3342 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3343 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3344 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3345 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3346 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3347 | } |
| 3348 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3349 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3350 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3351 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3352 | if (if_cond == kCondNE) { |
| 3353 | return true; |
| 3354 | } else if (if_cond == kCondEQ) { |
| 3355 | return false; |
| 3356 | } |
| 3357 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3361 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3362 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3363 | if (if_cond == kCondEQ) { |
| 3364 | return true; |
| 3365 | } else if (if_cond == kCondNE) { |
| 3366 | return false; |
| 3367 | } |
| 3368 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3369 | } |
| 3370 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3371 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3372 | // Needed if we merge a HCompare into a HCondition. |
| 3373 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3374 | static constexpr size_t kFieldComparisonBiasSize = |
| 3375 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3376 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3377 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3378 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3379 | using ComparisonBiasField = |
| 3380 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3381 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3382 | template <typename T> |
| 3383 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3384 | |
| 3385 | template <typename T> |
| 3386 | int32_t CompareFP(T x, T y) const { |
| 3387 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3388 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3389 | // Handle the bias. |
| 3390 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3391 | } |
| 3392 | |
| 3393 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3394 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3395 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3396 | } |
| 3397 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3398 | private: |
| 3399 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3400 | }; |
| 3401 | |
| 3402 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3403 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3404 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3405 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3406 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3407 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3408 | bool IsCommutative() const OVERRIDE { return true; } |
| 3409 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3410 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3411 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3412 | return MakeConstantCondition(true, GetDexPc()); |
| 3413 | } |
| 3414 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3415 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3416 | } |
| 3417 | // In the following Evaluate methods, a HCompare instruction has |
| 3418 | // been merged into this HEqual instruction; evaluate it as |
| 3419 | // `Compare(x, y) == 0`. |
| 3420 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3421 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3422 | GetDexPc()); |
| 3423 | } |
| 3424 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3425 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3426 | } |
| 3427 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3428 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3429 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3430 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3431 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3432 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3433 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3434 | return kCondEQ; |
| 3435 | } |
| 3436 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3437 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3438 | return kCondNE; |
| 3439 | } |
| 3440 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3441 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3442 | 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] | 3443 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3444 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3445 | }; |
| 3446 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3447 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3448 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3449 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3450 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3451 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3452 | bool IsCommutative() const OVERRIDE { return true; } |
| 3453 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3454 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3455 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3456 | return MakeConstantCondition(false, GetDexPc()); |
| 3457 | } |
| 3458 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3459 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3460 | } |
| 3461 | // In the following Evaluate methods, a HCompare instruction has |
| 3462 | // been merged into this HNotEqual instruction; evaluate it as |
| 3463 | // `Compare(x, y) != 0`. |
| 3464 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3465 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3466 | } |
| 3467 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3468 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3469 | } |
| 3470 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3471 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3472 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3473 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3474 | DECLARE_INSTRUCTION(NotEqual); |
| 3475 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3476 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3477 | return kCondNE; |
| 3478 | } |
| 3479 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3480 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3481 | return kCondEQ; |
| 3482 | } |
| 3483 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3484 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3485 | 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] | 3486 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3487 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3488 | }; |
| 3489 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3490 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3491 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3492 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3493 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3494 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3495 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3496 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3497 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3498 | // In the following Evaluate methods, a HCompare instruction has |
| 3499 | // been merged into this HLessThan instruction; evaluate it as |
| 3500 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3501 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3502 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3503 | } |
| 3504 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3505 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3506 | } |
| 3507 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3508 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3509 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3510 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3511 | DECLARE_INSTRUCTION(LessThan); |
| 3512 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3513 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3514 | return kCondLT; |
| 3515 | } |
| 3516 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3517 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3518 | return kCondGE; |
| 3519 | } |
| 3520 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3521 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3522 | 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] | 3523 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3524 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3525 | }; |
| 3526 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3527 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3528 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3529 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3530 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3531 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3532 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3533 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3534 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3535 | // In the following Evaluate methods, a HCompare instruction has |
| 3536 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3537 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 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(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3540 | } |
| 3541 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3542 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3543 | } |
| 3544 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3545 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3546 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3547 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3548 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3549 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3550 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3551 | return kCondLE; |
| 3552 | } |
| 3553 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3554 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3555 | return kCondGT; |
| 3556 | } |
| 3557 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3558 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3559 | 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] | 3560 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3561 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3562 | }; |
| 3563 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3564 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3565 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3566 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3567 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3568 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3569 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3570 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3571 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3572 | // In the following Evaluate methods, a HCompare instruction has |
| 3573 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3574 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3575 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3576 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3577 | } |
| 3578 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3579 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3580 | } |
| 3581 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3582 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3583 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3584 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3585 | DECLARE_INSTRUCTION(GreaterThan); |
| 3586 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3587 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3588 | return kCondGT; |
| 3589 | } |
| 3590 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3591 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3592 | return kCondLE; |
| 3593 | } |
| 3594 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3595 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3596 | 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] | 3597 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3598 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3599 | }; |
| 3600 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3601 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3602 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3603 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3604 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3605 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3606 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3607 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3608 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3609 | // In the following Evaluate methods, a HCompare instruction has |
| 3610 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3611 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3612 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3613 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3614 | } |
| 3615 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3616 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3617 | } |
| 3618 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3619 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3620 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3621 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3622 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3623 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3624 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3625 | return kCondGE; |
| 3626 | } |
| 3627 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3628 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3629 | return kCondLT; |
| 3630 | } |
| 3631 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3632 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3633 | 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] | 3634 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3635 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3636 | }; |
| 3637 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3638 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3639 | public: |
| 3640 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3641 | : HCondition(first, second, dex_pc) {} |
| 3642 | |
| 3643 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3644 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3645 | } |
| 3646 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3647 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3648 | } |
| 3649 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3650 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3651 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3652 | UNREACHABLE(); |
| 3653 | } |
| 3654 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3655 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3656 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3657 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | DECLARE_INSTRUCTION(Below); |
| 3661 | |
| 3662 | IfCondition GetCondition() const OVERRIDE { |
| 3663 | return kCondB; |
| 3664 | } |
| 3665 | |
| 3666 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3667 | return kCondAE; |
| 3668 | } |
| 3669 | |
| 3670 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3671 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3672 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3673 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3674 | |
| 3675 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3676 | }; |
| 3677 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3678 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3679 | public: |
| 3680 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3681 | : HCondition(first, second, dex_pc) {} |
| 3682 | |
| 3683 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3684 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3685 | } |
| 3686 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3687 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3688 | } |
| 3689 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3690 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3691 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3692 | UNREACHABLE(); |
| 3693 | } |
| 3694 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3695 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3696 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3697 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3698 | } |
| 3699 | |
| 3700 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3701 | |
| 3702 | IfCondition GetCondition() const OVERRIDE { |
| 3703 | return kCondBE; |
| 3704 | } |
| 3705 | |
| 3706 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3707 | return kCondA; |
| 3708 | } |
| 3709 | |
| 3710 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3711 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3712 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3713 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3714 | |
| 3715 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3716 | }; |
| 3717 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3718 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3719 | public: |
| 3720 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3721 | : HCondition(first, second, dex_pc) {} |
| 3722 | |
| 3723 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3724 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3725 | } |
| 3726 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3727 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3728 | } |
| 3729 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3730 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3731 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3732 | UNREACHABLE(); |
| 3733 | } |
| 3734 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3735 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3736 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3737 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3738 | } |
| 3739 | |
| 3740 | DECLARE_INSTRUCTION(Above); |
| 3741 | |
| 3742 | IfCondition GetCondition() const OVERRIDE { |
| 3743 | return kCondA; |
| 3744 | } |
| 3745 | |
| 3746 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3747 | return kCondBE; |
| 3748 | } |
| 3749 | |
| 3750 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3751 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3752 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3753 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3754 | |
| 3755 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3756 | }; |
| 3757 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3758 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3759 | public: |
| 3760 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3761 | : HCondition(first, second, dex_pc) {} |
| 3762 | |
| 3763 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3764 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3765 | } |
| 3766 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3767 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3768 | } |
| 3769 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3770 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3771 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3772 | UNREACHABLE(); |
| 3773 | } |
| 3774 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3775 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3776 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3777 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3781 | |
| 3782 | IfCondition GetCondition() const OVERRIDE { |
| 3783 | return kCondAE; |
| 3784 | } |
| 3785 | |
| 3786 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3787 | return kCondB; |
| 3788 | } |
| 3789 | |
| 3790 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3791 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3792 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3793 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3794 | |
| 3795 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3796 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3797 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3798 | // Instruction to check how two inputs compare to each other. |
| 3799 | // 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] | 3800 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3801 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3802 | // Note that `comparison_type` is the type of comparison performed |
| 3803 | // between the comparison's inputs, not the type of the instantiated |
| 3804 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3805 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3806 | HInstruction* first, |
| 3807 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3808 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3809 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3810 | : HBinaryOperation(Primitive::kPrimInt, |
| 3811 | first, |
| 3812 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3813 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3814 | dex_pc) { |
| 3815 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3816 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3817 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3818 | } |
| 3819 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3820 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3821 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3822 | |
| 3823 | template <typename T> |
| 3824 | int32_t ComputeFP(T x, T y) const { |
| 3825 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3826 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3827 | // Handle the bias. |
| 3828 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3829 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3830 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3831 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3832 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3833 | // reach this code path when processing a freshly built HIR |
| 3834 | // graph. However HCompare integer instructions can be synthesized |
| 3835 | // by the instruction simplifier to implement IntegerCompare and |
| 3836 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3837 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3838 | } |
| 3839 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3840 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3841 | } |
| 3842 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3843 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3844 | } |
| 3845 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3846 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3847 | } |
| 3848 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3849 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3850 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3851 | } |
| 3852 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3853 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3854 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3855 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3856 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3857 | bool IsGtBias() const { |
| 3858 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3859 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3860 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3861 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3862 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3863 | // Comparisons do not require a runtime call in any back end. |
| 3864 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3865 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3866 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3867 | DECLARE_INSTRUCTION(Compare); |
| 3868 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3869 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3870 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3871 | static constexpr size_t kFieldComparisonBiasSize = |
| 3872 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3873 | static constexpr size_t kNumberOfComparePackedBits = |
| 3874 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3875 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3876 | using ComparisonBiasField = |
| 3877 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3878 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3879 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3880 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3881 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3882 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3883 | } |
| 3884 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3885 | private: |
| 3886 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3887 | }; |
| 3888 | |
Nicolas Geoffray | 2b615ba | 2017-01-06 14:40:07 +0000 | [diff] [blame] | 3889 | class HNewInstance FINAL : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3890 | public: |
| 3891 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3892 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3893 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3894 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3895 | bool finalizable, |
| 3896 | QuickEntrypointEnum entrypoint) |
| 3897 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3898 | type_index_(type_index), |
| 3899 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3900 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3901 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3902 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3903 | } |
| 3904 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3905 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3906 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3907 | |
| 3908 | // Calls runtime so needs an environment. |
| 3909 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3910 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3911 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3912 | bool CanThrow() const OVERRIDE { return true; } |
| 3913 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 3914 | bool NeedsChecks() const { |
| 3915 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 3916 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3917 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3918 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3919 | |
| 3920 | bool CanBeNull() const OVERRIDE { return false; } |
| 3921 | |
| 3922 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3923 | |
| 3924 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3925 | entrypoint_ = entrypoint; |
| 3926 | } |
| 3927 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 3928 | HLoadClass* GetLoadClass() const { |
| 3929 | HInstruction* input = InputAt(0); |
| 3930 | if (input->IsClinitCheck()) { |
| 3931 | input = input->InputAt(0); |
| 3932 | } |
| 3933 | DCHECK(input->IsLoadClass()); |
| 3934 | return input->AsLoadClass(); |
| 3935 | } |
| 3936 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3937 | bool IsStringAlloc() const; |
| 3938 | |
| 3939 | DECLARE_INSTRUCTION(NewInstance); |
| 3940 | |
| 3941 | private: |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 3942 | static constexpr size_t kFlagFinalizable = kNumberOfExpressionPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3943 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3944 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3945 | "Too many packed fields."); |
| 3946 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3947 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3948 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3949 | QuickEntrypointEnum entrypoint_; |
| 3950 | |
| 3951 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3952 | }; |
| 3953 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3954 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3955 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3956 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3957 | }; |
| 3958 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3959 | enum IntrinsicSideEffects { |
| 3960 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3961 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3962 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3963 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3964 | }; |
| 3965 | |
| 3966 | enum IntrinsicExceptions { |
| 3967 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3968 | kCanThrow // Intrinsic may throw exceptions. |
| 3969 | }; |
| 3970 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3971 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3972 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3973 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3974 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3975 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3976 | SetRawInputAt(index, argument); |
| 3977 | } |
| 3978 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3979 | // Return the number of arguments. This number can be lower than |
| 3980 | // the number of inputs returned by InputCount(), as some invoke |
| 3981 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3982 | // inputs at the end of their list of inputs. |
| 3983 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3984 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3985 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3986 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3987 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3988 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3989 | InvokeType GetInvokeType() const { |
| 3990 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3991 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3992 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3993 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3994 | return intrinsic_; |
| 3995 | } |
| 3996 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3997 | void SetIntrinsic(Intrinsics intrinsic, |
| 3998 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3999 | IntrinsicSideEffects side_effects, |
| 4000 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4001 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4002 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4003 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4004 | } |
| 4005 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4006 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4007 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4008 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4009 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4010 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4011 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4012 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4013 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 4014 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4015 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4016 | uint32_t* GetIntrinsicOptimizations() { |
| 4017 | return &intrinsic_optimizations_; |
| 4018 | } |
| 4019 | |
| 4020 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4021 | return &intrinsic_optimizations_; |
| 4022 | } |
| 4023 | |
| 4024 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4025 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4026 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4027 | void SetResolvedMethod(ArtMethod* method) { resolved_method_ = method; } |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4028 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4029 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4030 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4031 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4032 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4033 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4034 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4035 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4036 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4037 | static constexpr size_t kFieldReturnTypeSize = |
| 4038 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 4039 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 4040 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 4041 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4042 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4043 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 4044 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4045 | HInvoke(ArenaAllocator* arena, |
| 4046 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4047 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4048 | Primitive::Type return_type, |
| 4049 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4050 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4051 | ArtMethod* resolved_method, |
| 4052 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4053 | : HVariableInputSizeInstruction( |
| 4054 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4055 | dex_pc, |
| 4056 | arena, |
| 4057 | number_of_arguments + number_of_other_inputs, |
| 4058 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4059 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4060 | resolved_method_(resolved_method), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4061 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4062 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4063 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4064 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4065 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4066 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4067 | } |
| 4068 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4069 | uint32_t number_of_arguments_; |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4070 | ArtMethod* resolved_method_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4071 | const uint32_t dex_method_index_; |
| 4072 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4073 | |
| 4074 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4075 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4076 | |
| 4077 | private: |
| 4078 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 4079 | }; |
| 4080 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4081 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4082 | public: |
| 4083 | HInvokeUnresolved(ArenaAllocator* arena, |
| 4084 | uint32_t number_of_arguments, |
| 4085 | Primitive::Type return_type, |
| 4086 | uint32_t dex_pc, |
| 4087 | uint32_t dex_method_index, |
| 4088 | InvokeType invoke_type) |
| 4089 | : HInvoke(arena, |
| 4090 | number_of_arguments, |
| 4091 | 0u /* number_of_other_inputs */, |
| 4092 | return_type, |
| 4093 | dex_pc, |
| 4094 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4095 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4096 | invoke_type) { |
| 4097 | } |
| 4098 | |
| 4099 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4100 | |
| 4101 | private: |
| 4102 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 4103 | }; |
| 4104 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4105 | class HInvokePolymorphic FINAL : public HInvoke { |
| 4106 | public: |
| 4107 | HInvokePolymorphic(ArenaAllocator* arena, |
| 4108 | uint32_t number_of_arguments, |
| 4109 | Primitive::Type return_type, |
| 4110 | uint32_t dex_pc, |
| 4111 | uint32_t dex_method_index) |
| 4112 | : HInvoke(arena, |
| 4113 | number_of_arguments, |
| 4114 | 0u /* number_of_other_inputs */, |
| 4115 | return_type, |
| 4116 | dex_pc, |
| 4117 | dex_method_index, |
| 4118 | nullptr, |
| 4119 | kVirtual) {} |
| 4120 | |
| 4121 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4122 | |
| 4123 | private: |
| 4124 | DISALLOW_COPY_AND_ASSIGN(HInvokePolymorphic); |
| 4125 | }; |
| 4126 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4127 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4128 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4129 | // Requirements of this method call regarding the class |
| 4130 | // initialization (clinit) check of its declaring class. |
| 4131 | enum class ClinitCheckRequirement { |
| 4132 | kNone, // Class already initialized. |
| 4133 | kExplicit, // Static call having explicit clinit check as last input. |
| 4134 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4135 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4136 | }; |
| 4137 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4138 | // Determines how to load the target ArtMethod*. |
| 4139 | enum class MethodLoadKind { |
| 4140 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4141 | kStringInit, |
| 4142 | |
| 4143 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4144 | kRecursive, |
| 4145 | |
| 4146 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4147 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 4148 | kDirectAddress, |
| 4149 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4150 | // 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] | 4151 | // Used when we need to use the dex cache, for example for invoke-static that |
| 4152 | // may cause class initialization (the entry may point to a resolution method), |
| 4153 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 4154 | kDexCachePcRelative, |
| 4155 | |
| 4156 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 4157 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 4158 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 4159 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4160 | kDexCacheViaMethod, |
| 4161 | }; |
| 4162 | |
| 4163 | // Determines the location of the code pointer. |
| 4164 | enum class CodePtrLocation { |
| 4165 | // Recursive call, use local PC-relative call instruction. |
| 4166 | kCallSelf, |
| 4167 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4168 | // Use code pointer from the ArtMethod*. |
| 4169 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4170 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4171 | kCallArtMethod, |
| 4172 | }; |
| 4173 | |
| 4174 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4175 | MethodLoadKind method_load_kind; |
| 4176 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4177 | // The method load data holds |
| 4178 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4179 | // Note that there are multiple string init methods, each having its own offset. |
| 4180 | // - the method address for kDirectAddress |
| 4181 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4182 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4183 | }; |
| 4184 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4185 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 4186 | uint32_t number_of_arguments, |
| 4187 | Primitive::Type return_type, |
| 4188 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4189 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4190 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4191 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4192 | InvokeType invoke_type, |
| 4193 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4194 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4195 | : HInvoke(arena, |
| 4196 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4197 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4198 | // potentially one other if the clinit check is explicit, and potentially |
| 4199 | // one other if the method is a string factory. |
| 4200 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4201 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4202 | return_type, |
| 4203 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4204 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4205 | resolved_method, |
| 4206 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4207 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4208 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4209 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4210 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4211 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4212 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4213 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4214 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4215 | |
| 4216 | // Using the current method is the default and once we find a better |
| 4217 | // method load kind, we should not go back to using the current method. |
| 4218 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4219 | |
| 4220 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4221 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4222 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4223 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4224 | dispatch_info_ = dispatch_info; |
| 4225 | } |
| 4226 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4227 | void AddSpecialInput(HInstruction* input) { |
| 4228 | // We allow only one special input. |
| 4229 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4230 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4231 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4232 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4233 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4234 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4235 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4236 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4237 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4238 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4239 | DCHECK(!input_records.empty()); |
| 4240 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4241 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4242 | // Note: `last_input` may be null during arguments setup. |
| 4243 | if (last_input != nullptr) { |
| 4244 | // `last_input` is the last input of a static invoke marked as having |
| 4245 | // an explicit clinit check. It must either be: |
| 4246 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4247 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4248 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4249 | } |
| 4250 | } |
| 4251 | return input_records; |
| 4252 | } |
| 4253 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4254 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4255 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4256 | // TODO: for intrinsics we can generate implicit null checks. |
| 4257 | return false; |
| 4258 | } |
| 4259 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4260 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4261 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4264 | // Get the index of the special input, if any. |
| 4265 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4266 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4267 | // method pointer; otherwise there may be one platform-specific special input, |
| 4268 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4269 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4270 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4271 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4272 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4273 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4274 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4275 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4276 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4277 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4278 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4279 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 4280 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4281 | bool HasCurrentMethodInput() const { |
| 4282 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4283 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4284 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4285 | return true; |
| 4286 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4287 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4288 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4289 | return false; |
| 4290 | } |
| 4291 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4292 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4293 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4294 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4295 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | uint64_t GetMethodAddress() const { |
| 4299 | DCHECK(HasMethodAddress()); |
| 4300 | return dispatch_info_.method_load_data; |
| 4301 | } |
| 4302 | |
| 4303 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4304 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4305 | return dispatch_info_.method_load_data; |
| 4306 | } |
| 4307 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4308 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4309 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4310 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4311 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4312 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4313 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4314 | // Is this instruction a call to a static method? |
| 4315 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4316 | return GetInvokeType() == kStatic; |
| 4317 | } |
| 4318 | |
| 4319 | MethodReference GetTargetMethod() const { |
| 4320 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4321 | } |
| 4322 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4323 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4324 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4325 | // instruction; only relevant for static calls with explicit clinit check. |
| 4326 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4327 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4328 | size_t last_input_index = inputs_.size() - 1u; |
| 4329 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4330 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4331 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4332 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4333 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4334 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4335 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | // 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] | 4339 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4340 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4341 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4342 | } |
| 4343 | |
| 4344 | // Is this a call to a static method whose declaring class has an |
| 4345 | // implicit intialization check requirement? |
| 4346 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4347 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4348 | } |
| 4349 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4350 | // Does this method load kind need the current method as an input? |
| 4351 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4352 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4353 | } |
| 4354 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4355 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4356 | |
| 4357 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4358 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4359 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4360 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4361 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4362 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4363 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4364 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4365 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4366 | kFieldClinitCheckRequirement, |
| 4367 | kFieldClinitCheckRequirementSize>; |
| 4368 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4369 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4370 | MethodReference target_method_; |
| 4371 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4372 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4373 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4374 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4375 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4376 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4377 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4378 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4379 | public: |
| 4380 | HInvokeVirtual(ArenaAllocator* arena, |
| 4381 | uint32_t number_of_arguments, |
| 4382 | Primitive::Type return_type, |
| 4383 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4384 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4385 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4386 | uint32_t vtable_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4387 | : HInvoke(arena, |
| 4388 | number_of_arguments, |
| 4389 | 0u, |
| 4390 | return_type, |
| 4391 | dex_pc, |
| 4392 | dex_method_index, |
| 4393 | resolved_method, |
| 4394 | kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4395 | vtable_index_(vtable_index) {} |
| 4396 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4397 | bool CanBeNull() const OVERRIDE { |
| 4398 | switch (GetIntrinsic()) { |
| 4399 | case Intrinsics::kThreadCurrentThread: |
| 4400 | case Intrinsics::kStringBufferAppend: |
| 4401 | case Intrinsics::kStringBufferToString: |
| 4402 | case Intrinsics::kStringBuilderAppend: |
| 4403 | case Intrinsics::kStringBuilderToString: |
| 4404 | return false; |
| 4405 | default: |
| 4406 | return HInvoke::CanBeNull(); |
| 4407 | } |
| 4408 | } |
| 4409 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4410 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4411 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4412 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4413 | } |
| 4414 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4415 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4416 | |
| 4417 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4418 | |
| 4419 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4420 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4421 | const uint32_t vtable_index_; |
| 4422 | |
| 4423 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4424 | }; |
| 4425 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4426 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4427 | public: |
| 4428 | HInvokeInterface(ArenaAllocator* arena, |
| 4429 | uint32_t number_of_arguments, |
| 4430 | Primitive::Type return_type, |
| 4431 | uint32_t dex_pc, |
| 4432 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4433 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4434 | uint32_t imt_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4435 | : HInvoke(arena, |
| 4436 | number_of_arguments, |
| 4437 | 0u, |
| 4438 | return_type, |
| 4439 | dex_pc, |
| 4440 | dex_method_index, |
| 4441 | resolved_method, |
| 4442 | kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4443 | imt_index_(imt_index) {} |
| 4444 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4445 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4446 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4447 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4448 | } |
| 4449 | |
Nicolas Geoffray | fbdfa6d | 2017-02-03 10:43:13 +0000 | [diff] [blame] | 4450 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 4451 | // The assembly stub currently needs it. |
| 4452 | return true; |
| 4453 | } |
| 4454 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4455 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4456 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4457 | |
| 4458 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4459 | |
| 4460 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4461 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4462 | const uint32_t imt_index_; |
| 4463 | |
| 4464 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4465 | }; |
| 4466 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4467 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4468 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4469 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4470 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4471 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4472 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4473 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4474 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4475 | |
| 4476 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4477 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4478 | } |
| 4479 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4480 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4481 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4482 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4483 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4484 | } |
| 4485 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4486 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4487 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4488 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4489 | DECLARE_INSTRUCTION(Neg); |
| 4490 | |
| 4491 | private: |
| 4492 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4493 | }; |
| 4494 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4495 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4496 | public: |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4497 | HNewArray(HInstruction* cls, HInstruction* length, uint32_t dex_pc) |
| 4498 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc) { |
| 4499 | SetRawInputAt(0, cls); |
| 4500 | SetRawInputAt(1, length); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4501 | } |
| 4502 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4503 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4504 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4505 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4506 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4507 | bool CanThrow() const OVERRIDE { return true; } |
| 4508 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4509 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4510 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4511 | HLoadClass* GetLoadClass() const { |
| 4512 | DCHECK(InputAt(0)->IsLoadClass()); |
| 4513 | return InputAt(0)->AsLoadClass(); |
| 4514 | } |
| 4515 | |
| 4516 | HInstruction* GetLength() const { |
| 4517 | return InputAt(1); |
| 4518 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4519 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4520 | DECLARE_INSTRUCTION(NewArray); |
| 4521 | |
| 4522 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4523 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4524 | }; |
| 4525 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4526 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4527 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4528 | HAdd(Primitive::Type result_type, |
| 4529 | HInstruction* left, |
| 4530 | HInstruction* right, |
| 4531 | uint32_t dex_pc = kNoDexPc) |
| 4532 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4533 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4534 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4535 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4536 | 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] | 4537 | |
| 4538 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4539 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4540 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4541 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4542 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4543 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4544 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4545 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4546 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4547 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4548 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4549 | } |
| 4550 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4551 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4552 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4553 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4554 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4555 | DECLARE_INSTRUCTION(Add); |
| 4556 | |
| 4557 | private: |
| 4558 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4559 | }; |
| 4560 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4561 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4562 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4563 | HSub(Primitive::Type result_type, |
| 4564 | HInstruction* left, |
| 4565 | HInstruction* right, |
| 4566 | uint32_t dex_pc = kNoDexPc) |
| 4567 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4568 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4569 | 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] | 4570 | |
| 4571 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4572 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4573 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4574 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4575 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4576 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4577 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4578 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4579 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4580 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4581 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4582 | } |
| 4583 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4584 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4585 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4586 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4587 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4588 | DECLARE_INSTRUCTION(Sub); |
| 4589 | |
| 4590 | private: |
| 4591 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4592 | }; |
| 4593 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4594 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4595 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4596 | HMul(Primitive::Type result_type, |
| 4597 | HInstruction* left, |
| 4598 | HInstruction* right, |
| 4599 | uint32_t dex_pc = kNoDexPc) |
| 4600 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4601 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4602 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4603 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4604 | 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] | 4605 | |
| 4606 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4607 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4608 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4609 | } |
| 4610 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4611 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4612 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4613 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4614 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4615 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4616 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4617 | } |
| 4618 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4619 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4620 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4621 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4622 | |
| 4623 | DECLARE_INSTRUCTION(Mul); |
| 4624 | |
| 4625 | private: |
| 4626 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4627 | }; |
| 4628 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4629 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4630 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4631 | HDiv(Primitive::Type result_type, |
| 4632 | HInstruction* left, |
| 4633 | HInstruction* right, |
| 4634 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4635 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4636 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4637 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4638 | T ComputeIntegral(T x, T y) const { |
| 4639 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4640 | // Our graph structure ensures we never have 0 for `y` during |
| 4641 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4642 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4643 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4644 | return (y == -1) ? -x : x / y; |
| 4645 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4646 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4647 | template <typename T> |
| 4648 | T ComputeFP(T x, T y) const { |
| 4649 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4650 | return x / y; |
| 4651 | } |
| 4652 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4653 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4654 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4655 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4656 | } |
| 4657 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4658 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4659 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4660 | } |
| 4661 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4662 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4663 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4664 | } |
| 4665 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4666 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4667 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4668 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4669 | |
| 4670 | DECLARE_INSTRUCTION(Div); |
| 4671 | |
| 4672 | private: |
| 4673 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4674 | }; |
| 4675 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4676 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4677 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4678 | HRem(Primitive::Type result_type, |
| 4679 | HInstruction* left, |
| 4680 | HInstruction* right, |
| 4681 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4682 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4683 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4684 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4685 | T ComputeIntegral(T x, T y) const { |
| 4686 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4687 | // Our graph structure ensures we never have 0 for `y` during |
| 4688 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4689 | DCHECK_NE(y, 0); |
| 4690 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4691 | return (y == -1) ? 0 : x % y; |
| 4692 | } |
| 4693 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4694 | template <typename T> |
| 4695 | T ComputeFP(T x, T y) const { |
| 4696 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4697 | return std::fmod(x, y); |
| 4698 | } |
| 4699 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4700 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4701 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4702 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4703 | } |
| 4704 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4705 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4706 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4707 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4708 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4709 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4710 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4711 | } |
| 4712 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4713 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4714 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4715 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4716 | |
| 4717 | DECLARE_INSTRUCTION(Rem); |
| 4718 | |
| 4719 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4720 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4721 | }; |
| 4722 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4723 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4724 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4725 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4726 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4727 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4728 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4729 | SetRawInputAt(0, value); |
| 4730 | } |
| 4731 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4732 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4733 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4734 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4735 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4736 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4737 | return true; |
| 4738 | } |
| 4739 | |
| 4740 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4741 | bool CanThrow() const OVERRIDE { return true; } |
| 4742 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4743 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4744 | |
| 4745 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4746 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4747 | }; |
| 4748 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4749 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4750 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4751 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4752 | HInstruction* value, |
| 4753 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4754 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4755 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4756 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4757 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4758 | } |
| 4759 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4760 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4761 | 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] | 4762 | return value << (distance & max_shift_distance); |
| 4763 | } |
| 4764 | |
| 4765 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4766 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4767 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4768 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4769 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4770 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4771 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4772 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4773 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4774 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4775 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4776 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4777 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4778 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4779 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4780 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4781 | UNREACHABLE(); |
| 4782 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4783 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4784 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4785 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4786 | UNREACHABLE(); |
| 4787 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4788 | |
| 4789 | DECLARE_INSTRUCTION(Shl); |
| 4790 | |
| 4791 | private: |
| 4792 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4793 | }; |
| 4794 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4795 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4796 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4797 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4798 | HInstruction* value, |
| 4799 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4800 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4801 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4802 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4803 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4804 | } |
| 4805 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4806 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4807 | 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] | 4808 | return value >> (distance & max_shift_distance); |
| 4809 | } |
| 4810 | |
| 4811 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4812 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4813 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4814 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4815 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4816 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4817 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4818 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4819 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4820 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4821 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4822 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4823 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4824 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4825 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4826 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4827 | UNREACHABLE(); |
| 4828 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4829 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4830 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4831 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4832 | UNREACHABLE(); |
| 4833 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4834 | |
| 4835 | DECLARE_INSTRUCTION(Shr); |
| 4836 | |
| 4837 | private: |
| 4838 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4839 | }; |
| 4840 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4841 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4842 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4843 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4844 | HInstruction* value, |
| 4845 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4846 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4847 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4848 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4849 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4850 | } |
| 4851 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4852 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4853 | 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] | 4854 | typedef typename std::make_unsigned<T>::type V; |
| 4855 | V ux = static_cast<V>(value); |
| 4856 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4857 | } |
| 4858 | |
| 4859 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4860 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4861 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4862 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4863 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4864 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4865 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4866 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4867 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4868 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4869 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4870 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4871 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4872 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4873 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4874 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4875 | UNREACHABLE(); |
| 4876 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4877 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4878 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4879 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4880 | UNREACHABLE(); |
| 4881 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4882 | |
| 4883 | DECLARE_INSTRUCTION(UShr); |
| 4884 | |
| 4885 | private: |
| 4886 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4887 | }; |
| 4888 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4889 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4890 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4891 | HAnd(Primitive::Type result_type, |
| 4892 | HInstruction* left, |
| 4893 | HInstruction* right, |
| 4894 | uint32_t dex_pc = kNoDexPc) |
| 4895 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4896 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4897 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4898 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4899 | 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] | 4900 | |
| 4901 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4902 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4903 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4904 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4905 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4906 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4907 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4908 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4909 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4910 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4911 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4912 | UNREACHABLE(); |
| 4913 | } |
| 4914 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4915 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4916 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4917 | UNREACHABLE(); |
| 4918 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4919 | |
| 4920 | DECLARE_INSTRUCTION(And); |
| 4921 | |
| 4922 | private: |
| 4923 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4924 | }; |
| 4925 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4926 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4927 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4928 | HOr(Primitive::Type result_type, |
| 4929 | HInstruction* left, |
| 4930 | HInstruction* right, |
| 4931 | uint32_t dex_pc = kNoDexPc) |
| 4932 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4933 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4934 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4935 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4936 | 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] | 4937 | |
| 4938 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4939 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4940 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4941 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4942 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4943 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4944 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4945 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4946 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4947 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4948 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4949 | UNREACHABLE(); |
| 4950 | } |
| 4951 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4952 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4953 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4954 | UNREACHABLE(); |
| 4955 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4956 | |
| 4957 | DECLARE_INSTRUCTION(Or); |
| 4958 | |
| 4959 | private: |
| 4960 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4961 | }; |
| 4962 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4963 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4964 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4965 | HXor(Primitive::Type result_type, |
| 4966 | HInstruction* left, |
| 4967 | HInstruction* right, |
| 4968 | uint32_t dex_pc = kNoDexPc) |
| 4969 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4970 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4971 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4972 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4973 | 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] | 4974 | |
| 4975 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4976 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4977 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4978 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4979 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4980 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4981 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4982 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4983 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4984 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4985 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4986 | UNREACHABLE(); |
| 4987 | } |
| 4988 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4989 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4990 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4991 | UNREACHABLE(); |
| 4992 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4993 | |
| 4994 | DECLARE_INSTRUCTION(Xor); |
| 4995 | |
| 4996 | private: |
| 4997 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4998 | }; |
| 4999 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5000 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5001 | public: |
| 5002 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5003 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5004 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 5005 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5006 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5007 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5008 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5009 | 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] | 5010 | typedef typename std::make_unsigned<T>::type V; |
| 5011 | V ux = static_cast<V>(value); |
| 5012 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5013 | return static_cast<T>(ux); |
| 5014 | } else { |
| 5015 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5016 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 5017 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5018 | } |
| 5019 | } |
| 5020 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5021 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5022 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5023 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5024 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5025 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5026 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5027 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5028 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5029 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5030 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5031 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5032 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5033 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5034 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5035 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5036 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5037 | UNREACHABLE(); |
| 5038 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5039 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5040 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5041 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5042 | UNREACHABLE(); |
| 5043 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5044 | |
| 5045 | DECLARE_INSTRUCTION(Ror); |
| 5046 | |
| 5047 | private: |
| 5048 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 5049 | }; |
| 5050 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5051 | // The value of a parameter in this method. Its location depends on |
| 5052 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5053 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5054 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5055 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5056 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5057 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5058 | Primitive::Type parameter_type, |
| 5059 | bool is_this = false) |
| 5060 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5061 | dex_file_(dex_file), |
| 5062 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5063 | index_(index) { |
| 5064 | SetPackedFlag<kFlagIsThis>(is_this); |
| 5065 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 5066 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5067 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5068 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5069 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5070 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5071 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5072 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5073 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 5074 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5075 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5076 | DECLARE_INSTRUCTION(ParameterValue); |
| 5077 | |
| 5078 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5079 | // Whether or not the parameter value corresponds to 'this' argument. |
| 5080 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 5081 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 5082 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 5083 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 5084 | "Too many packed fields."); |
| 5085 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5086 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5087 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5088 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5089 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5090 | const uint8_t index_; |
| 5091 | |
| 5092 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 5093 | }; |
| 5094 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5095 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5096 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5097 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5098 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5099 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5100 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5101 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5102 | return true; |
| 5103 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5104 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5105 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5106 | |
| 5107 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5108 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5109 | } |
| 5110 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5111 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5112 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5113 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5114 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5115 | UNREACHABLE(); |
| 5116 | } |
| 5117 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5118 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5119 | UNREACHABLE(); |
| 5120 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5121 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5122 | DECLARE_INSTRUCTION(Not); |
| 5123 | |
| 5124 | private: |
| 5125 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 5126 | }; |
| 5127 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5128 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5129 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5130 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5131 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5132 | |
| 5133 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5134 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5135 | return true; |
| 5136 | } |
| 5137 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5138 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5139 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5140 | return !x; |
| 5141 | } |
| 5142 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5143 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5144 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5145 | } |
| 5146 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5147 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5148 | UNREACHABLE(); |
| 5149 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5150 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5151 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5152 | UNREACHABLE(); |
| 5153 | } |
| 5154 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5155 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5156 | UNREACHABLE(); |
| 5157 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5158 | |
| 5159 | DECLARE_INSTRUCTION(BooleanNot); |
| 5160 | |
| 5161 | private: |
| 5162 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 5163 | }; |
| 5164 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5165 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5166 | public: |
| 5167 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 5168 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5169 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5170 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5171 | // Invariant: We should never generate a conversion to a Boolean value. |
| 5172 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | HInstruction* GetInput() const { return InputAt(0); } |
| 5176 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 5177 | Primitive::Type GetResultType() const { return GetType(); } |
| 5178 | |
| 5179 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5180 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5181 | return true; |
| 5182 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5183 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5184 | // Try to statically evaluate the conversion and return a HConstant |
| 5185 | // containing the result. If the input cannot be converted, return nullptr. |
| 5186 | HConstant* TryStaticEvaluation() const; |
| 5187 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5188 | DECLARE_INSTRUCTION(TypeConversion); |
| 5189 | |
| 5190 | private: |
| 5191 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 5192 | }; |
| 5193 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5194 | static constexpr uint32_t kNoRegNumber = -1; |
| 5195 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5196 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5197 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5198 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 5199 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5200 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5201 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5202 | SetRawInputAt(0, value); |
| 5203 | } |
| 5204 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5205 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5206 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5207 | return true; |
| 5208 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5209 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5210 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5211 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5212 | bool CanThrow() const OVERRIDE { return true; } |
| 5213 | |
| 5214 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5215 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5216 | |
| 5217 | DECLARE_INSTRUCTION(NullCheck); |
| 5218 | |
| 5219 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5220 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 5221 | }; |
| 5222 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5223 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5224 | // 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] | 5225 | class FieldInfo : public ValueObject { |
| 5226 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5227 | FieldInfo(ArtField* field, |
| 5228 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5229 | Primitive::Type field_type, |
| 5230 | bool is_volatile, |
| 5231 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5232 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5233 | const DexFile& dex_file) |
| 5234 | : field_(field), |
| 5235 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5236 | field_type_(field_type), |
| 5237 | is_volatile_(is_volatile), |
| 5238 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5239 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5240 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5241 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5242 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5243 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5244 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5245 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5246 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5247 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5248 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5249 | |
| 5250 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5251 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5252 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5253 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5254 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5255 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5256 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5257 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5258 | }; |
| 5259 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5260 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5261 | public: |
| 5262 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5263 | ArtField* field, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5264 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5265 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5266 | bool is_volatile, |
| 5267 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5268 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5269 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5270 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5271 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5272 | field_info_(field, |
| 5273 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5274 | field_type, |
| 5275 | is_volatile, |
| 5276 | field_idx, |
| 5277 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5278 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5279 | SetRawInputAt(0, value); |
| 5280 | } |
| 5281 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5282 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5283 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5284 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5285 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5286 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5287 | } |
| 5288 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5289 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5290 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5291 | } |
| 5292 | |
| 5293 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5294 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5295 | } |
| 5296 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5297 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5298 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5299 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5300 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5301 | |
| 5302 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5303 | |
| 5304 | private: |
| 5305 | const FieldInfo field_info_; |
| 5306 | |
| 5307 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5308 | }; |
| 5309 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5310 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5311 | public: |
| 5312 | HInstanceFieldSet(HInstruction* object, |
| 5313 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5314 | ArtField* field, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5315 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5316 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5317 | bool is_volatile, |
| 5318 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5319 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5320 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5321 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5322 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5323 | field_info_(field, |
| 5324 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5325 | field_type, |
| 5326 | is_volatile, |
| 5327 | field_idx, |
| 5328 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5329 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5330 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5331 | SetRawInputAt(0, object); |
| 5332 | SetRawInputAt(1, value); |
| 5333 | } |
| 5334 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5335 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5336 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5337 | } |
| 5338 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5339 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5340 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5341 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5342 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5343 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5344 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5345 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5346 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5347 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5348 | |
| 5349 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5350 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5351 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5352 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5353 | "Too many packed fields."); |
| 5354 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5355 | const FieldInfo field_info_; |
| 5356 | |
| 5357 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5358 | }; |
| 5359 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5360 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5361 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5362 | HArrayGet(HInstruction* array, |
| 5363 | HInstruction* index, |
| 5364 | Primitive::Type type, |
| 5365 | uint32_t dex_pc, |
| 5366 | bool is_string_char_at = false) |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5367 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5368 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5369 | SetRawInputAt(0, array); |
| 5370 | SetRawInputAt(1, index); |
| 5371 | } |
| 5372 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5373 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5374 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5375 | return true; |
| 5376 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5377 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5378 | // TODO: We can be smarter here. |
| 5379 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5380 | // which generates the implicit null check. There are cases when these can be removed |
| 5381 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5382 | // implicit check here (as long as the address falls in the first page). |
| 5383 | return false; |
| 5384 | } |
| 5385 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5386 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5387 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5388 | if (kIsDebugBuild && result) { |
| 5389 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5390 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5391 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5392 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5393 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5394 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5395 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5396 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5397 | } |
| 5398 | } |
| 5399 | return result; |
| 5400 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5401 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5402 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5403 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5404 | HInstruction* GetArray() const { return InputAt(0); } |
| 5405 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5406 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5407 | DECLARE_INSTRUCTION(ArrayGet); |
| 5408 | |
| 5409 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5410 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5411 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5412 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5413 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5414 | // a flag, so that code generators don't need to do the locking. |
| 5415 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5416 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5417 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5418 | "Too many packed fields."); |
| 5419 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5420 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5421 | }; |
| 5422 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5423 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5424 | public: |
| 5425 | HArraySet(HInstruction* array, |
| 5426 | HInstruction* index, |
| 5427 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5428 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5429 | uint32_t dex_pc) |
| 5430 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5431 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5432 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5433 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5434 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5435 | SetRawInputAt(0, array); |
| 5436 | SetRawInputAt(1, index); |
| 5437 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5438 | // Make a best guess now, may be refined during SSA building. |
| 5439 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5440 | } |
| 5441 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5442 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5443 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5444 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5445 | } |
| 5446 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5447 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5448 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5449 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5450 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5451 | // TODO: Same as for ArrayGet. |
| 5452 | return false; |
| 5453 | } |
| 5454 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5455 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5456 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5457 | } |
| 5458 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5459 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5460 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5461 | } |
| 5462 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5463 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5464 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5465 | } |
| 5466 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5467 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5468 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5469 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5470 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5471 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5472 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5473 | HInstruction* GetArray() const { return InputAt(0); } |
| 5474 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5475 | HInstruction* GetValue() const { return InputAt(2); } |
| 5476 | |
| 5477 | Primitive::Type GetComponentType() const { |
| 5478 | // The Dex format does not type floating point index operations. Since the |
| 5479 | // `expected_component_type_` is set during building and can therefore not |
| 5480 | // be correct, we also check what is the value type. If it is a floating |
| 5481 | // point type, we must use that type. |
| 5482 | Primitive::Type value_type = GetValue()->GetType(); |
| 5483 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5484 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5485 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5486 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5487 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5488 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5489 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5490 | } |
| 5491 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5492 | void ComputeSideEffects() { |
| 5493 | Primitive::Type type = GetComponentType(); |
| 5494 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5495 | SideEffectsForArchRuntimeCalls(type))); |
| 5496 | } |
| 5497 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5498 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5499 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5500 | } |
| 5501 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5502 | DECLARE_INSTRUCTION(ArraySet); |
| 5503 | |
| 5504 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5505 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5506 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5507 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5508 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5509 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5510 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5511 | // Cached information for the reference_type_info_ so that codegen |
| 5512 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5513 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5514 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5515 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5516 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5517 | using ExpectedComponentTypeField = |
| 5518 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5519 | |
| 5520 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5521 | }; |
| 5522 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5523 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5524 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5525 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5526 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5527 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5528 | // Note that arrays do not change length, so the instruction does not |
| 5529 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5530 | SetRawInputAt(0, array); |
| 5531 | } |
| 5532 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5533 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5534 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5535 | return true; |
| 5536 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5537 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5538 | return obj == InputAt(0); |
| 5539 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5540 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5541 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5542 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5543 | DECLARE_INSTRUCTION(ArrayLength); |
| 5544 | |
| 5545 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5546 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5547 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5548 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5549 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5550 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5551 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5552 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5553 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5554 | "Too many packed fields."); |
| 5555 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5556 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5557 | }; |
| 5558 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5559 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5560 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5561 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5562 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5563 | HBoundsCheck(HInstruction* index, |
| 5564 | HInstruction* length, |
| 5565 | uint32_t dex_pc, |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5566 | bool string_char_at = false) |
| 5567 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5568 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5569 | SetPackedFlag<kFlagIsStringCharAt>(string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5570 | SetRawInputAt(0, index); |
| 5571 | SetRawInputAt(1, length); |
| 5572 | } |
| 5573 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5574 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5575 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5576 | return true; |
| 5577 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5578 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5579 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5580 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5581 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5582 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5583 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5584 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5585 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5586 | |
| 5587 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5588 | |
| 5589 | private: |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5590 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5591 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5592 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5593 | }; |
| 5594 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5595 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5596 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5597 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5598 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5599 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5600 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5601 | return true; |
| 5602 | } |
| 5603 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5604 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5605 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5606 | |
| 5607 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5608 | |
| 5609 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5610 | // Only used for code generation, in order to share the same slow path between back edges |
| 5611 | // of a same loop. |
| 5612 | SlowPathCode* slow_path_; |
| 5613 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5614 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5615 | }; |
| 5616 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5617 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5618 | // It ensures that we can generate line number and local variables at this point. |
| 5619 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5620 | public: |
| 5621 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5622 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5623 | |
| 5624 | bool NeedsEnvironment() const OVERRIDE { |
| 5625 | return true; |
| 5626 | } |
| 5627 | |
| 5628 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5629 | |
| 5630 | private: |
| 5631 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5632 | }; |
| 5633 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5634 | /** |
| 5635 | * Instruction to load a Class object. |
| 5636 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5637 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5638 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5639 | // Determines how to load the Class. |
| 5640 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5641 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 5642 | kInvalid = -1, |
| 5643 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5644 | // Use the Class* from the method's own ArtMethod*. |
| 5645 | kReferrersClass, |
| 5646 | |
| 5647 | // Use boot image Class* address that will be known at link time. |
| 5648 | // Used for boot image classes referenced by boot image code in non-PIC mode. |
| 5649 | kBootImageLinkTimeAddress, |
| 5650 | |
| 5651 | // Use PC-relative boot image Class* address that will be known at link time. |
| 5652 | // Used for boot image classes referenced by boot image code in PIC mode. |
| 5653 | kBootImageLinkTimePcRelative, |
| 5654 | |
| 5655 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5656 | // Used for boot image classes referenced by apps in AOT- and JIT-compiled code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5657 | kBootImageAddress, |
| 5658 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5659 | // Load from an entry in the .bss section using a PC-relative load. |
| 5660 | // Used for classes outside boot image when .bss is accessible with a PC-relative load. |
| 5661 | kBssEntry, |
| 5662 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5663 | // Load from the root table associated with the JIT compiled method. |
| 5664 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5665 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5666 | // Load from resolved types array accessed through the class loaded from |
| 5667 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5668 | // all other types are unavailable. |
| 5669 | kDexCacheViaMethod, |
| 5670 | |
| 5671 | kLast = kDexCacheViaMethod |
| 5672 | }; |
| 5673 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5674 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5675 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5676 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5677 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5678 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5679 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5680 | bool needs_access_check) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5681 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5682 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5683 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5684 | dex_file_(dex_file), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5685 | klass_(klass), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5686 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5687 | // Referrers class should not need access check. We never inline unverified |
| 5688 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5689 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5690 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5691 | SetPackedField<LoadKindField>( |
| 5692 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kDexCacheViaMethod); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5693 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5694 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5695 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5696 | } |
| 5697 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5698 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5699 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5700 | LoadKind GetLoadKind() const { |
| 5701 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5702 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5703 | |
| 5704 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5705 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5706 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5707 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5708 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5709 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5710 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5711 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5712 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5713 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5714 | } |
| 5715 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5716 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5717 | // The entrypoint the code generator is going to call does not do |
| 5718 | // clinit of the class. |
| 5719 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5720 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5724 | return NeedsAccessCheck() || |
| 5725 | MustGenerateClinitCheck() || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5726 | GetLoadKind() == LoadKind::kDexCacheViaMethod || |
| 5727 | GetLoadKind() == LoadKind::kBssEntry; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5728 | } |
| 5729 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5730 | bool CanThrow() const OVERRIDE { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5731 | return NeedsAccessCheck() || |
| 5732 | MustGenerateClinitCheck() || |
| 5733 | // If the class is in the boot image, the lookup in the runtime call cannot throw. |
| 5734 | // This keeps CanThrow() consistent between non-PIC (using kBootImageAddress) and |
| 5735 | // PIC and subsequently avoids a DCE behavior dependency on the PIC option. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5736 | ((GetLoadKind() == LoadKind::kDexCacheViaMethod || |
| 5737 | GetLoadKind() == LoadKind::kBssEntry) && |
| 5738 | !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5739 | } |
| 5740 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5741 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5742 | return loaded_class_rti_; |
| 5743 | } |
| 5744 | |
| 5745 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5746 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5747 | DCHECK(rti.IsExact()); |
| 5748 | loaded_class_rti_ = rti; |
| 5749 | } |
| 5750 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5751 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5752 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5753 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5754 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5755 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5756 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5757 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5758 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5759 | return SideEffects::CanTriggerGC(); |
| 5760 | } |
| 5761 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5762 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5763 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5764 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5765 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5766 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5767 | void MarkInBootImage() { |
| 5768 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 5769 | } |
| 5770 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5771 | void AddSpecialInput(HInstruction* special_input); |
| 5772 | |
| 5773 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5774 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5775 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5776 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 5777 | } |
| 5778 | |
| 5779 | Primitive::Type GetType() const OVERRIDE { |
| 5780 | return Primitive::kPrimNot; |
| 5781 | } |
| 5782 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5783 | Handle<mirror::Class> GetClass() const { |
| 5784 | return klass_; |
| 5785 | } |
| 5786 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5787 | DECLARE_INSTRUCTION(LoadClass); |
| 5788 | |
| 5789 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5790 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5791 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5792 | // Whether this instruction must generate the initialization check. |
| 5793 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5794 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5795 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 5796 | static constexpr size_t kFieldLoadKindSize = |
| 5797 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5798 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5799 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5800 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 5801 | |
| 5802 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5803 | return load_kind == LoadKind::kReferrersClass || |
| 5804 | load_kind == LoadKind::kBootImageLinkTimeAddress || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5805 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5806 | load_kind == LoadKind::kBssEntry || |
| 5807 | load_kind == LoadKind::kDexCacheViaMethod; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5808 | } |
| 5809 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5810 | void SetLoadKindInternal(LoadKind load_kind); |
| 5811 | |
| 5812 | // The special input is the HCurrentMethod for kDexCacheViaMethod or kReferrersClass. |
| 5813 | // For other load kinds it's empty or possibly some architecture-specific instruction |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5814 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5815 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5816 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5817 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 5818 | // - The compiling method's dex file if the class is defined there too. |
| 5819 | // - The compiling method's dex file if the class is referenced there. |
| 5820 | // - The dex file where the class is defined. When the load kind can only be |
| 5821 | // kBssEntry or kDexCacheViaMethod, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5822 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5823 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5824 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5825 | Handle<mirror::Class> klass_; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5826 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5827 | ReferenceTypeInfo loaded_class_rti_; |
| 5828 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5829 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5830 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5831 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 5832 | |
| 5833 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5834 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5835 | // The special input is used for PC-relative loads on some architectures, |
| 5836 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5837 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5838 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5839 | GetLoadKind() == LoadKind::kBootImageAddress || |
| 5840 | GetLoadKind() == LoadKind::kBssEntry) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5841 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5842 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 5843 | special_input->AddUseAt(this, 0); |
| 5844 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5845 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5846 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5847 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5848 | // Determines how to load the String. |
| 5849 | enum class LoadKind { |
| 5850 | // Use boot image String* address that will be known at link time. |
| 5851 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5852 | kBootImageLinkTimeAddress, |
| 5853 | |
| 5854 | // Use PC-relative boot image String* address that will be known at link time. |
| 5855 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5856 | kBootImageLinkTimePcRelative, |
| 5857 | |
| 5858 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5859 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5860 | kBootImageAddress, |
| 5861 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5862 | // Load from an entry in the .bss section using a PC-relative load. |
| 5863 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 5864 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5865 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5866 | // Load from the root table associated with the JIT compiled method. |
| 5867 | kJitTableAddress, |
| 5868 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5869 | // Load from resolved strings array accessed through the class loaded from |
| 5870 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5871 | // all other types are unavailable. |
| 5872 | kDexCacheViaMethod, |
| 5873 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5874 | kLast = kDexCacheViaMethod, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5875 | }; |
| 5876 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5877 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5878 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5879 | const DexFile& dex_file, |
| 5880 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5881 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5882 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5883 | string_index_(string_index), |
| 5884 | dex_file_(dex_file) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5885 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5886 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5887 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5888 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5889 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5890 | LoadKind GetLoadKind() const { |
| 5891 | return GetPackedField<LoadKindField>(); |
| 5892 | } |
| 5893 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5894 | const DexFile& GetDexFile() const { |
| 5895 | return dex_file_; |
| 5896 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5897 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5898 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5899 | return string_index_; |
| 5900 | } |
| 5901 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5902 | Handle<mirror::String> GetString() const { |
| 5903 | return string_; |
| 5904 | } |
| 5905 | |
| 5906 | void SetString(Handle<mirror::String> str) { |
| 5907 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5908 | } |
| 5909 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5910 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5911 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5912 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5913 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5914 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5915 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5916 | // Will call the runtime if we need to load the string through |
| 5917 | // the dex cache and the string is not guaranteed to be there yet. |
| 5918 | bool NeedsEnvironment() const OVERRIDE { |
| 5919 | LoadKind load_kind = GetLoadKind(); |
| 5920 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5921 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5922 | load_kind == LoadKind::kBootImageAddress || |
| 5923 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5924 | return false; |
| 5925 | } |
Vladimir Marko | 4d1be49 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 5926 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5927 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5928 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5929 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5930 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5931 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5932 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5933 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5934 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5935 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5936 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5937 | return SideEffects::CanTriggerGC(); |
| 5938 | } |
| 5939 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5940 | void AddSpecialInput(HInstruction* special_input); |
| 5941 | |
| 5942 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5943 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5944 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5945 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5946 | } |
| 5947 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5948 | Primitive::Type GetType() const OVERRIDE { |
| 5949 | return Primitive::kPrimNot; |
| 5950 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5951 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5952 | DECLARE_INSTRUCTION(LoadString); |
| 5953 | |
| 5954 | private: |
Vladimir Marko | 4d1be49 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 5955 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5956 | static constexpr size_t kFieldLoadKindSize = |
| 5957 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5958 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5959 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5960 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5961 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5962 | void SetLoadKindInternal(LoadKind load_kind); |
| 5963 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5964 | // The special input is the HCurrentMethod for kDexCacheViaMethod. |
| 5965 | // For other load kinds it's empty or possibly some architecture-specific instruction |
Vladimir Marko | 48886c2 | 2017-01-06 11:45:47 +0000 | [diff] [blame] | 5966 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5967 | HUserRecord<HInstruction*> special_input_; |
| 5968 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5969 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5970 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5971 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5972 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5973 | |
| 5974 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5975 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5976 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5977 | |
| 5978 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5979 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5980 | // The special input is used for PC-relative loads on some architectures, |
| 5981 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5982 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5983 | GetLoadKind() == LoadKind::kBssEntry || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5984 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5985 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5986 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5987 | // so use the GetInputRecords() from the base class to set the input record. |
| 5988 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5989 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5990 | special_input->AddUseAt(this, 0); |
| 5991 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5992 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5993 | /** |
| 5994 | * Performs an initialization check on its Class object input. |
| 5995 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5996 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5997 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5998 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5999 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6000 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6001 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 6002 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6003 | SetRawInputAt(0, constant); |
| 6004 | } |
| 6005 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6006 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6007 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6008 | return true; |
| 6009 | } |
| 6010 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6011 | bool NeedsEnvironment() const OVERRIDE { |
| 6012 | // May call runtime to initialize the class. |
| 6013 | return true; |
| 6014 | } |
| 6015 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 6016 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6017 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6018 | HLoadClass* GetLoadClass() const { |
| 6019 | DCHECK(InputAt(0)->IsLoadClass()); |
| 6020 | return InputAt(0)->AsLoadClass(); |
| 6021 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6022 | |
| 6023 | DECLARE_INSTRUCTION(ClinitCheck); |
| 6024 | |
| 6025 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6026 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 6027 | }; |
| 6028 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6029 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6030 | public: |
| 6031 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6032 | ArtField* field, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6033 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6034 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6035 | bool is_volatile, |
| 6036 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6037 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6038 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6039 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 6040 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6041 | field_info_(field, |
| 6042 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6043 | field_type, |
| 6044 | is_volatile, |
| 6045 | field_idx, |
| 6046 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6047 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6048 | SetRawInputAt(0, cls); |
| 6049 | } |
| 6050 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6051 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 6052 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6053 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6054 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 6055 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6056 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6057 | } |
| 6058 | |
| 6059 | size_t ComputeHashCode() const OVERRIDE { |
| 6060 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6061 | } |
| 6062 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6063 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6064 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 6065 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6066 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6067 | |
| 6068 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 6069 | |
| 6070 | private: |
| 6071 | const FieldInfo field_info_; |
| 6072 | |
| 6073 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 6074 | }; |
| 6075 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6076 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6077 | public: |
| 6078 | HStaticFieldSet(HInstruction* cls, |
| 6079 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6080 | ArtField* field, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6081 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6082 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6083 | bool is_volatile, |
| 6084 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6085 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6086 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6087 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 6088 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6089 | field_info_(field, |
| 6090 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6091 | field_type, |
| 6092 | is_volatile, |
| 6093 | field_idx, |
| 6094 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6095 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6096 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6097 | SetRawInputAt(0, cls); |
| 6098 | SetRawInputAt(1, value); |
| 6099 | } |
| 6100 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6101 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6102 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 6103 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6104 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6105 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6106 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6107 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6108 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6109 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6110 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6111 | |
| 6112 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6113 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6114 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6115 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6116 | "Too many packed fields."); |
| 6117 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6118 | const FieldInfo field_info_; |
| 6119 | |
| 6120 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 6121 | }; |
| 6122 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6123 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6124 | public: |
| 6125 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 6126 | Primitive::Type field_type, |
| 6127 | uint32_t field_index, |
| 6128 | uint32_t dex_pc) |
| 6129 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6130 | field_index_(field_index) { |
| 6131 | SetRawInputAt(0, obj); |
| 6132 | } |
| 6133 | |
| 6134 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6135 | bool CanThrow() const OVERRIDE { return true; } |
| 6136 | |
| 6137 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6138 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6139 | |
| 6140 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6141 | |
| 6142 | private: |
| 6143 | const uint32_t field_index_; |
| 6144 | |
| 6145 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 6146 | }; |
| 6147 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6148 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6149 | public: |
| 6150 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6151 | HInstruction* value, |
| 6152 | Primitive::Type field_type, |
| 6153 | uint32_t field_index, |
| 6154 | uint32_t dex_pc) |
| 6155 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6156 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6157 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6158 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6159 | SetRawInputAt(0, obj); |
| 6160 | SetRawInputAt(1, value); |
| 6161 | } |
| 6162 | |
| 6163 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6164 | bool CanThrow() const OVERRIDE { return true; } |
| 6165 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6166 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6167 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6168 | |
| 6169 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6170 | |
| 6171 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6172 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6173 | static constexpr size_t kFieldFieldTypeSize = |
| 6174 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6175 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6176 | kFieldFieldType + kFieldFieldTypeSize; |
| 6177 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6178 | "Too many packed fields."); |
| 6179 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6180 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6181 | const uint32_t field_index_; |
| 6182 | |
| 6183 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 6184 | }; |
| 6185 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6186 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6187 | public: |
| 6188 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 6189 | uint32_t field_index, |
| 6190 | uint32_t dex_pc) |
| 6191 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6192 | field_index_(field_index) { |
| 6193 | } |
| 6194 | |
| 6195 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6196 | bool CanThrow() const OVERRIDE { return true; } |
| 6197 | |
| 6198 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6199 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6200 | |
| 6201 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6202 | |
| 6203 | private: |
| 6204 | const uint32_t field_index_; |
| 6205 | |
| 6206 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 6207 | }; |
| 6208 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6209 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6210 | public: |
| 6211 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 6212 | Primitive::Type field_type, |
| 6213 | uint32_t field_index, |
| 6214 | uint32_t dex_pc) |
| 6215 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6216 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6217 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6218 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6219 | SetRawInputAt(0, value); |
| 6220 | } |
| 6221 | |
| 6222 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6223 | bool CanThrow() const OVERRIDE { return true; } |
| 6224 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6225 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6226 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6227 | |
| 6228 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6229 | |
| 6230 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6231 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6232 | static constexpr size_t kFieldFieldTypeSize = |
| 6233 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6234 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6235 | kFieldFieldType + kFieldFieldTypeSize; |
| 6236 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6237 | "Too many packed fields."); |
| 6238 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6239 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6240 | const uint32_t field_index_; |
| 6241 | |
| 6242 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6243 | }; |
| 6244 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6245 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6246 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6247 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6248 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6249 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6250 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6251 | bool CanBeNull() const OVERRIDE { return false; } |
| 6252 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6253 | DECLARE_INSTRUCTION(LoadException); |
| 6254 | |
| 6255 | private: |
| 6256 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6257 | }; |
| 6258 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6259 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6260 | // 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] | 6261 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6262 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6263 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6264 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6265 | |
| 6266 | DECLARE_INSTRUCTION(ClearException); |
| 6267 | |
| 6268 | private: |
| 6269 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6270 | }; |
| 6271 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6272 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6273 | public: |
| 6274 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6275 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6276 | SetRawInputAt(0, exception); |
| 6277 | } |
| 6278 | |
| 6279 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6280 | |
| 6281 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6282 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6283 | bool CanThrow() const OVERRIDE { return true; } |
| 6284 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6285 | |
| 6286 | DECLARE_INSTRUCTION(Throw); |
| 6287 | |
| 6288 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6289 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6290 | }; |
| 6291 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6292 | /** |
| 6293 | * Implementation strategies for the code generator of a HInstanceOf |
| 6294 | * or `HCheckCast`. |
| 6295 | */ |
| 6296 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6297 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6298 | kExactCheck, // Can do a single class compare. |
| 6299 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6300 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6301 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6302 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6303 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6304 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6305 | }; |
| 6306 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6307 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6308 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6309 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6310 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6311 | HInstanceOf(HInstruction* object, |
| 6312 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6313 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6314 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6315 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6316 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6317 | dex_pc) { |
| 6318 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6319 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6320 | SetRawInputAt(0, object); |
| 6321 | SetRawInputAt(1, constant); |
| 6322 | } |
| 6323 | |
| 6324 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6325 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6326 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6327 | return true; |
| 6328 | } |
| 6329 | |
| 6330 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6331 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6332 | } |
| 6333 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6334 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6335 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6336 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6337 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6338 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6339 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6340 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6341 | // Mips currently does runtime calls for any other checks. |
| 6342 | return check_kind != TypeCheckKind::kExactCheck; |
| 6343 | } |
| 6344 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6345 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6346 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6347 | } |
| 6348 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6349 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6350 | |
| 6351 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6352 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6353 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6354 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6355 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6356 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6357 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6358 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6359 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6360 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6361 | }; |
| 6362 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6363 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6364 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6365 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6366 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6367 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6368 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6369 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6370 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6371 | SetRawInputAt(0, input); |
| 6372 | } |
| 6373 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6374 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6375 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6376 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6377 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6378 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6379 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6380 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6381 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6382 | } |
| 6383 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6384 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6385 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6386 | DECLARE_INSTRUCTION(BoundType); |
| 6387 | |
| 6388 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6389 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6390 | // is false then CanBeNull() cannot be true). |
| 6391 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6392 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6393 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6394 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6395 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6396 | // 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] | 6397 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6398 | // It is used to bound the type in cases like: |
| 6399 | // if (x instanceof ClassX) { |
| 6400 | // // uper_bound_ will be ClassX |
| 6401 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6402 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6403 | |
| 6404 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6405 | }; |
| 6406 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6407 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6408 | public: |
| 6409 | HCheckCast(HInstruction* object, |
| 6410 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6411 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6412 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6413 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6414 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6415 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6416 | SetRawInputAt(0, object); |
| 6417 | SetRawInputAt(1, constant); |
| 6418 | } |
| 6419 | |
| 6420 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6421 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6422 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6423 | return true; |
| 6424 | } |
| 6425 | |
| 6426 | bool NeedsEnvironment() const OVERRIDE { |
| 6427 | // Instruction may throw a CheckCastError. |
| 6428 | return true; |
| 6429 | } |
| 6430 | |
| 6431 | bool CanThrow() const OVERRIDE { return true; } |
| 6432 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6433 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6434 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6435 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6436 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6437 | |
| 6438 | DECLARE_INSTRUCTION(CheckCast); |
| 6439 | |
| 6440 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6441 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6442 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6443 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6444 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6445 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6446 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6447 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6448 | |
| 6449 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6450 | }; |
| 6451 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6452 | /** |
| 6453 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6454 | * @details We define the combined barrier types that are actually required |
| 6455 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6456 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6457 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6458 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6459 | * The current recipe is as follows: |
| 6460 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6461 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6462 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6463 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6464 | * class has final fields. |
| 6465 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6466 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6467 | */ |
| 6468 | enum MemBarrierKind { |
| 6469 | kAnyStore, |
| 6470 | kLoadAny, |
| 6471 | kStoreStore, |
| 6472 | kAnyAny, |
| 6473 | kNTStoreStore, |
| 6474 | kLastBarrierKind = kNTStoreStore |
| 6475 | }; |
| 6476 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6477 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6478 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6479 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6480 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6481 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6482 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6483 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6484 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6485 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6486 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6487 | |
| 6488 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6489 | |
| 6490 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6491 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6492 | static constexpr size_t kFieldBarrierKindSize = |
| 6493 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6494 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6495 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6496 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6497 | "Too many packed fields."); |
| 6498 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6499 | |
| 6500 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6501 | }; |
| 6502 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6503 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6504 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6505 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6506 | kEnter, |
| 6507 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6508 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6509 | }; |
| 6510 | |
| 6511 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6512 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6513 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6514 | dex_pc) { |
| 6515 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6516 | SetRawInputAt(0, object); |
| 6517 | } |
| 6518 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6519 | // Instruction may go into runtime, so we need an environment. |
| 6520 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6521 | |
| 6522 | bool CanThrow() const OVERRIDE { |
| 6523 | // Verifier guarantees that monitor-exit cannot throw. |
| 6524 | // This is important because it allows the HGraphBuilder to remove |
| 6525 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6526 | return IsEnter(); |
| 6527 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6528 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6529 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6530 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6531 | |
| 6532 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6533 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6534 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6535 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6536 | static constexpr size_t kFieldOperationKindSize = |
| 6537 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6538 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6539 | kFieldOperationKind + kFieldOperationKindSize; |
| 6540 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6541 | "Too many packed fields."); |
| 6542 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6543 | |
| 6544 | private: |
| 6545 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6546 | }; |
| 6547 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6548 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6549 | public: |
| 6550 | HSelect(HInstruction* condition, |
| 6551 | HInstruction* true_value, |
| 6552 | HInstruction* false_value, |
| 6553 | uint32_t dex_pc) |
| 6554 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6555 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6556 | |
| 6557 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6558 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6559 | // that architectures which implement HSelect as a conditional move also |
| 6560 | // will not need to invert the condition. |
| 6561 | SetRawInputAt(0, false_value); |
| 6562 | SetRawInputAt(1, true_value); |
| 6563 | SetRawInputAt(2, condition); |
| 6564 | } |
| 6565 | |
| 6566 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6567 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6568 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6569 | |
| 6570 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6571 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6572 | return true; |
| 6573 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6574 | |
| 6575 | bool CanBeNull() const OVERRIDE { |
| 6576 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6577 | } |
| 6578 | |
| 6579 | DECLARE_INSTRUCTION(Select); |
| 6580 | |
| 6581 | private: |
| 6582 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6583 | }; |
| 6584 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6585 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6586 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6587 | MoveOperands(Location source, |
| 6588 | Location destination, |
| 6589 | Primitive::Type type, |
| 6590 | HInstruction* instruction) |
| 6591 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6592 | |
| 6593 | Location GetSource() const { return source_; } |
| 6594 | Location GetDestination() const { return destination_; } |
| 6595 | |
| 6596 | void SetSource(Location value) { source_ = value; } |
| 6597 | void SetDestination(Location value) { destination_ = value; } |
| 6598 | |
| 6599 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6600 | // destination (but not the source). |
| 6601 | Location MarkPending() { |
| 6602 | DCHECK(!IsPending()); |
| 6603 | Location dest = destination_; |
| 6604 | destination_ = Location::NoLocation(); |
| 6605 | return dest; |
| 6606 | } |
| 6607 | |
| 6608 | void ClearPending(Location dest) { |
| 6609 | DCHECK(IsPending()); |
| 6610 | destination_ = dest; |
| 6611 | } |
| 6612 | |
| 6613 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6614 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6615 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6616 | } |
| 6617 | |
| 6618 | // True if this blocks a move from the given location. |
| 6619 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6620 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6621 | } |
| 6622 | |
| 6623 | // A move is redundant if it's been eliminated, if its source and |
| 6624 | // destination are the same, or if its destination is unneeded. |
| 6625 | bool IsRedundant() const { |
| 6626 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6627 | } |
| 6628 | |
| 6629 | // We clear both operands to indicate move that's been eliminated. |
| 6630 | void Eliminate() { |
| 6631 | source_ = destination_ = Location::NoLocation(); |
| 6632 | } |
| 6633 | |
| 6634 | bool IsEliminated() const { |
| 6635 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6636 | return source_.IsInvalid(); |
| 6637 | } |
| 6638 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6639 | Primitive::Type GetType() const { return type_; } |
| 6640 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6641 | bool Is64BitMove() const { |
| 6642 | return Primitive::Is64BitType(type_); |
| 6643 | } |
| 6644 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6645 | HInstruction* GetInstruction() const { return instruction_; } |
| 6646 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6647 | private: |
| 6648 | Location source_; |
| 6649 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6650 | // The type this move is for. |
| 6651 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6652 | // The instruction this move is assocatied with. Null when this move is |
| 6653 | // for moving an input in the expected locations of user (including a phi user). |
| 6654 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6655 | // in the same parallel move. |
| 6656 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6657 | }; |
| 6658 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6659 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6660 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6661 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6662 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6663 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6664 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6665 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6666 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6667 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6668 | moves_.reserve(kDefaultNumberOfMoves); |
| 6669 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6670 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6671 | void AddMove(Location source, |
| 6672 | Location destination, |
| 6673 | Primitive::Type type, |
| 6674 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6675 | DCHECK(source.IsValid()); |
| 6676 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6677 | if (kIsDebugBuild) { |
| 6678 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6679 | for (const MoveOperands& move : moves_) { |
| 6680 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6681 | // Special case the situation where the move is for the spill slot |
| 6682 | // of the instruction. |
| 6683 | if ((GetPrevious() == instruction) |
| 6684 | || ((GetPrevious() == nullptr) |
| 6685 | && instruction->IsPhi() |
| 6686 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6687 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6688 | << "Doing parallel moves for the same instruction."; |
| 6689 | } else { |
| 6690 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6691 | } |
| 6692 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6693 | } |
| 6694 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6695 | for (const MoveOperands& move : moves_) { |
| 6696 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6697 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6698 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6699 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6700 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6701 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6702 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6703 | } |
| 6704 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6705 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6706 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6707 | } |
| 6708 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6709 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6710 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6711 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6712 | |
| 6713 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6714 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6715 | |
| 6716 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6717 | }; |
| 6718 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6719 | } // namespace art |
| 6720 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame^] | 6721 | #include "nodes_vector.h" |
| 6722 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6723 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6724 | #include "nodes_shared.h" |
| 6725 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6726 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6727 | #include "nodes_arm.h" |
| 6728 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6729 | #ifdef ART_ENABLE_CODEGEN_mips |
| 6730 | #include "nodes_mips.h" |
| 6731 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6732 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6733 | #include "nodes_x86.h" |
| 6734 | #endif |
| 6735 | |
| 6736 | namespace art { |
| 6737 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6738 | class HGraphVisitor : public ValueObject { |
| 6739 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6740 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6741 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6742 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6743 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6744 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6745 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6746 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6747 | void VisitInsertionOrder(); |
| 6748 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6749 | // Visit the graph following dominator tree reverse post-order. |
| 6750 | void VisitReversePostOrder(); |
| 6751 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6752 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6753 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6754 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6755 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6756 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6757 | |
| 6758 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6759 | |
| 6760 | #undef DECLARE_VISIT_INSTRUCTION |
| 6761 | |
| 6762 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6763 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6764 | |
| 6765 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6766 | }; |
| 6767 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6768 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6769 | public: |
| 6770 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6771 | virtual ~HGraphDelegateVisitor() {} |
| 6772 | |
| 6773 | // Visit functions that delegate to to super class. |
| 6774 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6775 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6776 | |
| 6777 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6778 | |
| 6779 | #undef DECLARE_VISIT_INSTRUCTION |
| 6780 | |
| 6781 | private: |
| 6782 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6783 | }; |
| 6784 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6785 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6786 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6787 | // block id. |
| 6788 | class HBlocksInLoopIterator : public ValueObject { |
| 6789 | public: |
| 6790 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6791 | : blocks_in_loop_(info.GetBlocks()), |
| 6792 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6793 | index_(0) { |
| 6794 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6795 | Advance(); |
| 6796 | } |
| 6797 | } |
| 6798 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6799 | bool Done() const { return index_ == blocks_.size(); } |
| 6800 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6801 | void Advance() { |
| 6802 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6803 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6804 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6805 | break; |
| 6806 | } |
| 6807 | } |
| 6808 | } |
| 6809 | |
| 6810 | private: |
| 6811 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6812 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6813 | size_t index_; |
| 6814 | |
| 6815 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6816 | }; |
| 6817 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6818 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6819 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6820 | // post order. |
| 6821 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6822 | public: |
| 6823 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6824 | : blocks_in_loop_(info.GetBlocks()), |
| 6825 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6826 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6827 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6828 | Advance(); |
| 6829 | } |
| 6830 | } |
| 6831 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6832 | bool Done() const { return index_ == blocks_.size(); } |
| 6833 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6834 | void Advance() { |
| 6835 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6836 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6837 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6838 | break; |
| 6839 | } |
| 6840 | } |
| 6841 | } |
| 6842 | |
| 6843 | private: |
| 6844 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6845 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6846 | size_t index_; |
| 6847 | |
| 6848 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6849 | }; |
| 6850 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6851 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6852 | if (constant->IsIntConstant()) { |
| 6853 | return constant->AsIntConstant()->GetValue(); |
| 6854 | } else if (constant->IsLongConstant()) { |
| 6855 | return constant->AsLongConstant()->GetValue(); |
| 6856 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6857 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6858 | return 0; |
| 6859 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6860 | } |
| 6861 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6862 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6863 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6864 | inline const H##type* HInstruction::As##type() const { \ |
| 6865 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6866 | } \ |
| 6867 | inline H##type* HInstruction::As##type() { \ |
| 6868 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6869 | } |
| 6870 | |
| 6871 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6872 | #undef INSTRUCTION_TYPE_CHECK |
| 6873 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6874 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6875 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6876 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6877 | size_t number_of_new_blocks, |
| 6878 | size_t after) { |
| 6879 | DCHECK_LT(after, blocks->size()); |
| 6880 | size_t old_size = blocks->size(); |
| 6881 | size_t new_size = old_size + number_of_new_blocks; |
| 6882 | blocks->resize(new_size); |
| 6883 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6884 | } |
| 6885 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6886 | /* |
| 6887 | * Hunt "under the hood" of array lengths (leading to array references), |
| 6888 | * null checks (also leading to array references), and new arrays |
| 6889 | * (leading to the actual length). This makes it more likely related |
| 6890 | * instructions become actually comparable. |
| 6891 | */ |
| 6892 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 6893 | while (instruction->IsArrayLength() || |
| 6894 | instruction->IsNullCheck() || |
| 6895 | instruction->IsNewArray()) { |
| 6896 | instruction = instruction->IsNewArray() |
| 6897 | ? instruction->AsNewArray()->GetLength() |
| 6898 | : instruction->InputAt(0); |
| 6899 | } |
| 6900 | return instruction; |
| 6901 | } |
| 6902 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6903 | } // namespace art |
| 6904 | |
| 6905 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |