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" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 31 | #include "deoptimization_kind.h" |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 32 | #include "dex_file.h" |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 33 | #include "dex_file_types.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 34 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 35 | #include "handle.h" |
| 36 | #include "handle_scope.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 37 | #include "intrinsics_enum.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 38 | #include "invoke_type.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 39 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 40 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 41 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 42 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 43 | #include "primitive.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 44 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 45 | |
| 46 | namespace art { |
| 47 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 48 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 49 | class HBasicBlock; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 50 | class HConstructorFence; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 51 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 52 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 53 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 54 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 55 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 56 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 57 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 58 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 59 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 60 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 61 | class HNullConstant; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 62 | class HParameterValue; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 63 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 64 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 65 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 66 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 67 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 68 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 69 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 70 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 71 | namespace mirror { |
| 72 | class DexCache; |
| 73 | } // namespace mirror |
| 74 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 75 | static const int kDefaultNumberOfBlocks = 8; |
| 76 | static const int kDefaultNumberOfSuccessors = 2; |
| 77 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 78 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 79 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 80 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 81 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 82 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 83 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 84 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 85 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 86 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 87 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 88 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 89 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 90 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 91 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 92 | static constexpr uint32_t kNoDexPc = -1; |
| 93 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 94 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 95 | // For the purposes of the compiler, the dex files must actually be the same object |
| 96 | // if we want to safely treat them as the same. This is especially important for JIT |
| 97 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 98 | // times and provide different class resolution but no two class loaders should ever |
| 99 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 100 | // all sorts of weird failures. |
| 101 | return &lhs == &rhs; |
| 102 | } |
| 103 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 104 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 105 | // All types. |
| 106 | kCondEQ, // == |
| 107 | kCondNE, // != |
| 108 | // Signed integers and floating-point numbers. |
| 109 | kCondLT, // < |
| 110 | kCondLE, // <= |
| 111 | kCondGT, // > |
| 112 | kCondGE, // >= |
| 113 | // Unsigned integers. |
| 114 | kCondB, // < |
| 115 | kCondBE, // <= |
| 116 | kCondA, // > |
| 117 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 118 | // First and last aliases. |
| 119 | kCondFirst = kCondEQ, |
| 120 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 123 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 124 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 125 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 126 | kAnalysisFailThrowCatchLoop, |
| 127 | kAnalysisFailAmbiguousArrayOp, |
| 128 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 131 | template <typename T> |
| 132 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 133 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 134 | } |
| 135 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 136 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 137 | public: |
| 138 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 139 | |
| 140 | void AddInstruction(HInstruction* instruction); |
| 141 | void RemoveInstruction(HInstruction* instruction); |
| 142 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 143 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 144 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 145 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 146 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 147 | // Return true if this list contains `instruction`. |
| 148 | bool Contains(HInstruction* instruction) const; |
| 149 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 150 | // Return true if `instruction1` is found before `instruction2` in |
| 151 | // this instruction list and false otherwise. Abort if none |
| 152 | // of these instructions is found. |
| 153 | bool FoundBefore(const HInstruction* instruction1, |
| 154 | const HInstruction* instruction2) const; |
| 155 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 156 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 157 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 158 | |
| 159 | // Update the block of all instructions to be `block`. |
| 160 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 161 | |
| 162 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 163 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 164 | void Add(const HInstructionList& instruction_list); |
| 165 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 166 | // Return the number of instructions in the list. This is an expensive operation. |
| 167 | size_t CountSize() const; |
| 168 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 169 | private: |
| 170 | HInstruction* first_instruction_; |
| 171 | HInstruction* last_instruction_; |
| 172 | |
| 173 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 174 | friend class HGraph; |
| 175 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 176 | friend class HInstructionIterator; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 177 | friend class HInstructionIteratorHandleChanges; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 178 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 179 | |
| 180 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 181 | }; |
| 182 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 183 | class ReferenceTypeInfo : ValueObject { |
| 184 | public: |
| 185 | typedef Handle<mirror::Class> TypeHandle; |
| 186 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 187 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 188 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 189 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 190 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 191 | } |
| 192 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 193 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 194 | return ReferenceTypeInfo(type_handle, is_exact); |
| 195 | } |
| 196 | |
| 197 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 198 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 199 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 200 | return handle.GetReference() != nullptr; |
| 201 | } |
| 202 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 203 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 204 | return IsValidHandle(type_handle_); |
| 205 | } |
| 206 | |
| 207 | bool IsExact() const { return is_exact_; } |
| 208 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 209 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 210 | DCHECK(IsValid()); |
| 211 | return GetTypeHandle()->IsObjectClass(); |
| 212 | } |
| 213 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 214 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 215 | DCHECK(IsValid()); |
| 216 | return GetTypeHandle()->IsStringClass(); |
| 217 | } |
| 218 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 219 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 220 | DCHECK(IsValid()); |
| 221 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 222 | } |
| 223 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 224 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 225 | DCHECK(IsValid()); |
| 226 | return GetTypeHandle()->IsInterface(); |
| 227 | } |
| 228 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 229 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 230 | DCHECK(IsValid()); |
| 231 | return GetTypeHandle()->IsArrayClass(); |
| 232 | } |
| 233 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 234 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 235 | DCHECK(IsValid()); |
| 236 | return GetTypeHandle()->IsPrimitiveArray(); |
| 237 | } |
| 238 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 239 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 240 | DCHECK(IsValid()); |
| 241 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 242 | } |
| 243 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 244 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 245 | DCHECK(IsValid()); |
| 246 | if (!IsExact()) return false; |
| 247 | if (!IsArrayClass()) return false; |
| 248 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 249 | } |
| 250 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 251 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 252 | DCHECK(IsValid()); |
| 253 | if (!IsExact()) return false; |
| 254 | if (!IsArrayClass()) return false; |
| 255 | if (!rti.IsArrayClass()) return false; |
| 256 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 257 | rti.GetTypeHandle()->GetComponentType()); |
| 258 | } |
| 259 | |
| 260 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 261 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 262 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 263 | DCHECK(IsValid()); |
| 264 | DCHECK(rti.IsValid()); |
| 265 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 266 | } |
| 267 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 268 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 269 | DCHECK(IsValid()); |
| 270 | DCHECK(rti.IsValid()); |
| 271 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 272 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 273 | } |
| 274 | |
| 275 | // Returns true if the type information provide the same amount of details. |
| 276 | // Note that it does not mean that the instructions have the same actual type |
| 277 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 278 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 279 | if (!IsValid() && !rti.IsValid()) { |
| 280 | // Invalid types are equal. |
| 281 | return true; |
| 282 | } |
| 283 | if (!IsValid() || !rti.IsValid()) { |
| 284 | // One is valid, the other not. |
| 285 | return false; |
| 286 | } |
| 287 | return IsExact() == rti.IsExact() |
| 288 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 289 | } |
| 290 | |
| 291 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 292 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 293 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 294 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 295 | |
| 296 | // The class of the object. |
| 297 | TypeHandle type_handle_; |
| 298 | // Whether or not the type is exact or a superclass of the actual type. |
| 299 | // Whether or not we have any information about this type. |
| 300 | bool is_exact_; |
| 301 | }; |
| 302 | |
| 303 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 304 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 305 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 306 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 307 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 308 | HGraph(ArenaAllocator* arena, |
| 309 | const DexFile& dex_file, |
| 310 | uint32_t method_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 311 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 312 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 313 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 314 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 315 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 316 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 317 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 318 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 319 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 320 | entry_block_(nullptr), |
| 321 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 322 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 323 | number_of_vregs_(0), |
| 324 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 325 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 326 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 327 | has_try_catch_(false), |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 328 | has_simd_(false), |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 329 | has_loops_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 330 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 331 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 332 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 333 | dex_file_(dex_file), |
| 334 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 335 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 336 | in_ssa_form_(false), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 337 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 338 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 339 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 340 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 341 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 342 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 343 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 344 | cached_current_method_(nullptr), |
Nicolas Geoffray | 53fec08 | 2017-03-27 12:56:16 +0100 | [diff] [blame] | 345 | art_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 346 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 347 | osr_(osr), |
| 348 | cha_single_implementation_list_(arena->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 349 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 350 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 351 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 352 | // 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] | 353 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 354 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 355 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 356 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 357 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 358 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 359 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 360 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 361 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 362 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 363 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 364 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 365 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 366 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 367 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 368 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 369 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 370 | void ComputeDominanceInformation(); |
| 371 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 372 | void ClearLoopInformation(); |
| 373 | void FindBackEdges(ArenaBitVector* visited); |
| 374 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 375 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 376 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 377 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 378 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 379 | // 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] | 380 | // 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] | 381 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 382 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 383 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 384 | // order and loop information. |
| 385 | void ComputeTryBlockInformation(); |
| 386 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 387 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 388 | // Returns the instruction to replace the invoke expression or null if the |
| 389 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 390 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 391 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 392 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 393 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 394 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 395 | // should be the new back edge. |
| 396 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 397 | HBasicBlock* reference, |
| 398 | bool replace_if_back_edge); |
| 399 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 400 | // Need to add a couple of blocks to test if the loop body is entered and |
| 401 | // put deoptimization instructions, etc. |
| 402 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 403 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 404 | // Adds a new loop directly after the loop with the given header and exit. |
| 405 | // Returns the new preheader. |
| 406 | HBasicBlock* TransformLoopForVectorization(HBasicBlock* header, |
| 407 | HBasicBlock* body, |
| 408 | HBasicBlock* exit); |
| 409 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 410 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 411 | // other blocks and has no instructions or phis. |
| 412 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 413 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 414 | // Splits the edge between `block` and `successor` while preserving the |
| 415 | // indices in the predecessor/successor lists. If there are multiple edges |
| 416 | // between the blocks, the lowest indices are used. |
| 417 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 418 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 419 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 420 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 421 | void SimplifyLoop(HBasicBlock* header); |
| 422 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 423 | int32_t GetNextInstructionId() { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 424 | CHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 425 | return current_instruction_id_++; |
| 426 | } |
| 427 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 428 | int32_t GetCurrentInstructionId() const { |
| 429 | return current_instruction_id_; |
| 430 | } |
| 431 | |
| 432 | void SetCurrentInstructionId(int32_t id) { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 433 | CHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 434 | current_instruction_id_ = id; |
| 435 | } |
| 436 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 437 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 438 | return maximum_number_of_out_vregs_; |
| 439 | } |
| 440 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 441 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 442 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 443 | } |
| 444 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 445 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 446 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 447 | } |
| 448 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 449 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 450 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 451 | } |
| 452 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 453 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 454 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 455 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 456 | } |
| 457 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 458 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 459 | number_of_vregs_ = number_of_vregs; |
| 460 | } |
| 461 | |
| 462 | uint16_t GetNumberOfVRegs() const { |
| 463 | return number_of_vregs_; |
| 464 | } |
| 465 | |
| 466 | void SetNumberOfInVRegs(uint16_t value) { |
| 467 | number_of_in_vregs_ = value; |
| 468 | } |
| 469 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 470 | uint16_t GetNumberOfInVRegs() const { |
| 471 | return number_of_in_vregs_; |
| 472 | } |
| 473 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 474 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 475 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 476 | return number_of_vregs_ - number_of_in_vregs_; |
| 477 | } |
| 478 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 479 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 480 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 481 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 482 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 483 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 484 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 485 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 486 | } |
| 487 | |
| 488 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 489 | return ReverseRange(GetReversePostOrder()); |
| 490 | } |
| 491 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 492 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 493 | return linear_order_; |
| 494 | } |
| 495 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 496 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 497 | return ReverseRange(GetLinearOrder()); |
| 498 | } |
| 499 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 500 | bool HasBoundsChecks() const { |
| 501 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 504 | void SetHasBoundsChecks(bool value) { |
| 505 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 506 | } |
| 507 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 508 | bool IsDebuggable() const { return debuggable_; } |
| 509 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 510 | // 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] | 511 | // already, it is created and inserted into the graph. This method is only for |
| 512 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 513 | 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] | 514 | |
| 515 | // TODO: This is problematic for the consistency of reference type propagation |
| 516 | // because it can be created anytime after the pass and thus it will be left |
| 517 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 518 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 519 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 520 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 521 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 522 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 523 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 524 | return CreateConstant(value, &cached_long_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 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 527 | 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] | 528 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 529 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 530 | 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] | 531 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 532 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 533 | HCurrentMethod* GetCurrentMethod(); |
| 534 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 535 | const DexFile& GetDexFile() const { |
| 536 | return dex_file_; |
| 537 | } |
| 538 | |
| 539 | uint32_t GetMethodIdx() const { |
| 540 | return method_idx_; |
| 541 | } |
| 542 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 543 | // Get the method name (without the signature), e.g. "<init>" |
| 544 | const char* GetMethodName() const; |
| 545 | |
| 546 | // Get the pretty method name (class + name + optionally signature). |
| 547 | std::string PrettyMethod(bool with_signature = true) const; |
| 548 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 549 | InvokeType GetInvokeType() const { |
| 550 | return invoke_type_; |
| 551 | } |
| 552 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 553 | InstructionSet GetInstructionSet() const { |
| 554 | return instruction_set_; |
| 555 | } |
| 556 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 557 | bool IsCompilingOsr() const { return osr_; } |
| 558 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 559 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 560 | return cha_single_implementation_list_; |
| 561 | } |
| 562 | |
| 563 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 564 | cha_single_implementation_list_.insert(method); |
| 565 | } |
| 566 | |
| 567 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 568 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 569 | } |
| 570 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 571 | bool HasTryCatch() const { return has_try_catch_; } |
| 572 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 573 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 574 | bool HasSIMD() const { return has_simd_; } |
| 575 | void SetHasSIMD(bool value) { has_simd_ = value; } |
| 576 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 577 | bool HasLoops() const { return has_loops_; } |
| 578 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 579 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 580 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 581 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 582 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 583 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 584 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 585 | |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 586 | // Returns an instruction with the opposite Boolean value from 'cond'. |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 587 | // The instruction has been inserted into the graph, either as a constant, or |
| 588 | // before cursor. |
| 589 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 590 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 591 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 592 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 593 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 594 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 595 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 596 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 597 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 598 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 599 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 600 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 601 | template <class InstructionType, typename ValueType> |
| 602 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 603 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 604 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 605 | // Try to find an existing constant of the given value. |
| 606 | InstructionType* constant = nullptr; |
| 607 | auto cached_constant = cache->find(value); |
| 608 | if (cached_constant != cache->end()) { |
| 609 | constant = cached_constant->second; |
| 610 | } |
| 611 | |
| 612 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 613 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 614 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 615 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 616 | cache->Overwrite(value, constant); |
| 617 | InsertConstant(constant); |
| 618 | } |
| 619 | return constant; |
| 620 | } |
| 621 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 622 | void InsertConstant(HConstant* instruction); |
| 623 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 624 | // Cache a float constant into the graph. This method should only be |
| 625 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 626 | void CacheFloatConstant(HFloatConstant* constant); |
| 627 | |
| 628 | // See CacheFloatConstant comment. |
| 629 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 630 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 631 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 632 | |
| 633 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 634 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 635 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 636 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 637 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 638 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 639 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 640 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 641 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 642 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 643 | HBasicBlock* entry_block_; |
| 644 | HBasicBlock* exit_block_; |
| 645 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 646 | // 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] | 647 | uint16_t maximum_number_of_out_vregs_; |
| 648 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 649 | // The number of virtual registers in this method. Contains the parameters. |
| 650 | uint16_t number_of_vregs_; |
| 651 | |
| 652 | // The number of virtual registers used by parameters of this method. |
| 653 | uint16_t number_of_in_vregs_; |
| 654 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 655 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 656 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 657 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 658 | // Flag whether there are bounds checks in the graph. We can skip |
| 659 | // BCE if it's false. It's only best effort to keep it up to date in |
| 660 | // the presence of code elimination so there might be false positives. |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 661 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 662 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 663 | // Flag whether there are try/catch blocks in the graph. We will skip |
| 664 | // try/catch-related passes if it's false. It's only best effort to keep |
| 665 | // it up to date in the presence of code elimination so there might be |
| 666 | // false positives. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 667 | bool has_try_catch_; |
| 668 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 669 | // Flag whether SIMD instructions appear in the graph. If true, the |
| 670 | // code generators may have to be more careful spilling the wider |
| 671 | // contents of SIMD registers. |
| 672 | bool has_simd_; |
| 673 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 674 | // Flag whether there are any loops in the graph. We can skip loop |
| 675 | // optimization if it's false. It's only best effort to keep it up |
| 676 | // to date in the presence of code elimination so there might be false |
| 677 | // positives. |
| 678 | bool has_loops_; |
| 679 | |
| 680 | // Flag whether there are any irreducible loops in the graph. It's only |
| 681 | // best effort to keep it up to date in the presence of code elimination |
| 682 | // so there might be false positives. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 683 | bool has_irreducible_loops_; |
| 684 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 685 | // Indicates whether the graph should be compiled in a way that |
| 686 | // ensures full debuggability. If false, we can apply more |
| 687 | // aggressive optimizations that may limit the level of debugging. |
| 688 | const bool debuggable_; |
| 689 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 690 | // 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] | 691 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 692 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 693 | // The dex file from which the method is from. |
| 694 | const DexFile& dex_file_; |
| 695 | |
| 696 | // The method index in the dex file. |
| 697 | const uint32_t method_idx_; |
| 698 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 699 | // If inlined, this encodes how the callee is being invoked. |
| 700 | const InvokeType invoke_type_; |
| 701 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 702 | // Whether the graph has been transformed to SSA form. Only used |
| 703 | // in debug mode to ensure we are not using properties only valid |
| 704 | // for non-SSA form (like the number of temporaries). |
| 705 | bool in_ssa_form_; |
| 706 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 707 | // Number of CHA guards in the graph. Used to short-circuit the |
| 708 | // CHA guard optimization pass when there is no CHA guard left. |
| 709 | uint32_t number_of_cha_guards_; |
| 710 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 711 | const InstructionSet instruction_set_; |
| 712 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 713 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 714 | HNullConstant* cached_null_constant_; |
| 715 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 716 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 717 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 718 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 719 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 720 | HCurrentMethod* cached_current_method_; |
| 721 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 722 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 723 | // for example for methods whose declaring class could not be resolved |
| 724 | // (such as when the superclass could not be found). |
| 725 | ArtMethod* art_method_; |
| 726 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 727 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 728 | // collection pointer to passes which may create NullConstant. |
| 729 | ReferenceTypeInfo inexact_object_rti_; |
| 730 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 731 | // Whether we are compiling this graph for on stack replacement: this will |
| 732 | // make all loops seen as irreducible and emit special stack maps to mark |
| 733 | // compiled code entries which the interpreter can directly jump to. |
| 734 | const bool osr_; |
| 735 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 736 | // List of methods that are assumed to have single implementation. |
| 737 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 738 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 739 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 740 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 741 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 742 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 743 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 744 | }; |
| 745 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 746 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 747 | public: |
| 748 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 749 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 750 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 751 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 752 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 753 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 754 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 755 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 756 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 757 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 758 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 759 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 760 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 761 | |
| 762 | void Dump(std::ostream& os); |
| 763 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 764 | HBasicBlock* GetHeader() const { |
| 765 | return header_; |
| 766 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 767 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 768 | void SetHeader(HBasicBlock* block) { |
| 769 | header_ = block; |
| 770 | } |
| 771 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 772 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 773 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 774 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 775 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 776 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 777 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 778 | } |
| 779 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 780 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 781 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 782 | } |
| 783 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 784 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 785 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 786 | } |
| 787 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 788 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 789 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 792 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 793 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 794 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 795 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 796 | } |
| 797 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 798 | // Returns the lifetime position of the back edge that has the |
| 799 | // greatest lifetime position. |
| 800 | size_t GetLifetimeEnd() const; |
| 801 | |
| 802 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 803 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 804 | } |
| 805 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 806 | // Finds blocks that are part of this loop. |
| 807 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 808 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 809 | // Returns whether this loop information contains `block`. |
| 810 | // Note that this loop information *must* be populated before entering this function. |
| 811 | bool Contains(const HBasicBlock& block) const; |
| 812 | |
| 813 | // Returns whether this loop information is an inner loop of `other`. |
| 814 | // Note that `other` *must* be populated before entering this function. |
| 815 | bool IsIn(const HLoopInformation& other) const; |
| 816 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 817 | // Returns true if instruction is not defined within this loop. |
| 818 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 819 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 820 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 821 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 822 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 823 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 824 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 825 | void ClearAllBlocks() { |
| 826 | blocks_.ClearAllBits(); |
| 827 | } |
| 828 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 829 | bool HasBackEdgeNotDominatedByHeader() const; |
| 830 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 831 | bool IsPopulated() const { |
| 832 | return blocks_.GetHighestBitSet() != -1; |
| 833 | } |
| 834 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 835 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 836 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 837 | bool HasExitEdge() const; |
| 838 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 839 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 840 | // Internal recursive implementation of `Populate`. |
| 841 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 842 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 843 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 844 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 845 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 846 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 847 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 848 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 849 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 850 | |
| 851 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 852 | }; |
| 853 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 854 | // Stores try/catch information for basic blocks. |
| 855 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 856 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 857 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 858 | public: |
| 859 | // Try block information constructor. |
| 860 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 861 | : try_entry_(&try_entry), |
| 862 | catch_dex_file_(nullptr), |
| 863 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 864 | DCHECK(try_entry_ != nullptr); |
| 865 | } |
| 866 | |
| 867 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 868 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 869 | : try_entry_(nullptr), |
| 870 | catch_dex_file_(&dex_file), |
| 871 | catch_type_index_(catch_type_index) {} |
| 872 | |
| 873 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 874 | |
| 875 | const HTryBoundary& GetTryEntry() const { |
| 876 | DCHECK(IsTryBlock()); |
| 877 | return *try_entry_; |
| 878 | } |
| 879 | |
| 880 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 881 | |
| 882 | bool IsCatchAllTypeIndex() const { |
| 883 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 884 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 885 | } |
| 886 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 887 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 888 | DCHECK(IsCatchBlock()); |
| 889 | return catch_type_index_; |
| 890 | } |
| 891 | |
| 892 | const DexFile& GetCatchDexFile() const { |
| 893 | DCHECK(IsCatchBlock()); |
| 894 | return *catch_dex_file_; |
| 895 | } |
| 896 | |
| 897 | private: |
| 898 | // One of possibly several TryBoundary instructions entering the block's try. |
| 899 | // Only set for try blocks. |
| 900 | const HTryBoundary* try_entry_; |
| 901 | |
| 902 | // Exception type information. Only set for catch blocks. |
| 903 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 904 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 905 | }; |
| 906 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 907 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 908 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 909 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 910 | // A block in a method. Contains the list of instructions represented |
| 911 | // as a double linked list. Each block knows its predecessors and |
| 912 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 913 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 914 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 915 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 916 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 917 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 918 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 919 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 920 | loop_information_(nullptr), |
| 921 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 922 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 923 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 924 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 925 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 926 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 927 | try_catch_information_(nullptr) { |
| 928 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 929 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 930 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 931 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 932 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 933 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 934 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 935 | } |
| 936 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 937 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 938 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 939 | } |
| 940 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 941 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 942 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 943 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 944 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 945 | return ContainsElement(successors_, block, start_from); |
| 946 | } |
| 947 | |
| 948 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 949 | return dominated_blocks_; |
| 950 | } |
| 951 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 952 | bool IsEntryBlock() const { |
| 953 | return graph_->GetEntryBlock() == this; |
| 954 | } |
| 955 | |
| 956 | bool IsExitBlock() const { |
| 957 | return graph_->GetExitBlock() == this; |
| 958 | } |
| 959 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 960 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 961 | bool IsSingleTryBoundary() const; |
| 962 | |
| 963 | // Returns true if this block emits nothing but a jump. |
| 964 | bool IsSingleJump() const { |
| 965 | HLoopInformation* loop_info = GetLoopInformation(); |
| 966 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 967 | // Back edges generate a suspend check. |
| 968 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 969 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 970 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 971 | void AddBackEdge(HBasicBlock* back_edge) { |
| 972 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 973 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 974 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 975 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 976 | loop_information_->AddBackEdge(back_edge); |
| 977 | } |
| 978 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 979 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 980 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 981 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 982 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 983 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 984 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 985 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 986 | HBasicBlock* GetDominator() const { return dominator_; } |
| 987 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 988 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 989 | |
| 990 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 991 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 992 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 993 | |
| 994 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 995 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 996 | } |
| 997 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 998 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 999 | |
| 1000 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1001 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1004 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1005 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1006 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1007 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1008 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1009 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1010 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1011 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1012 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1013 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1014 | successors_.push_back(block); |
| 1015 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1018 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1019 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1020 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1021 | new_block->predecessors_.push_back(this); |
| 1022 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1025 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1026 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1027 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1028 | new_block->successors_.push_back(this); |
| 1029 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1032 | // Insert `this` between `predecessor` and `successor. This method |
| 1033 | // preserves the indicies, and will update the first edge found between |
| 1034 | // `predecessor` and `successor`. |
| 1035 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1036 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1037 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1038 | successor->predecessors_[predecessor_index] = this; |
| 1039 | predecessor->successors_[successor_index] = this; |
| 1040 | successors_.push_back(successor); |
| 1041 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1042 | } |
| 1043 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1044 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1045 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1048 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1049 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1052 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1053 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1057 | predecessors_.push_back(block); |
| 1058 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1059 | } |
| 1060 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1061 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1062 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1063 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1066 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1067 | DCHECK_EQ(successors_.size(), 2u); |
| 1068 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1069 | } |
| 1070 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1071 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1072 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1075 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1076 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1077 | } |
| 1078 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1079 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1080 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1081 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1085 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1086 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1090 | // predecessors is at index `idx`. |
| 1091 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1092 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1093 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1094 | } |
| 1095 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1096 | // Create a new block between this block and its predecessors. The new block |
| 1097 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1098 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1099 | // loop and try/catch information are not updated. |
| 1100 | HBasicBlock* CreateImmediateDominator(); |
| 1101 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1102 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1103 | // created, latter block. Note that this method will add the block to the |
| 1104 | // graph, create a Goto at the end of the former block and will create an edge |
| 1105 | // 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] | 1106 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1107 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1108 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1109 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1110 | // created block. Note that this method just updates raw block information, |
| 1111 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1112 | // update the graph, reverse post order, loop information, nor make sure the |
| 1113 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1114 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1115 | |
| 1116 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1117 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1118 | |
| 1119 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1120 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1121 | // that this method does not update the graph, reverse post order, loop |
| 1122 | // information, nor make sure the blocks are consistent (for example ending |
| 1123 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1124 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1125 | |
| 1126 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1127 | // of `this` are moved to `other`. |
| 1128 | // Note that this method does not update the graph, reverse post order, loop |
| 1129 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1130 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1131 | void ReplaceWith(HBasicBlock* other); |
| 1132 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1133 | // Merges the instructions of `other` at the end of `this`. |
| 1134 | void MergeInstructionsWith(HBasicBlock* other); |
| 1135 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1136 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1137 | // order, links to predecessors, successors, dominators and deletes the block |
| 1138 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1139 | // predecessor of `other` and vice versa. |
| 1140 | void MergeWith(HBasicBlock* other); |
| 1141 | |
| 1142 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1143 | // removes it from all loops it is included in and eventually from the graph. |
| 1144 | // The block must not dominate any other block. Predecessors and successors |
| 1145 | // are safely updated. |
| 1146 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1147 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1148 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1149 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1150 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1151 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1152 | // Replace instruction `initial` with `replacement` within this block. |
| 1153 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1154 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1155 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1156 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1157 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1158 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1159 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1160 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1161 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1162 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1163 | |
| 1164 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1165 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1166 | } |
| 1167 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1168 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1169 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1170 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1171 | } |
| 1172 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1173 | bool IsFirstPredecessorBackEdge() const { |
| 1174 | DCHECK(IsLoopHeader()); |
| 1175 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1176 | } |
| 1177 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1178 | HLoopInformation* GetLoopInformation() const { |
| 1179 | return loop_information_; |
| 1180 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1181 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1182 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1183 | // 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] | 1184 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1185 | void SetInLoop(HLoopInformation* info) { |
| 1186 | if (IsLoopHeader()) { |
| 1187 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1188 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1189 | loop_information_ = info; |
| 1190 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1191 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1192 | // Note that a non loop header having a loop information means this loop information |
| 1193 | // has already been populated |
| 1194 | loop_information_ = info; |
| 1195 | } else { |
| 1196 | // Block is part of an inner loop. Do not update the loop information. |
| 1197 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1198 | // at this point, because this method is being called while populating `info`. |
| 1199 | } |
| 1200 | } |
| 1201 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1202 | // Raw update of the loop information. |
| 1203 | void SetLoopInformation(HLoopInformation* info) { |
| 1204 | loop_information_ = info; |
| 1205 | } |
| 1206 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1207 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1208 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1209 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1210 | |
| 1211 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1212 | try_catch_information_ = try_catch_information; |
| 1213 | } |
| 1214 | |
| 1215 | bool IsTryBlock() const { |
| 1216 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1217 | } |
| 1218 | |
| 1219 | bool IsCatchBlock() const { |
| 1220 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1221 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1222 | |
| 1223 | // Returns the try entry that this block's successors should have. They will |
| 1224 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1225 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1226 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1227 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1228 | bool HasThrowingInstructions() const; |
| 1229 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1230 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1231 | bool Dominates(HBasicBlock* block) const; |
| 1232 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1233 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1234 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1235 | |
| 1236 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1237 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1238 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1239 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1240 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1241 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1242 | bool HasSinglePhi() const; |
| 1243 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1244 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1245 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1246 | ArenaVector<HBasicBlock*> predecessors_; |
| 1247 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1248 | HInstructionList instructions_; |
| 1249 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1250 | HLoopInformation* loop_information_; |
| 1251 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1252 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1253 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1254 | // The dex program counter of the first instruction of this block. |
| 1255 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1256 | size_t lifetime_start_; |
| 1257 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1258 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1259 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1260 | friend class HGraph; |
| 1261 | friend class HInstruction; |
| 1262 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1263 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1264 | }; |
| 1265 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1266 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1267 | // from the innermost to the outermost. |
| 1268 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1269 | public: |
| 1270 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1271 | : current_(block.GetLoopInformation()) {} |
| 1272 | |
| 1273 | bool Done() const { return current_ == nullptr; } |
| 1274 | |
| 1275 | void Advance() { |
| 1276 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1277 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | HLoopInformation* Current() const { |
| 1281 | DCHECK(!Done()); |
| 1282 | return current_; |
| 1283 | } |
| 1284 | |
| 1285 | private: |
| 1286 | HLoopInformation* current_; |
| 1287 | |
| 1288 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1289 | }; |
| 1290 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1291 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1292 | M(Above, Condition) \ |
| 1293 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1294 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1295 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1296 | M(ArrayGet, Instruction) \ |
| 1297 | M(ArrayLength, Instruction) \ |
| 1298 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1299 | M(Below, Condition) \ |
| 1300 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1301 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1302 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1303 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1304 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1305 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1306 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1307 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1308 | M(Compare, BinaryOperation) \ |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1309 | M(ConstructorFence, Instruction) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1310 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1311 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1312 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1313 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1314 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1315 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1316 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1317 | M(Exit, Instruction) \ |
| 1318 | M(FloatConstant, Constant) \ |
| 1319 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1320 | M(GreaterThan, Condition) \ |
| 1321 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1322 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1323 | M(InstanceFieldGet, Instruction) \ |
| 1324 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1325 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1326 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1327 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1328 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1329 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1330 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1331 | M(InvokePolymorphic, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1332 | M(LessThan, Condition) \ |
| 1333 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1334 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1335 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1336 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1337 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1338 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1339 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1340 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1341 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1342 | M(Neg, UnaryOperation) \ |
| 1343 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1344 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1345 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1346 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1347 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1348 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1349 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1350 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1351 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1352 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1353 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1354 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1355 | M(Return, Instruction) \ |
| 1356 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1357 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1358 | M(Shl, BinaryOperation) \ |
| 1359 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1360 | M(StaticFieldGet, Instruction) \ |
| 1361 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1362 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1363 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1364 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1365 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1366 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1367 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1368 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1369 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1370 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1371 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1372 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1373 | M(Xor, BinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1374 | M(VecReplicateScalar, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1375 | M(VecSumReduce, VecUnaryOperation) \ |
| 1376 | M(VecCnv, VecUnaryOperation) \ |
| 1377 | M(VecNeg, VecUnaryOperation) \ |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1378 | M(VecAbs, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1379 | M(VecNot, VecUnaryOperation) \ |
| 1380 | M(VecAdd, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1381 | M(VecHalvingAdd, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1382 | M(VecSub, VecBinaryOperation) \ |
| 1383 | M(VecMul, VecBinaryOperation) \ |
| 1384 | M(VecDiv, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1385 | M(VecMin, VecBinaryOperation) \ |
| 1386 | M(VecMax, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1387 | M(VecAnd, VecBinaryOperation) \ |
| 1388 | M(VecAndNot, VecBinaryOperation) \ |
| 1389 | M(VecOr, VecBinaryOperation) \ |
| 1390 | M(VecXor, VecBinaryOperation) \ |
| 1391 | M(VecShl, VecBinaryOperation) \ |
| 1392 | M(VecShr, VecBinaryOperation) \ |
| 1393 | M(VecUShr, VecBinaryOperation) \ |
Aart Bik | 8de5916 | 2017-04-21 09:42:01 -0700 | [diff] [blame] | 1394 | M(VecSetScalars, VecOperation) \ |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1395 | M(VecMultiplyAccumulate, VecOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1396 | M(VecLoad, VecMemoryOperation) \ |
| 1397 | M(VecStore, VecMemoryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1398 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1399 | /* |
| 1400 | * Instructions, shared across several (not all) architectures. |
| 1401 | */ |
| 1402 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1403 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1404 | #else |
| 1405 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1406 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1407 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1408 | M(MultiplyAccumulate, Instruction) \ |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 1409 | M(IntermediateAddress, Instruction) \ |
| 1410 | M(IntermediateAddressIndex, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1411 | #endif |
| 1412 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1413 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1414 | |
| 1415 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1416 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1417 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1418 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1419 | #else |
| 1420 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1421 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1422 | M(MipsPackedSwitch, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1423 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1424 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1425 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1426 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1427 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1428 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1429 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1430 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1431 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1432 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1433 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1434 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1435 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1436 | |
| 1437 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1438 | |
| 1439 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1440 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1441 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1442 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1443 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1444 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1445 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1446 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1447 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1448 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1449 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1450 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1451 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1452 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1453 | M(BinaryOperation, Instruction) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1454 | M(Invoke, Instruction) \ |
| 1455 | M(VecOperation, Instruction) \ |
| 1456 | M(VecUnaryOperation, VecOperation) \ |
| 1457 | M(VecBinaryOperation, VecOperation) \ |
| 1458 | M(VecMemoryOperation, VecOperation) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1459 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1460 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1461 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1462 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1463 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1464 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1465 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1466 | #undef FORWARD_DECLARATION |
| 1467 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1468 | #define DECLARE_INSTRUCTION(type) \ |
| 1469 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1470 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1471 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1472 | return other->Is##type(); \ |
| 1473 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1474 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1475 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1476 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1477 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1478 | const H##type* As##type() const { return this; } \ |
| 1479 | H##type* As##type() { return this; } |
| 1480 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1481 | template <typename T> |
Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 1482 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode>, |
| 1483 | public IntrusiveForwardListNode<HUseListNode<T>> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1484 | public: |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1485 | // Get the instruction which has this use as one of the inputs. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1486 | T GetUser() const { return user_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1487 | // Get the position of the input record that this use corresponds to. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1488 | size_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1489 | // Set the position of the input record that this use corresponds to. |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1490 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1491 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1492 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1493 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1494 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1495 | |
| 1496 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1497 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1498 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1499 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1500 | |
| 1501 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1502 | }; |
| 1503 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1504 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1505 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1506 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1507 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1508 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1509 | // by the used instructions. |
| 1510 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1511 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1512 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1513 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1514 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1515 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1516 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1517 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1518 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1519 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1520 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1524 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1525 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1526 | |
| 1527 | private: |
| 1528 | // Instruction used by the user. |
| 1529 | HInstruction* instruction_; |
| 1530 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1531 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1532 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1533 | }; |
| 1534 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1535 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1536 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1537 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1538 | struct HInputExtractor { |
| 1539 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1540 | return record.GetInstruction(); |
| 1541 | } |
| 1542 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1543 | return record.GetInstruction(); |
| 1544 | } |
| 1545 | }; |
| 1546 | |
| 1547 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1548 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1549 | |
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 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1552 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1553 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1554 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1555 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1556 | * modify the value of a reference field read [although it may modify the |
| 1557 | * reference fetch prior to reading the field, which is represented by its own |
| 1558 | * write/read dependence]). The analysis makes conservative points-to |
| 1559 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1560 | * the same, and any reference read depends on any reference read without |
| 1561 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1562 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1563 | * The internal representation uses 38-bit and is described in the table below. |
| 1564 | * The first line indicates the side effect, and for field/array accesses the |
| 1565 | * second line indicates the type of the access (in the order of the |
| 1566 | * Primitive::Type enum). |
| 1567 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1568 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1569 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1570 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1571 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1572 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1573 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1574 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1575 | * |
| 1576 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1577 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1578 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1579 | class SideEffects : public ValueObject { |
| 1580 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1581 | SideEffects() : flags_(0) {} |
| 1582 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1583 | static SideEffects None() { |
| 1584 | return SideEffects(0); |
| 1585 | } |
| 1586 | |
| 1587 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1588 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1589 | } |
| 1590 | |
| 1591 | static SideEffects AllChanges() { |
| 1592 | return SideEffects(kAllChangeBits); |
| 1593 | } |
| 1594 | |
| 1595 | static SideEffects AllDependencies() { |
| 1596 | return SideEffects(kAllDependOnBits); |
| 1597 | } |
| 1598 | |
| 1599 | static SideEffects AllExceptGCDependency() { |
| 1600 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1601 | } |
| 1602 | |
| 1603 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1604 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1605 | } |
| 1606 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1607 | static SideEffects AllWrites() { |
| 1608 | return SideEffects(kAllWrites); |
| 1609 | } |
| 1610 | |
| 1611 | static SideEffects AllReads() { |
| 1612 | return SideEffects(kAllReads); |
| 1613 | } |
| 1614 | |
| 1615 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1616 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1617 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1618 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1621 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1622 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1623 | } |
| 1624 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1625 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1626 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1627 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1628 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1632 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1635 | static SideEffects CanTriggerGC() { |
| 1636 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1637 | } |
| 1638 | |
| 1639 | static SideEffects DependsOnGC() { |
| 1640 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1641 | } |
| 1642 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1643 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1644 | SideEffects Union(SideEffects other) const { |
| 1645 | return SideEffects(flags_ | other.flags_); |
| 1646 | } |
| 1647 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1648 | SideEffects Exclusion(SideEffects other) const { |
| 1649 | return SideEffects(flags_ & ~other.flags_); |
| 1650 | } |
| 1651 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1652 | void Add(SideEffects other) { |
| 1653 | flags_ |= other.flags_; |
| 1654 | } |
| 1655 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1656 | bool Includes(SideEffects other) const { |
| 1657 | return (other.flags_ & flags_) == other.flags_; |
| 1658 | } |
| 1659 | |
| 1660 | bool HasSideEffects() const { |
| 1661 | return (flags_ & kAllChangeBits); |
| 1662 | } |
| 1663 | |
| 1664 | bool HasDependencies() const { |
| 1665 | return (flags_ & kAllDependOnBits); |
| 1666 | } |
| 1667 | |
| 1668 | // Returns true if there are no side effects or dependencies. |
| 1669 | bool DoesNothing() const { |
| 1670 | return flags_ == 0; |
| 1671 | } |
| 1672 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1673 | // Returns true if something is written. |
| 1674 | bool DoesAnyWrite() const { |
| 1675 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1676 | } |
| 1677 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1678 | // Returns true if something is read. |
| 1679 | bool DoesAnyRead() const { |
| 1680 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1681 | } |
| 1682 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1683 | // Returns true if potentially everything is written and read |
| 1684 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1685 | bool DoesAllReadWrite() const { |
| 1686 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1687 | } |
| 1688 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1689 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1690 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1693 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1694 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1695 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1696 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1700 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1701 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1702 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1703 | for (int s = kLastBit; s >= 0; s--) { |
| 1704 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1705 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1706 | // This is a bit for the GC side effect. |
| 1707 | if (current_bit_is_set) { |
| 1708 | flags += "GC"; |
| 1709 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1710 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1711 | } else { |
| 1712 | // This is a bit for the array/field analysis. |
| 1713 | // The underscore character stands for the 'can trigger GC' bit. |
| 1714 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1715 | if (current_bit_is_set) { |
| 1716 | flags += kDebug[s]; |
| 1717 | } |
| 1718 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1719 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1720 | flags += "|"; |
| 1721 | } |
| 1722 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1723 | } |
| 1724 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1725 | } |
| 1726 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1727 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1728 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1729 | private: |
| 1730 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1731 | |
| 1732 | static constexpr int kFieldWriteOffset = 0; |
| 1733 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1734 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1735 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1736 | |
| 1737 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1738 | |
| 1739 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1740 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1741 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1742 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1743 | |
| 1744 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1745 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1746 | |
| 1747 | // Aliases. |
| 1748 | |
| 1749 | static_assert(kChangeBits == kDependOnBits, |
| 1750 | "the 'change' bits should match the 'depend on' bits."); |
| 1751 | |
| 1752 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1753 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1754 | static constexpr uint64_t kAllWrites = |
| 1755 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1756 | static constexpr uint64_t kAllReads = |
| 1757 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1758 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1759 | // Translates type to bit flag. |
| 1760 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1761 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1762 | const uint64_t one = 1; |
| 1763 | const int shift = type; // 0-based consecutive enum |
| 1764 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1765 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1766 | return one << (type + offset); |
| 1767 | } |
| 1768 | |
| 1769 | // Private constructor on direct flags value. |
| 1770 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1771 | |
| 1772 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1773 | }; |
| 1774 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1775 | // 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] | 1776 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1777 | public: |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1778 | ALWAYS_INLINE HEnvironment(ArenaAllocator* arena, |
| 1779 | size_t number_of_vregs, |
| 1780 | ArtMethod* method, |
| 1781 | uint32_t dex_pc, |
| 1782 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1783 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 1784 | locations_(arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1785 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1786 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1787 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1788 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1789 | } |
| 1790 | |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1791 | ALWAYS_INLINE HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1792 | : HEnvironment(arena, |
| 1793 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1794 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1795 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1796 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1797 | |
Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 1798 | void AllocateLocations() { |
| 1799 | DCHECK(locations_.empty()); |
| 1800 | locations_.resize(vregs_.size()); |
| 1801 | } |
| 1802 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1803 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1804 | if (parent_ != nullptr) { |
| 1805 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1806 | } else { |
| 1807 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1808 | parent_->CopyFrom(parent); |
| 1809 | if (parent->GetParent() != nullptr) { |
| 1810 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1811 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1812 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1813 | } |
| 1814 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1815 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1816 | void CopyFrom(HEnvironment* environment); |
| 1817 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1818 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1819 | // input to the loop phi instead. This is for inserting instructions that |
| 1820 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1821 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1822 | |
| 1823 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1824 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1828 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1831 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1832 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1833 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1834 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1835 | HEnvironment* GetParent() const { return parent_; } |
| 1836 | |
| 1837 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1838 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1842 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | uint32_t GetDexPc() const { |
| 1846 | return dex_pc_; |
| 1847 | } |
| 1848 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1849 | ArtMethod* GetMethod() const { |
| 1850 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1851 | } |
| 1852 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1853 | HInstruction* GetHolder() const { |
| 1854 | return holder_; |
| 1855 | } |
| 1856 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1857 | |
| 1858 | bool IsFromInlinedInvoke() const { |
| 1859 | return GetParent() != nullptr; |
| 1860 | } |
| 1861 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1862 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1863 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1864 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1865 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1866 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1867 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1868 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1869 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1870 | HInstruction* const holder_; |
| 1871 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1872 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1873 | |
| 1874 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1875 | }; |
| 1876 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1877 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1878 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1879 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1880 | : previous_(nullptr), |
| 1881 | next_(nullptr), |
| 1882 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1883 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1884 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1885 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1886 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1887 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1888 | locations_(nullptr), |
| 1889 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1890 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1891 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1892 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1893 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1894 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1895 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1896 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1897 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1898 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1899 | enum InstructionKind { |
| 1900 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1901 | }; |
| 1902 | #undef DECLARE_KIND |
| 1903 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1904 | HInstruction* GetNext() const { return next_; } |
| 1905 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1906 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1907 | HInstruction* GetNextDisregardingMoves() const; |
| 1908 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1909 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1910 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1911 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1912 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1913 | bool IsInBlock() const { return block_ != nullptr; } |
| 1914 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1915 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1916 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1917 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1918 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1919 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1920 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1921 | |
| 1922 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1923 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1924 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1925 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1926 | } |
| 1927 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1928 | HInputsRef GetInputs() { |
| 1929 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1930 | } |
| 1931 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1932 | HConstInputsRef GetInputs() const { |
| 1933 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1937 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1938 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 1939 | bool HasInput(HInstruction* input) const { |
| 1940 | for (const HInstruction* i : GetInputs()) { |
| 1941 | if (i == input) { |
| 1942 | return true; |
| 1943 | } |
| 1944 | } |
| 1945 | return false; |
| 1946 | } |
| 1947 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1948 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1949 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1950 | } |
| 1951 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1952 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1953 | virtual const char* DebugName() const = 0; |
| 1954 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1955 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1956 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1957 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1958 | |
| 1959 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1960 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1961 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1962 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 1963 | // Can the instruction throw? |
| 1964 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 1965 | // 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] | 1966 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1967 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1968 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1969 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1970 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1971 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1972 | // Does not apply for all instructions, but having this at top level greatly |
| 1973 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1974 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1975 | virtual bool CanBeNull() const { |
| 1976 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1977 | return true; |
| 1978 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1979 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1980 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1981 | return false; |
| 1982 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1983 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1984 | virtual bool IsActualObject() const { |
| 1985 | return GetType() == Primitive::kPrimNot; |
| 1986 | } |
| 1987 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1988 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1989 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1990 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1991 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1992 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1993 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1994 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1995 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1996 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1997 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1998 | // Note: fixup_end remains valid across push_front(). |
| 1999 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 2000 | HUseListNode<HInstruction*>* new_node = |
| 2001 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 2002 | uses_.push_front(*new_node); |
| 2003 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2006 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2007 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2008 | // Note: env_fixup_end remains valid across push_front(). |
| 2009 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2010 | HUseListNode<HEnvironment*>* new_node = |
| 2011 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 2012 | env_uses_.push_front(*new_node); |
| 2013 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2014 | } |
| 2015 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2016 | void RemoveAsUserOfInput(size_t input) { |
| 2017 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 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); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2021 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2022 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2023 | void RemoveAsUserOfAllInputs() { |
| 2024 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2025 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2026 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2027 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2028 | } |
| 2029 | } |
| 2030 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2031 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2032 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2033 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2034 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2035 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2036 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2037 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2038 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2039 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2040 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2041 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2042 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2043 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2044 | !CanThrow() && |
| 2045 | !IsSuspendCheck() && |
| 2046 | !IsControlFlow() && |
| 2047 | !IsNativeDebugInfo() && |
| 2048 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2049 | // If we added an explicit barrier then we should keep it. |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2050 | !IsMemoryBarrier() && |
| 2051 | !IsConstructorFence(); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2054 | bool IsDeadAndRemovable() const { |
| 2055 | return IsRemovable() && !HasUses(); |
| 2056 | } |
| 2057 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2058 | // Does this instruction strictly dominate `other_instruction`? |
| 2059 | // Returns false if this instruction and `other_instruction` are the same. |
| 2060 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2061 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2062 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2063 | int GetId() const { return id_; } |
| 2064 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2065 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2066 | int GetSsaIndex() const { return ssa_index_; } |
| 2067 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2068 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2069 | |
| 2070 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2071 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2072 | // Set the `environment_` field. Raw because this method does not |
| 2073 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2074 | void SetRawEnvironment(HEnvironment* environment) { |
| 2075 | DCHECK(environment_ == nullptr); |
| 2076 | DCHECK_EQ(environment->GetHolder(), this); |
| 2077 | environment_ = environment; |
| 2078 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2079 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2080 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2081 | DCHECK(environment_ != nullptr); |
| 2082 | DCHECK_EQ(environment->GetHolder(), this); |
| 2083 | DCHECK(environment->GetParent() == nullptr); |
| 2084 | environment->parent_ = environment_; |
| 2085 | environment_ = environment; |
| 2086 | } |
| 2087 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2088 | void RemoveEnvironment(); |
| 2089 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2090 | // Set the environment of this instruction, copying it from `environment`. While |
| 2091 | // copying, the uses lists are being updated. |
| 2092 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2093 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2094 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2095 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2096 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2097 | if (environment->GetParent() != nullptr) { |
| 2098 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2099 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2100 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2101 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2102 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2103 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2104 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2105 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2106 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2107 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2108 | if (environment->GetParent() != nullptr) { |
| 2109 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2110 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2113 | // Returns the number of entries in the environment. Typically, that is the |
| 2114 | // number of dex registers in a method. It could be more in case of inlining. |
| 2115 | size_t EnvironmentSize() const; |
| 2116 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2117 | LocationSummary* GetLocations() const { return locations_; } |
| 2118 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2119 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2120 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2121 | void ReplaceUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2122 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2123 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2124 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2125 | // uses of this instruction by `other` are *not* updated. |
| 2126 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2127 | ReplaceWith(other); |
| 2128 | other->ReplaceInput(this, use_index); |
| 2129 | } |
| 2130 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2131 | // Move `this` instruction before `cursor` |
| 2132 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2133 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2134 | // Move `this` before its first user and out of any loops. If there is no |
| 2135 | // out-of-loop user that dominates all other users, move the instruction |
| 2136 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2137 | // |
| 2138 | // This can be used only on non-throwing instructions with no side effects that |
| 2139 | // have at least one use but no environment uses. |
| 2140 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2141 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2142 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2143 | bool Is##type() const; \ |
| 2144 | const H##type* As##type() const; \ |
| 2145 | H##type* As##type(); |
| 2146 | |
| 2147 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2148 | #undef INSTRUCTION_TYPE_CHECK |
| 2149 | |
| 2150 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2151 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2152 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2153 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2154 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2155 | #undef INSTRUCTION_TYPE_CHECK |
| 2156 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2157 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2158 | // TODO: this method is used by LICM and GVN with possibly different |
| 2159 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2160 | virtual bool CanBeMoved() const { return false; } |
| 2161 | |
| 2162 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2163 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2164 | return false; |
| 2165 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2166 | |
| 2167 | // Returns whether any data encoded in the two instructions is equal. |
| 2168 | // This method does not look at the inputs. Both instructions must be |
| 2169 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2170 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2171 | return false; |
| 2172 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2173 | |
| 2174 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2175 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2176 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2177 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2178 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2179 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2180 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2181 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2182 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2183 | InstructionKind GetKind() const PURE; |
| 2184 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2185 | |
| 2186 | virtual size_t ComputeHashCode() const { |
| 2187 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2188 | for (const HInstruction* input : GetInputs()) { |
| 2189 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2190 | } |
| 2191 | return result; |
| 2192 | } |
| 2193 | |
| 2194 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2195 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2196 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2197 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2198 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2199 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2200 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2201 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2202 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2203 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2204 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2205 | |
| 2206 | // Returns whether the code generation of the instruction will require to have access |
| 2207 | // to the current method. Such instructions are: |
| 2208 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2209 | // 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] | 2210 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2211 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2212 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2213 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2214 | } |
| 2215 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2216 | // Returns whether the code generation of the instruction will require to have access |
| 2217 | // to the dex cache of the current method's declaring class via the current method. |
| 2218 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2219 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2220 | // Does this instruction have any use in an environment before |
| 2221 | // control flow hits 'other'? |
| 2222 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2223 | |
| 2224 | // Remove all references to environment uses of this instruction. |
| 2225 | // The caller must ensure that this is safe to do. |
| 2226 | void RemoveEnvironmentUsers(); |
| 2227 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2228 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2229 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2230 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2231 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2232 | // If set, the machine code for this instruction is assumed to be generated by |
| 2233 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2234 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2235 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2236 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2237 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2238 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2239 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2240 | return GetInputRecords()[i]; |
| 2241 | } |
| 2242 | |
| 2243 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2244 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2245 | input_records[index] = input; |
| 2246 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2247 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2248 | uint32_t GetPackedFields() const { |
| 2249 | return packed_fields_; |
| 2250 | } |
| 2251 | |
| 2252 | template <size_t flag> |
| 2253 | bool GetPackedFlag() const { |
| 2254 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2255 | } |
| 2256 | |
| 2257 | template <size_t flag> |
| 2258 | void SetPackedFlag(bool value = true) { |
| 2259 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2260 | } |
| 2261 | |
| 2262 | template <typename BitFieldType> |
| 2263 | typename BitFieldType::value_type GetPackedField() const { |
| 2264 | return BitFieldType::Decode(packed_fields_); |
| 2265 | } |
| 2266 | |
| 2267 | template <typename BitFieldType> |
| 2268 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2269 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2270 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2271 | } |
| 2272 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2273 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2274 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2275 | auto before_use_node = uses_.before_begin(); |
| 2276 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2277 | HInstruction* user = use_node->GetUser(); |
| 2278 | size_t input_index = use_node->GetIndex(); |
| 2279 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2280 | before_use_node = use_node; |
| 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2285 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2286 | if (next != uses_.end()) { |
| 2287 | HInstruction* next_user = next->GetUser(); |
| 2288 | size_t next_index = next->GetIndex(); |
| 2289 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2290 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2295 | auto before_env_use_node = env_uses_.before_begin(); |
| 2296 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2297 | HEnvironment* user = env_use_node->GetUser(); |
| 2298 | size_t input_index = env_use_node->GetIndex(); |
| 2299 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2300 | before_env_use_node = env_use_node; |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2305 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2306 | if (next != env_uses_.end()) { |
| 2307 | HEnvironment* next_user = next->GetUser(); |
| 2308 | size_t next_index = next->GetIndex(); |
| 2309 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2310 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2311 | } |
| 2312 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2313 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2314 | HInstruction* previous_; |
| 2315 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2316 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2317 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2318 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2319 | // An instruction gets an id when it is added to the graph. |
| 2320 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2321 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2322 | int id_; |
| 2323 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2324 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2325 | int ssa_index_; |
| 2326 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2327 | // Packed fields. |
| 2328 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2329 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2330 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2331 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2332 | |
| 2333 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2334 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2335 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2336 | // The environment associated with this instruction. Not null if the instruction |
| 2337 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2338 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2339 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2340 | // Set by the code generator. |
| 2341 | LocationSummary* locations_; |
| 2342 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2343 | // Set by the liveness analysis. |
| 2344 | LiveInterval* live_interval_; |
| 2345 | |
| 2346 | // Set by the liveness analysis, this is the position in a linear |
| 2347 | // order of blocks where this instruction's live interval start. |
| 2348 | size_t lifetime_position_; |
| 2349 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2350 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2351 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2352 | // The reference handle part of the reference type info. |
| 2353 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2354 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2355 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2356 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2357 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2358 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2359 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2360 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2361 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2362 | |
| 2363 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2364 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2365 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2366 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2367 | // Iterates over the instructions, while preserving the next instruction |
| 2368 | // in case the current instruction gets removed from the list by the user |
| 2369 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2370 | class HInstructionIterator : public ValueObject { |
| 2371 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2372 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2373 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2374 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2377 | bool Done() const { return instruction_ == nullptr; } |
| 2378 | HInstruction* Current() const { return instruction_; } |
| 2379 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2380 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2381 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | private: |
| 2385 | HInstruction* instruction_; |
| 2386 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2387 | |
| 2388 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2389 | }; |
| 2390 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2391 | // Iterates over the instructions without saving the next instruction, |
| 2392 | // therefore handling changes in the graph potentially made by the user |
| 2393 | // of this iterator. |
| 2394 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2395 | public: |
| 2396 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2397 | : instruction_(instructions.first_instruction_) { |
| 2398 | } |
| 2399 | |
| 2400 | bool Done() const { return instruction_ == nullptr; } |
| 2401 | HInstruction* Current() const { return instruction_; } |
| 2402 | void Advance() { |
| 2403 | instruction_ = instruction_->GetNext(); |
| 2404 | } |
| 2405 | |
| 2406 | private: |
| 2407 | HInstruction* instruction_; |
| 2408 | |
| 2409 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2410 | }; |
| 2411 | |
| 2412 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2413 | class HBackwardInstructionIterator : public ValueObject { |
| 2414 | public: |
| 2415 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2416 | : instruction_(instructions.last_instruction_) { |
| 2417 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2418 | } |
| 2419 | |
| 2420 | bool Done() const { return instruction_ == nullptr; } |
| 2421 | HInstruction* Current() const { return instruction_; } |
| 2422 | void Advance() { |
| 2423 | instruction_ = next_; |
| 2424 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2425 | } |
| 2426 | |
| 2427 | private: |
| 2428 | HInstruction* instruction_; |
| 2429 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2430 | |
| 2431 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2432 | }; |
| 2433 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2434 | class HVariableInputSizeInstruction : public HInstruction { |
| 2435 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2436 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2437 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 2438 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2439 | } |
| 2440 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2441 | void AddInput(HInstruction* input); |
| 2442 | void InsertInputAt(size_t index, HInstruction* input); |
| 2443 | void RemoveInputAt(size_t index); |
| 2444 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2445 | // Removes all the inputs. |
| 2446 | // Also removes this instructions from each input's use list |
| 2447 | // (for non-environment uses only). |
| 2448 | void RemoveAllInputs(); |
| 2449 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2450 | protected: |
| 2451 | HVariableInputSizeInstruction(SideEffects side_effects, |
| 2452 | uint32_t dex_pc, |
| 2453 | ArenaAllocator* arena, |
| 2454 | size_t number_of_inputs, |
| 2455 | ArenaAllocKind kind) |
| 2456 | : HInstruction(side_effects, dex_pc), |
| 2457 | inputs_(number_of_inputs, arena->Adapter(kind)) {} |
| 2458 | |
| 2459 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
| 2460 | |
| 2461 | private: |
| 2462 | DISALLOW_COPY_AND_ASSIGN(HVariableInputSizeInstruction); |
| 2463 | }; |
| 2464 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2465 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2466 | class HTemplateInstruction: public HInstruction { |
| 2467 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2468 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2469 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2470 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2471 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2472 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2473 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2474 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2477 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2478 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2479 | |
| 2480 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2481 | }; |
| 2482 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2483 | // HTemplateInstruction specialization for N=0. |
| 2484 | template<> |
| 2485 | class HTemplateInstruction<0>: public HInstruction { |
| 2486 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2487 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2488 | : HInstruction(side_effects, dex_pc) {} |
| 2489 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2490 | virtual ~HTemplateInstruction() {} |
| 2491 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2492 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2493 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2494 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | private: |
| 2498 | friend class SsaBuilder; |
| 2499 | }; |
| 2500 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2501 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2502 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2503 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2504 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2505 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2506 | this->template SetPackedField<TypeField>(type); |
| 2507 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2508 | virtual ~HExpression() {} |
| 2509 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2510 | Primitive::Type GetType() const OVERRIDE { |
| 2511 | return TypeField::Decode(this->GetPackedFields()); |
| 2512 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2513 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2514 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2515 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2516 | static constexpr size_t kFieldTypeSize = |
| 2517 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2518 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2519 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2520 | "Too many packed fields."); |
| 2521 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2522 | }; |
| 2523 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2524 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2525 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2526 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2527 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2528 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2529 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2530 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2531 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2532 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2533 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2534 | |
| 2535 | private: |
| 2536 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2537 | }; |
| 2538 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2539 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2540 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2541 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2542 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2543 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2544 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2545 | SetRawInputAt(0, value); |
| 2546 | } |
| 2547 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2548 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2549 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2550 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2551 | |
| 2552 | private: |
| 2553 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2554 | }; |
| 2555 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2556 | class HPhi FINAL : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2557 | public: |
| 2558 | HPhi(ArenaAllocator* arena, |
| 2559 | uint32_t reg_number, |
| 2560 | size_t number_of_inputs, |
| 2561 | Primitive::Type type, |
| 2562 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2563 | : HVariableInputSizeInstruction( |
| 2564 | SideEffects::None(), |
| 2565 | dex_pc, |
| 2566 | arena, |
| 2567 | number_of_inputs, |
| 2568 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2569 | reg_number_(reg_number) { |
| 2570 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2571 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2572 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2573 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2574 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2575 | SetPackedFlag<kFlagIsLive>(true); |
| 2576 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2577 | } |
| 2578 | |
| 2579 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2580 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2581 | return Primitive::PrimitiveKind(type); |
| 2582 | } |
| 2583 | |
| 2584 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2585 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2586 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2587 | void SetType(Primitive::Type new_type) { |
| 2588 | // Make sure that only valid type changes occur. The following are allowed: |
| 2589 | // (1) int -> float/ref (primitive type propagation), |
| 2590 | // (2) long -> double (primitive type propagation). |
| 2591 | DCHECK(GetType() == new_type || |
| 2592 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2593 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2594 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2595 | SetPackedField<TypeField>(new_type); |
| 2596 | } |
| 2597 | |
| 2598 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2599 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2600 | |
| 2601 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2602 | |
| 2603 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2604 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2605 | bool IsDead() const { return !IsLive(); } |
| 2606 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2607 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2608 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2609 | return other != nullptr |
| 2610 | && other->IsPhi() |
| 2611 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2612 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2613 | } |
| 2614 | |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 2615 | bool HasEquivalentPhi() const { |
| 2616 | if (GetPrevious() != nullptr && GetPrevious()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2617 | return true; |
| 2618 | } |
| 2619 | if (GetNext() != nullptr && GetNext()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2620 | return true; |
| 2621 | } |
| 2622 | return false; |
| 2623 | } |
| 2624 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2625 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2626 | // An equivalent phi is a phi having the same dex register and type. |
| 2627 | // It assumes that phis with the same dex register are adjacent. |
| 2628 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2629 | HInstruction* next = GetNext(); |
| 2630 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2631 | if (next->GetType() == GetType()) { |
| 2632 | return next->AsPhi(); |
| 2633 | } |
| 2634 | next = next->GetNext(); |
| 2635 | } |
| 2636 | return nullptr; |
| 2637 | } |
| 2638 | |
| 2639 | DECLARE_INSTRUCTION(Phi); |
| 2640 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2641 | private: |
| 2642 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2643 | static constexpr size_t kFieldTypeSize = |
| 2644 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2645 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2646 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2647 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2648 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2649 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2650 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2651 | const uint32_t reg_number_; |
| 2652 | |
| 2653 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2654 | }; |
| 2655 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2656 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2657 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2658 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2659 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2660 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2661 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2662 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2663 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2664 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2665 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2666 | |
| 2667 | private: |
| 2668 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2669 | }; |
| 2670 | |
| 2671 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2672 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2673 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2674 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2675 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2676 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2677 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2678 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2679 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2680 | } |
| 2681 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2682 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2683 | |
| 2684 | private: |
| 2685 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2686 | }; |
| 2687 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2688 | class HConstant : public HExpression<0> { |
| 2689 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2690 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2691 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2692 | |
| 2693 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2694 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2695 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2696 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2697 | // Is this constant 0 in the arithmetic sense? |
| 2698 | virtual bool IsArithmeticZero() const { return false; } |
| 2699 | // Is this constant a 0-bit pattern? |
| 2700 | virtual bool IsZeroBitPattern() const { return false; } |
| 2701 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2702 | virtual bool IsOne() const { return false; } |
| 2703 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2704 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2705 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2706 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2707 | |
| 2708 | private: |
| 2709 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2710 | }; |
| 2711 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2712 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2713 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2714 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2715 | return true; |
| 2716 | } |
| 2717 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2718 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2719 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2720 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2721 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2722 | // The null constant representation is a 0-bit pattern. |
| 2723 | virtual bool IsZeroBitPattern() const { return true; } |
| 2724 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2725 | DECLARE_INSTRUCTION(NullConstant); |
| 2726 | |
| 2727 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2728 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2729 | |
| 2730 | friend class HGraph; |
| 2731 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2732 | }; |
| 2733 | |
| 2734 | // Constants of the type int. Those can be from Dex instructions, or |
| 2735 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2736 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2737 | public: |
| 2738 | int32_t GetValue() const { return value_; } |
| 2739 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2740 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2741 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2742 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2743 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2744 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2745 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2746 | return other->AsIntConstant()->value_ == value_; |
| 2747 | } |
| 2748 | |
| 2749 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2750 | |
| 2751 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2752 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2753 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2754 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2755 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2756 | // Integer constants are used to encode Boolean values as well, |
| 2757 | // where 1 means true and 0 means false. |
| 2758 | bool IsTrue() const { return GetValue() == 1; } |
| 2759 | bool IsFalse() const { return GetValue() == 0; } |
| 2760 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2761 | DECLARE_INSTRUCTION(IntConstant); |
| 2762 | |
| 2763 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2764 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2765 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2766 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2767 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2768 | |
| 2769 | const int32_t value_; |
| 2770 | |
| 2771 | friend class HGraph; |
| 2772 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2773 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2774 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2775 | }; |
| 2776 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2777 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2778 | public: |
| 2779 | int64_t GetValue() const { return value_; } |
| 2780 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2781 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2782 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2783 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2784 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2785 | return other->AsLongConstant()->value_ == value_; |
| 2786 | } |
| 2787 | |
| 2788 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2789 | |
| 2790 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2791 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2792 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2793 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2794 | |
| 2795 | DECLARE_INSTRUCTION(LongConstant); |
| 2796 | |
| 2797 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2798 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2799 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2800 | |
| 2801 | const int64_t value_; |
| 2802 | |
| 2803 | friend class HGraph; |
| 2804 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2805 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2806 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2807 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2808 | public: |
| 2809 | float GetValue() const { return value_; } |
| 2810 | |
| 2811 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2812 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2813 | } |
| 2814 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2815 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2816 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2817 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2818 | } |
| 2819 | |
| 2820 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2821 | |
| 2822 | bool IsMinusOne() const OVERRIDE { |
| 2823 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2824 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2825 | bool IsArithmeticZero() const OVERRIDE { |
| 2826 | return std::fpclassify(value_) == FP_ZERO; |
| 2827 | } |
| 2828 | bool IsArithmeticPositiveZero() const { |
| 2829 | return IsArithmeticZero() && !std::signbit(value_); |
| 2830 | } |
| 2831 | bool IsArithmeticNegativeZero() const { |
| 2832 | return IsArithmeticZero() && std::signbit(value_); |
| 2833 | } |
| 2834 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2835 | 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] | 2836 | } |
| 2837 | bool IsOne() const OVERRIDE { |
| 2838 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2839 | } |
| 2840 | bool IsNaN() const { |
| 2841 | return std::isnan(value_); |
| 2842 | } |
| 2843 | |
| 2844 | DECLARE_INSTRUCTION(FloatConstant); |
| 2845 | |
| 2846 | private: |
| 2847 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2848 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2849 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2850 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2851 | |
| 2852 | const float value_; |
| 2853 | |
| 2854 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2855 | friend class SsaBuilder; |
| 2856 | friend class HGraph; |
| 2857 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2858 | }; |
| 2859 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2860 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2861 | public: |
| 2862 | double GetValue() const { return value_; } |
| 2863 | |
| 2864 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2865 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2866 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2867 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2868 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2869 | } |
| 2870 | |
| 2871 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2872 | |
| 2873 | bool IsMinusOne() const OVERRIDE { |
| 2874 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2875 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2876 | bool IsArithmeticZero() const OVERRIDE { |
| 2877 | return std::fpclassify(value_) == FP_ZERO; |
| 2878 | } |
| 2879 | bool IsArithmeticPositiveZero() const { |
| 2880 | return IsArithmeticZero() && !std::signbit(value_); |
| 2881 | } |
| 2882 | bool IsArithmeticNegativeZero() const { |
| 2883 | return IsArithmeticZero() && std::signbit(value_); |
| 2884 | } |
| 2885 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2886 | 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] | 2887 | } |
| 2888 | bool IsOne() const OVERRIDE { |
| 2889 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2890 | } |
| 2891 | bool IsNaN() const { |
| 2892 | return std::isnan(value_); |
| 2893 | } |
| 2894 | |
| 2895 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2896 | |
| 2897 | private: |
| 2898 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2899 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2900 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2901 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2902 | |
| 2903 | const double value_; |
| 2904 | |
| 2905 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2906 | friend class SsaBuilder; |
| 2907 | friend class HGraph; |
| 2908 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2909 | }; |
| 2910 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2911 | // Conditional branch. A block ending with an HIf instruction must have |
| 2912 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2913 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2914 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2915 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2916 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2917 | SetRawInputAt(0, input); |
| 2918 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2919 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2920 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2921 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2922 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2923 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2927 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2928 | } |
| 2929 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2930 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2931 | |
| 2932 | private: |
| 2933 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2934 | }; |
| 2935 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2936 | |
| 2937 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2938 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2939 | // non-exceptional control flow. |
| 2940 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2941 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2942 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2943 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2944 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2945 | kEntry, |
| 2946 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2947 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2948 | }; |
| 2949 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2950 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2951 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2952 | SetPackedField<BoundaryKindField>(kind); |
| 2953 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2954 | |
| 2955 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2956 | |
| 2957 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2958 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2959 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2960 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2961 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2962 | } |
| 2963 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2964 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2965 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2966 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2967 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2968 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | // If not present already, adds `handler` to its block's list of exception |
| 2972 | // handlers. |
| 2973 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2974 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2975 | GetBlock()->AddSuccessor(handler); |
| 2976 | } |
| 2977 | } |
| 2978 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2979 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2980 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2981 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2982 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2983 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2984 | DECLARE_INSTRUCTION(TryBoundary); |
| 2985 | |
| 2986 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2987 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2988 | static constexpr size_t kFieldBoundaryKindSize = |
| 2989 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2990 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2991 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2992 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2993 | "Too many packed fields."); |
| 2994 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2995 | |
| 2996 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2997 | }; |
| 2998 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2999 | // Deoptimize to interpreter, upon checking a condition. |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3000 | class HDeoptimize FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3001 | public: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3002 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 3003 | // across. |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3004 | HDeoptimize(ArenaAllocator* arena, HInstruction* cond, DeoptimizationKind kind, uint32_t dex_pc) |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3005 | : HVariableInputSizeInstruction( |
| 3006 | SideEffects::All(), |
| 3007 | dex_pc, |
| 3008 | arena, |
| 3009 | /* number_of_inputs */ 1, |
| 3010 | kArenaAllocMisc) { |
| 3011 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 3012 | SetPackedField<DeoptimizeKindField>(kind); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3013 | SetRawInputAt(0, cond); |
| 3014 | } |
| 3015 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3016 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3017 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3018 | // instead of `guard`. |
| 3019 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3020 | // at the point of the `HDeoptimize`. |
| 3021 | HDeoptimize(ArenaAllocator* arena, |
| 3022 | HInstruction* cond, |
| 3023 | HInstruction* guard, |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3024 | DeoptimizationKind kind, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3025 | uint32_t dex_pc) |
| 3026 | : HVariableInputSizeInstruction( |
| 3027 | SideEffects::CanTriggerGC(), |
| 3028 | dex_pc, |
| 3029 | arena, |
| 3030 | /* number_of_inputs */ 2, |
| 3031 | kArenaAllocMisc) { |
| 3032 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3033 | SetPackedField<DeoptimizeKindField>(kind); |
| 3034 | SetRawInputAt(0, cond); |
| 3035 | SetRawInputAt(1, guard); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3036 | } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3037 | |
| 3038 | bool CanBeMoved() const OVERRIDE { return GetPackedFlag<kFieldCanBeMoved>(); } |
| 3039 | |
| 3040 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 3041 | return (other->CanBeMoved() == CanBeMoved()) && (other->AsDeoptimize()->GetKind() == GetKind()); |
| 3042 | } |
| 3043 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3044 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3045 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3046 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3047 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3048 | DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3049 | |
| 3050 | Primitive::Type GetType() const OVERRIDE { |
| 3051 | return GuardsAnInput() ? GuardedInput()->GetType() : Primitive::kPrimVoid; |
| 3052 | } |
| 3053 | |
| 3054 | bool GuardsAnInput() const { |
| 3055 | return InputCount() == 2; |
| 3056 | } |
| 3057 | |
| 3058 | HInstruction* GuardedInput() const { |
| 3059 | DCHECK(GuardsAnInput()); |
| 3060 | return InputAt(1); |
| 3061 | } |
| 3062 | |
| 3063 | void RemoveGuard() { |
| 3064 | RemoveInputAt(1); |
| 3065 | } |
| 3066 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3067 | DECLARE_INSTRUCTION(Deoptimize); |
| 3068 | |
| 3069 | private: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3070 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3071 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3072 | static constexpr size_t kFieldDeoptimizeKindSize = |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3073 | MinimumBitsToStore(static_cast<size_t>(DeoptimizationKind::kLast)); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3074 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3075 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3076 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3077 | "Too many packed fields."); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3078 | using DeoptimizeKindField = |
| 3079 | BitField<DeoptimizationKind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3080 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3081 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 3082 | }; |
| 3083 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3084 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3085 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3086 | // if it's true, starts to do deoptimization. |
| 3087 | // It has a 4-byte slot on stack. |
| 3088 | // TODO: allocate a register for this flag. |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3089 | class HShouldDeoptimizeFlag FINAL : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3090 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3091 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3092 | // with regard to other passes. |
| 3093 | HShouldDeoptimizeFlag(ArenaAllocator* arena, uint32_t dex_pc) |
| 3094 | : HVariableInputSizeInstruction(SideEffects::None(), dex_pc, arena, 0, kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3095 | } |
| 3096 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3097 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimInt; } |
| 3098 | |
| 3099 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3100 | // further guard elimination/motion since a guard might have been used for justification |
| 3101 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3102 | // to avoid other optimizations trying to move it. |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3103 | bool CanBeMoved() const OVERRIDE { return false; } |
| 3104 | |
| 3105 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3106 | |
| 3107 | private: |
| 3108 | DISALLOW_COPY_AND_ASSIGN(HShouldDeoptimizeFlag); |
| 3109 | }; |
| 3110 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3111 | // Represents the ArtMethod that was passed as a first argument to |
| 3112 | // the method. It is used by instructions that depend on it, like |
| 3113 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3114 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3115 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3116 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3117 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3118 | |
| 3119 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3120 | |
| 3121 | private: |
| 3122 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 3123 | }; |
| 3124 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3125 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3126 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3127 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3128 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3129 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3130 | kVTable, |
| 3131 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3132 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3133 | }; |
| 3134 | HClassTableGet(HInstruction* cls, |
| 3135 | Primitive::Type type, |
| 3136 | TableKind kind, |
| 3137 | size_t index, |
| 3138 | uint32_t dex_pc) |
| 3139 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3140 | index_(index) { |
| 3141 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3142 | SetRawInputAt(0, cls); |
| 3143 | } |
| 3144 | |
| 3145 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3146 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3147 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3148 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3149 | } |
| 3150 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3151 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3152 | size_t GetIndex() const { return index_; } |
| 3153 | |
| 3154 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3155 | |
| 3156 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3157 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 3158 | static constexpr size_t kFieldTableKindSize = |
| 3159 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3160 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3161 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3162 | "Too many packed fields."); |
| 3163 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3164 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3165 | // The index of the ArtMethod in the table. |
| 3166 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3167 | |
| 3168 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 3169 | }; |
| 3170 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3171 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3172 | // have one successor for each entry in the switch table, and the final successor |
| 3173 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3174 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3175 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3176 | HPackedSwitch(int32_t start_value, |
| 3177 | uint32_t num_entries, |
| 3178 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3179 | uint32_t dex_pc = kNoDexPc) |
| 3180 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 3181 | start_value_(start_value), |
| 3182 | num_entries_(num_entries) { |
| 3183 | SetRawInputAt(0, input); |
| 3184 | } |
| 3185 | |
| 3186 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3187 | |
| 3188 | int32_t GetStartValue() const { return start_value_; } |
| 3189 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3190 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3191 | |
| 3192 | HBasicBlock* GetDefaultBlock() const { |
| 3193 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3194 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3195 | } |
| 3196 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3197 | |
| 3198 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3199 | const int32_t start_value_; |
| 3200 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3201 | |
| 3202 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 3203 | }; |
| 3204 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3205 | class HUnaryOperation : public HExpression<1> { |
| 3206 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3207 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3208 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3209 | SetRawInputAt(0, input); |
| 3210 | } |
| 3211 | |
| 3212 | HInstruction* GetInput() const { return InputAt(0); } |
| 3213 | Primitive::Type GetResultType() const { return GetType(); } |
| 3214 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3215 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3216 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3217 | return true; |
| 3218 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3219 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3220 | // Try to statically evaluate `this` and return a HConstant |
| 3221 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3222 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3223 | HConstant* TryStaticEvaluation() const; |
| 3224 | |
| 3225 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3226 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3227 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3228 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3229 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3230 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3231 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3232 | |
| 3233 | private: |
| 3234 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 3235 | }; |
| 3236 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3237 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3238 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3239 | HBinaryOperation(Primitive::Type result_type, |
| 3240 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3241 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3242 | SideEffects side_effects = SideEffects::None(), |
| 3243 | uint32_t dex_pc = kNoDexPc) |
| 3244 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3245 | SetRawInputAt(0, left); |
| 3246 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3247 | } |
| 3248 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3249 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3250 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3251 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3252 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3253 | virtual bool IsCommutative() const { return false; } |
| 3254 | |
| 3255 | // Put constant on the right. |
| 3256 | // Returns whether order is changed. |
| 3257 | bool OrderInputsWithConstantOnTheRight() { |
| 3258 | HInstruction* left = InputAt(0); |
| 3259 | HInstruction* right = InputAt(1); |
| 3260 | if (left->IsConstant() && !right->IsConstant()) { |
| 3261 | ReplaceInput(right, 0); |
| 3262 | ReplaceInput(left, 1); |
| 3263 | return true; |
| 3264 | } |
| 3265 | return false; |
| 3266 | } |
| 3267 | |
| 3268 | // Order inputs by instruction id, but favor constant on the right side. |
| 3269 | // This helps GVN for commutative ops. |
| 3270 | void OrderInputs() { |
| 3271 | DCHECK(IsCommutative()); |
| 3272 | HInstruction* left = InputAt(0); |
| 3273 | HInstruction* right = InputAt(1); |
| 3274 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3275 | return; |
| 3276 | } |
| 3277 | if (OrderInputsWithConstantOnTheRight()) { |
| 3278 | return; |
| 3279 | } |
| 3280 | // Order according to instruction id. |
| 3281 | if (left->GetId() > right->GetId()) { |
| 3282 | ReplaceInput(right, 0); |
| 3283 | ReplaceInput(left, 1); |
| 3284 | } |
| 3285 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3286 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3287 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3288 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3289 | return true; |
| 3290 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3291 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3292 | // Try to statically evaluate `this` and return a HConstant |
| 3293 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3294 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3295 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3296 | |
| 3297 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3298 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3299 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3300 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3301 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3302 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3303 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3304 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3305 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3306 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3307 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3308 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3309 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3310 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3311 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3312 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3313 | // 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] | 3314 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3315 | HConstant* GetConstantRight() const; |
| 3316 | |
| 3317 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3318 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3319 | HInstruction* GetLeastConstantLeft() const; |
| 3320 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3321 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3322 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3323 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3324 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3325 | }; |
| 3326 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3327 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3328 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3329 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3330 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3331 | kGtBias, // return 1 for NaN comparisons |
| 3332 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3333 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3334 | }; |
| 3335 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3336 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3337 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3338 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3339 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3340 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3341 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3342 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3343 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3344 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3345 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3346 | // `instruction`, and disregard moves in between. |
| 3347 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3348 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3349 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3350 | |
| 3351 | virtual IfCondition GetCondition() const = 0; |
| 3352 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3353 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3354 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3355 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3356 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3357 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3358 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3359 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3360 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3361 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3362 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3363 | } |
| 3364 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3365 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3366 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3367 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3368 | if (if_cond == kCondNE) { |
| 3369 | return true; |
| 3370 | } else if (if_cond == kCondEQ) { |
| 3371 | return false; |
| 3372 | } |
| 3373 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3377 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3378 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3379 | if (if_cond == kCondEQ) { |
| 3380 | return true; |
| 3381 | } else if (if_cond == kCondNE) { |
| 3382 | return false; |
| 3383 | } |
| 3384 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3385 | } |
| 3386 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3387 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3388 | // Needed if we merge a HCompare into a HCondition. |
| 3389 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3390 | static constexpr size_t kFieldComparisonBiasSize = |
| 3391 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3392 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3393 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3394 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3395 | using ComparisonBiasField = |
| 3396 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3397 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3398 | template <typename T> |
| 3399 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3400 | |
| 3401 | template <typename T> |
| 3402 | int32_t CompareFP(T x, T y) const { |
| 3403 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3404 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3405 | // Handle the bias. |
| 3406 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3407 | } |
| 3408 | |
| 3409 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3410 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3411 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3412 | } |
| 3413 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3414 | private: |
| 3415 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3416 | }; |
| 3417 | |
| 3418 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3419 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3420 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3421 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3422 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3423 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3424 | bool IsCommutative() const OVERRIDE { return true; } |
| 3425 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3426 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3427 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3428 | return MakeConstantCondition(true, GetDexPc()); |
| 3429 | } |
| 3430 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3431 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3432 | } |
| 3433 | // In the following Evaluate methods, a HCompare instruction has |
| 3434 | // been merged into this HEqual instruction; evaluate it as |
| 3435 | // `Compare(x, y) == 0`. |
| 3436 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3437 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3438 | GetDexPc()); |
| 3439 | } |
| 3440 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3441 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3442 | } |
| 3443 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3444 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3445 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3446 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3447 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3448 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3449 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3450 | return kCondEQ; |
| 3451 | } |
| 3452 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3453 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3454 | return kCondNE; |
| 3455 | } |
| 3456 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3457 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3458 | template <typename T> static bool Compute(T x, T y) { return x == y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3459 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3460 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3461 | }; |
| 3462 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3463 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3464 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3465 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3466 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3467 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3468 | bool IsCommutative() const OVERRIDE { return true; } |
| 3469 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3470 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3471 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3472 | return MakeConstantCondition(false, GetDexPc()); |
| 3473 | } |
| 3474 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3475 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3476 | } |
| 3477 | // In the following Evaluate methods, a HCompare instruction has |
| 3478 | // been merged into this HNotEqual instruction; evaluate it as |
| 3479 | // `Compare(x, y) != 0`. |
| 3480 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3481 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3482 | } |
| 3483 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3484 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3485 | } |
| 3486 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3487 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3488 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3489 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3490 | DECLARE_INSTRUCTION(NotEqual); |
| 3491 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3492 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3493 | return kCondNE; |
| 3494 | } |
| 3495 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3496 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3497 | return kCondEQ; |
| 3498 | } |
| 3499 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3500 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3501 | 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] | 3502 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3503 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3504 | }; |
| 3505 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3506 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3507 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3508 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3509 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3510 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3511 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3512 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3513 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3514 | // In the following Evaluate methods, a HCompare instruction has |
| 3515 | // been merged into this HLessThan instruction; evaluate it as |
| 3516 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3517 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3518 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3519 | } |
| 3520 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3521 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3522 | } |
| 3523 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3524 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3525 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3526 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3527 | DECLARE_INSTRUCTION(LessThan); |
| 3528 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3529 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3530 | return kCondLT; |
| 3531 | } |
| 3532 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3533 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3534 | return kCondGE; |
| 3535 | } |
| 3536 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3537 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3538 | 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] | 3539 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3540 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3541 | }; |
| 3542 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3543 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3544 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3545 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3546 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3547 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3548 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3549 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3550 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3551 | // In the following Evaluate methods, a HCompare instruction has |
| 3552 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3553 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3554 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3555 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3556 | } |
| 3557 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3558 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3559 | } |
| 3560 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3561 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3562 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3563 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3564 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3565 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3566 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3567 | return kCondLE; |
| 3568 | } |
| 3569 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3570 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3571 | return kCondGT; |
| 3572 | } |
| 3573 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3574 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3575 | 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] | 3576 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3577 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3578 | }; |
| 3579 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3580 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3581 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3582 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3583 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3584 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3585 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3586 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3587 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3588 | // In the following Evaluate methods, a HCompare instruction has |
| 3589 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3590 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3591 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3592 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3593 | } |
| 3594 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3595 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3596 | } |
| 3597 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3598 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3599 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3600 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3601 | DECLARE_INSTRUCTION(GreaterThan); |
| 3602 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3603 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3604 | return kCondGT; |
| 3605 | } |
| 3606 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3607 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3608 | return kCondLE; |
| 3609 | } |
| 3610 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3611 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3612 | 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] | 3613 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3614 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3615 | }; |
| 3616 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3617 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3618 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3619 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3620 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3621 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3622 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3623 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3624 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3625 | // In the following Evaluate methods, a HCompare instruction has |
| 3626 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3627 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3628 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3629 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3630 | } |
| 3631 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3632 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3633 | } |
| 3634 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3635 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3636 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3637 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3638 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3639 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3640 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3641 | return kCondGE; |
| 3642 | } |
| 3643 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3644 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3645 | return kCondLT; |
| 3646 | } |
| 3647 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3648 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3649 | 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] | 3650 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3651 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3652 | }; |
| 3653 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3654 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3655 | public: |
| 3656 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3657 | : HCondition(first, second, dex_pc) {} |
| 3658 | |
| 3659 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3660 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3661 | } |
| 3662 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3663 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3664 | } |
| 3665 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3666 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3667 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3668 | UNREACHABLE(); |
| 3669 | } |
| 3670 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3671 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3672 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3673 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | DECLARE_INSTRUCTION(Below); |
| 3677 | |
| 3678 | IfCondition GetCondition() const OVERRIDE { |
| 3679 | return kCondB; |
| 3680 | } |
| 3681 | |
| 3682 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3683 | return kCondAE; |
| 3684 | } |
| 3685 | |
| 3686 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3687 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3688 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3689 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3690 | |
| 3691 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3692 | }; |
| 3693 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3694 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3695 | public: |
| 3696 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3697 | : HCondition(first, second, dex_pc) {} |
| 3698 | |
| 3699 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3700 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3701 | } |
| 3702 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3703 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3704 | } |
| 3705 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3706 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3707 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3708 | UNREACHABLE(); |
| 3709 | } |
| 3710 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3711 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3712 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3713 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3714 | } |
| 3715 | |
| 3716 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3717 | |
| 3718 | IfCondition GetCondition() const OVERRIDE { |
| 3719 | return kCondBE; |
| 3720 | } |
| 3721 | |
| 3722 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3723 | return kCondA; |
| 3724 | } |
| 3725 | |
| 3726 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3727 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3728 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3729 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3730 | |
| 3731 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3732 | }; |
| 3733 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3734 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3735 | public: |
| 3736 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3737 | : HCondition(first, second, dex_pc) {} |
| 3738 | |
| 3739 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3740 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3741 | } |
| 3742 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3743 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3744 | } |
| 3745 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3746 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3747 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3748 | UNREACHABLE(); |
| 3749 | } |
| 3750 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3751 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3752 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3753 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | DECLARE_INSTRUCTION(Above); |
| 3757 | |
| 3758 | IfCondition GetCondition() const OVERRIDE { |
| 3759 | return kCondA; |
| 3760 | } |
| 3761 | |
| 3762 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3763 | return kCondBE; |
| 3764 | } |
| 3765 | |
| 3766 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3767 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3768 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3769 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3770 | |
| 3771 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3772 | }; |
| 3773 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3774 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3775 | public: |
| 3776 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3777 | : HCondition(first, second, dex_pc) {} |
| 3778 | |
| 3779 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3780 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3781 | } |
| 3782 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3783 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3784 | } |
| 3785 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3786 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3787 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3788 | UNREACHABLE(); |
| 3789 | } |
| 3790 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3791 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3792 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3793 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3794 | } |
| 3795 | |
| 3796 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3797 | |
| 3798 | IfCondition GetCondition() const OVERRIDE { |
| 3799 | return kCondAE; |
| 3800 | } |
| 3801 | |
| 3802 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3803 | return kCondB; |
| 3804 | } |
| 3805 | |
| 3806 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3807 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3808 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3809 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3810 | |
| 3811 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3812 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3813 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3814 | // Instruction to check how two inputs compare to each other. |
| 3815 | // 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] | 3816 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3817 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3818 | // Note that `comparison_type` is the type of comparison performed |
| 3819 | // between the comparison's inputs, not the type of the instantiated |
| 3820 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3821 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3822 | HInstruction* first, |
| 3823 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3824 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3825 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3826 | : HBinaryOperation(Primitive::kPrimInt, |
| 3827 | first, |
| 3828 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3829 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3830 | dex_pc) { |
| 3831 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3832 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3833 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3834 | } |
| 3835 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3836 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3837 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3838 | |
| 3839 | template <typename T> |
| 3840 | int32_t ComputeFP(T x, T y) const { |
| 3841 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3842 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3843 | // Handle the bias. |
| 3844 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3845 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3846 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3847 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3848 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3849 | // reach this code path when processing a freshly built HIR |
| 3850 | // graph. However HCompare integer instructions can be synthesized |
| 3851 | // by the instruction simplifier to implement IntegerCompare and |
| 3852 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3853 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3854 | } |
| 3855 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3856 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3857 | } |
| 3858 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3859 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3860 | } |
| 3861 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3862 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3863 | } |
| 3864 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3865 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3866 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3867 | } |
| 3868 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3869 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3870 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3871 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3872 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3873 | bool IsGtBias() const { |
| 3874 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3875 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3876 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3877 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3878 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3879 | // Comparisons do not require a runtime call in any back end. |
| 3880 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3881 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3882 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3883 | DECLARE_INSTRUCTION(Compare); |
| 3884 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3885 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3886 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3887 | static constexpr size_t kFieldComparisonBiasSize = |
| 3888 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3889 | static constexpr size_t kNumberOfComparePackedBits = |
| 3890 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3891 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3892 | using ComparisonBiasField = |
| 3893 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3894 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3895 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3896 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3897 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3898 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3899 | } |
| 3900 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3901 | private: |
| 3902 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3903 | }; |
| 3904 | |
Nicolas Geoffray | 2b615ba | 2017-01-06 14:40:07 +0000 | [diff] [blame] | 3905 | class HNewInstance FINAL : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3906 | public: |
| 3907 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3908 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3909 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3910 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3911 | bool finalizable, |
| 3912 | QuickEntrypointEnum entrypoint) |
| 3913 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3914 | type_index_(type_index), |
| 3915 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3916 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3917 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3918 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3919 | } |
| 3920 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3921 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3922 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3923 | |
| 3924 | // Calls runtime so needs an environment. |
| 3925 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3926 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3927 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3928 | bool CanThrow() const OVERRIDE { return true; } |
| 3929 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 3930 | bool NeedsChecks() const { |
| 3931 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 3932 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3933 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3934 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3935 | |
| 3936 | bool CanBeNull() const OVERRIDE { return false; } |
| 3937 | |
| 3938 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3939 | |
| 3940 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3941 | entrypoint_ = entrypoint; |
| 3942 | } |
| 3943 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 3944 | HLoadClass* GetLoadClass() const { |
| 3945 | HInstruction* input = InputAt(0); |
| 3946 | if (input->IsClinitCheck()) { |
| 3947 | input = input->InputAt(0); |
| 3948 | } |
| 3949 | DCHECK(input->IsLoadClass()); |
| 3950 | return input->AsLoadClass(); |
| 3951 | } |
| 3952 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3953 | bool IsStringAlloc() const; |
| 3954 | |
| 3955 | DECLARE_INSTRUCTION(NewInstance); |
| 3956 | |
| 3957 | private: |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 3958 | static constexpr size_t kFlagFinalizable = kNumberOfExpressionPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3959 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3960 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3961 | "Too many packed fields."); |
| 3962 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3963 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3964 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3965 | QuickEntrypointEnum entrypoint_; |
| 3966 | |
| 3967 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3968 | }; |
| 3969 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3970 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3971 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3972 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3973 | }; |
| 3974 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3975 | enum IntrinsicSideEffects { |
| 3976 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3977 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3978 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3979 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3980 | }; |
| 3981 | |
| 3982 | enum IntrinsicExceptions { |
| 3983 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3984 | kCanThrow // Intrinsic may throw exceptions. |
| 3985 | }; |
| 3986 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3987 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3988 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3989 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3990 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3991 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3992 | SetRawInputAt(index, argument); |
| 3993 | } |
| 3994 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3995 | // Return the number of arguments. This number can be lower than |
| 3996 | // the number of inputs returned by InputCount(), as some invoke |
| 3997 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3998 | // inputs at the end of their list of inputs. |
| 3999 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 4000 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4001 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4002 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4003 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4004 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4005 | InvokeType GetInvokeType() const { |
| 4006 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4007 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4008 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 4009 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4010 | return intrinsic_; |
| 4011 | } |
| 4012 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4013 | void SetIntrinsic(Intrinsics intrinsic, |
| 4014 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 4015 | IntrinsicSideEffects side_effects, |
| 4016 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4017 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4018 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4019 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4020 | } |
| 4021 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4022 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4023 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4024 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4025 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4026 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4027 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4028 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4029 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 4030 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4031 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4032 | uint32_t* GetIntrinsicOptimizations() { |
| 4033 | return &intrinsic_optimizations_; |
| 4034 | } |
| 4035 | |
| 4036 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4037 | return &intrinsic_optimizations_; |
| 4038 | } |
| 4039 | |
| 4040 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4041 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4042 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4043 | void SetResolvedMethod(ArtMethod* method) { resolved_method_ = method; } |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4044 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4045 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4046 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4047 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4048 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4049 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4050 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4051 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4052 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4053 | static constexpr size_t kFieldReturnTypeSize = |
| 4054 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 4055 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 4056 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 4057 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4058 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4059 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 4060 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4061 | HInvoke(ArenaAllocator* arena, |
| 4062 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4063 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4064 | Primitive::Type return_type, |
| 4065 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4066 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4067 | ArtMethod* resolved_method, |
| 4068 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4069 | : HVariableInputSizeInstruction( |
| 4070 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4071 | dex_pc, |
| 4072 | arena, |
| 4073 | number_of_arguments + number_of_other_inputs, |
| 4074 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4075 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4076 | resolved_method_(resolved_method), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4077 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4078 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4079 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4080 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4081 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4082 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4083 | } |
| 4084 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4085 | uint32_t number_of_arguments_; |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4086 | ArtMethod* resolved_method_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4087 | const uint32_t dex_method_index_; |
| 4088 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4089 | |
| 4090 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4091 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4092 | |
| 4093 | private: |
| 4094 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 4095 | }; |
| 4096 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4097 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4098 | public: |
| 4099 | HInvokeUnresolved(ArenaAllocator* arena, |
| 4100 | uint32_t number_of_arguments, |
| 4101 | Primitive::Type return_type, |
| 4102 | uint32_t dex_pc, |
| 4103 | uint32_t dex_method_index, |
| 4104 | InvokeType invoke_type) |
| 4105 | : HInvoke(arena, |
| 4106 | number_of_arguments, |
| 4107 | 0u /* number_of_other_inputs */, |
| 4108 | return_type, |
| 4109 | dex_pc, |
| 4110 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4111 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4112 | invoke_type) { |
| 4113 | } |
| 4114 | |
| 4115 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4116 | |
| 4117 | private: |
| 4118 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 4119 | }; |
| 4120 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4121 | class HInvokePolymorphic FINAL : public HInvoke { |
| 4122 | public: |
| 4123 | HInvokePolymorphic(ArenaAllocator* arena, |
| 4124 | uint32_t number_of_arguments, |
| 4125 | Primitive::Type return_type, |
| 4126 | uint32_t dex_pc, |
| 4127 | uint32_t dex_method_index) |
| 4128 | : HInvoke(arena, |
| 4129 | number_of_arguments, |
| 4130 | 0u /* number_of_other_inputs */, |
| 4131 | return_type, |
| 4132 | dex_pc, |
| 4133 | dex_method_index, |
| 4134 | nullptr, |
| 4135 | kVirtual) {} |
| 4136 | |
| 4137 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4138 | |
| 4139 | private: |
| 4140 | DISALLOW_COPY_AND_ASSIGN(HInvokePolymorphic); |
| 4141 | }; |
| 4142 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4143 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4144 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4145 | // Requirements of this method call regarding the class |
| 4146 | // initialization (clinit) check of its declaring class. |
| 4147 | enum class ClinitCheckRequirement { |
| 4148 | kNone, // Class already initialized. |
| 4149 | kExplicit, // Static call having explicit clinit check as last input. |
| 4150 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4151 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4152 | }; |
| 4153 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4154 | // Determines how to load the target ArtMethod*. |
| 4155 | enum class MethodLoadKind { |
| 4156 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4157 | kStringInit, |
| 4158 | |
| 4159 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4160 | kRecursive, |
| 4161 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4162 | // Use PC-relative boot image ArtMethod* address that will be known at link time. |
| 4163 | // Used for boot image methods referenced by boot image code. |
| 4164 | kBootImageLinkTimePcRelative, |
| 4165 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4166 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4167 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 4168 | kDirectAddress, |
| 4169 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4170 | // Load from an entry in the .bss section using a PC-relative load. |
| 4171 | // Used for classes outside boot image when .bss is accessible with a PC-relative load. |
| 4172 | kBssEntry, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4173 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4174 | // Make a runtime call to resolve and call the method. This is the last-resort-kind |
| 4175 | // used when other kinds are unimplemented on a particular architecture. |
| 4176 | kRuntimeCall, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4177 | }; |
| 4178 | |
| 4179 | // Determines the location of the code pointer. |
| 4180 | enum class CodePtrLocation { |
| 4181 | // Recursive call, use local PC-relative call instruction. |
| 4182 | kCallSelf, |
| 4183 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4184 | // Use code pointer from the ArtMethod*. |
| 4185 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4186 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4187 | kCallArtMethod, |
| 4188 | }; |
| 4189 | |
| 4190 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4191 | MethodLoadKind method_load_kind; |
| 4192 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4193 | // The method load data holds |
| 4194 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4195 | // Note that there are multiple string init methods, each having its own offset. |
| 4196 | // - the method address for kDirectAddress |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4197 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4198 | }; |
| 4199 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4200 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 4201 | uint32_t number_of_arguments, |
| 4202 | Primitive::Type return_type, |
| 4203 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4204 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4205 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4206 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4207 | InvokeType invoke_type, |
| 4208 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4209 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4210 | : HInvoke(arena, |
| 4211 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4212 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4213 | // potentially one other if the clinit check is explicit, and potentially |
| 4214 | // one other if the method is a string factory. |
| 4215 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4216 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4217 | return_type, |
| 4218 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4219 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4220 | resolved_method, |
| 4221 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4222 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4223 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4224 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4225 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4226 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4227 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4228 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4229 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4230 | |
| 4231 | // Using the current method is the default and once we find a better |
| 4232 | // method load kind, we should not go back to using the current method. |
| 4233 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4234 | |
| 4235 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4236 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4237 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4238 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4239 | dispatch_info_ = dispatch_info; |
| 4240 | } |
| 4241 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 4242 | DispatchInfo GetDispatchInfo() const { |
| 4243 | return dispatch_info_; |
| 4244 | } |
| 4245 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4246 | void AddSpecialInput(HInstruction* input) { |
| 4247 | // We allow only one special input. |
| 4248 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4249 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4250 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4251 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4252 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4253 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4254 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4255 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4256 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4257 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4258 | DCHECK(!input_records.empty()); |
| 4259 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4260 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4261 | // Note: `last_input` may be null during arguments setup. |
| 4262 | if (last_input != nullptr) { |
| 4263 | // `last_input` is the last input of a static invoke marked as having |
| 4264 | // an explicit clinit check. It must either be: |
| 4265 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4266 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4267 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4268 | } |
| 4269 | } |
| 4270 | return input_records; |
| 4271 | } |
| 4272 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4273 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4274 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4275 | // TODO: for intrinsics we can generate implicit null checks. |
| 4276 | return false; |
| 4277 | } |
| 4278 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4279 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4280 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4281 | } |
| 4282 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4283 | // Get the index of the special input, if any. |
| 4284 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4285 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4286 | // method pointer; otherwise there may be one platform-specific special input, |
| 4287 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4288 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4289 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4290 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4291 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4292 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4293 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4294 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4295 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4296 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4297 | bool HasPcRelativeMethodLoadKind() const { |
| 4298 | return GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4299 | GetMethodLoadKind() == MethodLoadKind::kBssEntry; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4300 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4301 | bool HasCurrentMethodInput() const { |
| 4302 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4303 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4304 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4305 | return true; |
| 4306 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4307 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4308 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4309 | return false; |
| 4310 | } |
| 4311 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4312 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4313 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4314 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4315 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | uint64_t GetMethodAddress() const { |
| 4319 | DCHECK(HasMethodAddress()); |
| 4320 | return dispatch_info_.method_load_data; |
| 4321 | } |
| 4322 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4323 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4324 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4325 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4326 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4327 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4328 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4329 | // Is this instruction a call to a static method? |
| 4330 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4331 | return GetInvokeType() == kStatic; |
| 4332 | } |
| 4333 | |
| 4334 | MethodReference GetTargetMethod() const { |
| 4335 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4336 | } |
| 4337 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4338 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4339 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4340 | // instruction; only relevant for static calls with explicit clinit check. |
| 4341 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4342 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4343 | size_t last_input_index = inputs_.size() - 1u; |
| 4344 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4345 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4346 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4347 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4348 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4349 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4350 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | // 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] | 4354 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4355 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4356 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | // Is this a call to a static method whose declaring class has an |
| 4360 | // implicit intialization check requirement? |
| 4361 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4362 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4363 | } |
| 4364 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4365 | // Does this method load kind need the current method as an input? |
| 4366 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4367 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kRuntimeCall; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4370 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4371 | |
| 4372 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4373 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4374 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4375 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4376 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4377 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4378 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4379 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4380 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4381 | kFieldClinitCheckRequirement, |
| 4382 | kFieldClinitCheckRequirementSize>; |
| 4383 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4384 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4385 | MethodReference target_method_; |
| 4386 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4387 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4388 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4389 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4390 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4391 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4392 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4393 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4394 | public: |
| 4395 | HInvokeVirtual(ArenaAllocator* arena, |
| 4396 | uint32_t number_of_arguments, |
| 4397 | Primitive::Type return_type, |
| 4398 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4399 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4400 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4401 | uint32_t vtable_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4402 | : HInvoke(arena, |
| 4403 | number_of_arguments, |
| 4404 | 0u, |
| 4405 | return_type, |
| 4406 | dex_pc, |
| 4407 | dex_method_index, |
| 4408 | resolved_method, |
| 4409 | kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4410 | vtable_index_(vtable_index) {} |
| 4411 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4412 | bool CanBeNull() const OVERRIDE { |
| 4413 | switch (GetIntrinsic()) { |
| 4414 | case Intrinsics::kThreadCurrentThread: |
| 4415 | case Intrinsics::kStringBufferAppend: |
| 4416 | case Intrinsics::kStringBufferToString: |
| 4417 | case Intrinsics::kStringBuilderAppend: |
| 4418 | case Intrinsics::kStringBuilderToString: |
| 4419 | return false; |
| 4420 | default: |
| 4421 | return HInvoke::CanBeNull(); |
| 4422 | } |
| 4423 | } |
| 4424 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4425 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4426 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4427 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4428 | } |
| 4429 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4430 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4431 | |
| 4432 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4433 | |
| 4434 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4435 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4436 | const uint32_t vtable_index_; |
| 4437 | |
| 4438 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4439 | }; |
| 4440 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4441 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4442 | public: |
| 4443 | HInvokeInterface(ArenaAllocator* arena, |
| 4444 | uint32_t number_of_arguments, |
| 4445 | Primitive::Type return_type, |
| 4446 | uint32_t dex_pc, |
| 4447 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4448 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4449 | uint32_t imt_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4450 | : HInvoke(arena, |
| 4451 | number_of_arguments, |
| 4452 | 0u, |
| 4453 | return_type, |
| 4454 | dex_pc, |
| 4455 | dex_method_index, |
| 4456 | resolved_method, |
| 4457 | kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4458 | imt_index_(imt_index) {} |
| 4459 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4460 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4461 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4462 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4463 | } |
| 4464 | |
Nicolas Geoffray | fbdfa6d | 2017-02-03 10:43:13 +0000 | [diff] [blame] | 4465 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 4466 | // The assembly stub currently needs it. |
| 4467 | return true; |
| 4468 | } |
| 4469 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4470 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4471 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4472 | |
| 4473 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4474 | |
| 4475 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4476 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4477 | const uint32_t imt_index_; |
| 4478 | |
| 4479 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4480 | }; |
| 4481 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4482 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4483 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4484 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4485 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4486 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4487 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4488 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4489 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4490 | |
| 4491 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4492 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4493 | } |
| 4494 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4495 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4496 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4497 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4498 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4499 | } |
| 4500 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4501 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4502 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4503 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4504 | DECLARE_INSTRUCTION(Neg); |
| 4505 | |
| 4506 | private: |
| 4507 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4508 | }; |
| 4509 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4510 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4511 | public: |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4512 | HNewArray(HInstruction* cls, HInstruction* length, uint32_t dex_pc) |
| 4513 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc) { |
| 4514 | SetRawInputAt(0, cls); |
| 4515 | SetRawInputAt(1, length); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4516 | } |
| 4517 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4518 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4519 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4520 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4521 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4522 | bool CanThrow() const OVERRIDE { return true; } |
| 4523 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4524 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4525 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4526 | HLoadClass* GetLoadClass() const { |
| 4527 | DCHECK(InputAt(0)->IsLoadClass()); |
| 4528 | return InputAt(0)->AsLoadClass(); |
| 4529 | } |
| 4530 | |
| 4531 | HInstruction* GetLength() const { |
| 4532 | return InputAt(1); |
| 4533 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4534 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4535 | DECLARE_INSTRUCTION(NewArray); |
| 4536 | |
| 4537 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4538 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4539 | }; |
| 4540 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4541 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4542 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4543 | HAdd(Primitive::Type result_type, |
| 4544 | HInstruction* left, |
| 4545 | HInstruction* right, |
| 4546 | uint32_t dex_pc = kNoDexPc) |
| 4547 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4548 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4549 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4550 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4551 | 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] | 4552 | |
| 4553 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4554 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4555 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4556 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4557 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4558 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4559 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4560 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4561 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4562 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4563 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4564 | } |
| 4565 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4566 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4567 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4568 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4569 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4570 | DECLARE_INSTRUCTION(Add); |
| 4571 | |
| 4572 | private: |
| 4573 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4574 | }; |
| 4575 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4576 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4577 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4578 | HSub(Primitive::Type result_type, |
| 4579 | HInstruction* left, |
| 4580 | HInstruction* right, |
| 4581 | uint32_t dex_pc = kNoDexPc) |
| 4582 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4583 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4584 | 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] | 4585 | |
| 4586 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4587 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4588 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4589 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4590 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4591 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4592 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4593 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4594 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4595 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4596 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4597 | } |
| 4598 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4599 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4600 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4601 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4602 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4603 | DECLARE_INSTRUCTION(Sub); |
| 4604 | |
| 4605 | private: |
| 4606 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4607 | }; |
| 4608 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4609 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4610 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4611 | HMul(Primitive::Type result_type, |
| 4612 | HInstruction* left, |
| 4613 | HInstruction* right, |
| 4614 | uint32_t dex_pc = kNoDexPc) |
| 4615 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4616 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4617 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4618 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4619 | 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] | 4620 | |
| 4621 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4622 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4623 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4624 | } |
| 4625 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4626 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4627 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4628 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4629 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4630 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4631 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4632 | } |
| 4633 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4634 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4635 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4636 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4637 | |
| 4638 | DECLARE_INSTRUCTION(Mul); |
| 4639 | |
| 4640 | private: |
| 4641 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4642 | }; |
| 4643 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4644 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4645 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4646 | HDiv(Primitive::Type result_type, |
| 4647 | HInstruction* left, |
| 4648 | HInstruction* right, |
| 4649 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4650 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4651 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4652 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4653 | T ComputeIntegral(T x, T y) const { |
| 4654 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4655 | // Our graph structure ensures we never have 0 for `y` during |
| 4656 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4657 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4658 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4659 | return (y == -1) ? -x : x / y; |
| 4660 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4661 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4662 | template <typename T> |
| 4663 | T ComputeFP(T x, T y) const { |
| 4664 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4665 | return x / y; |
| 4666 | } |
| 4667 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4668 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4669 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4670 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4671 | } |
| 4672 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4673 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4674 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4675 | } |
| 4676 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4677 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4678 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4679 | } |
| 4680 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4681 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4682 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4683 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4684 | |
| 4685 | DECLARE_INSTRUCTION(Div); |
| 4686 | |
| 4687 | private: |
| 4688 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4689 | }; |
| 4690 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4691 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4692 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4693 | HRem(Primitive::Type result_type, |
| 4694 | HInstruction* left, |
| 4695 | HInstruction* right, |
| 4696 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4697 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4698 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4699 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4700 | T ComputeIntegral(T x, T y) const { |
| 4701 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4702 | // Our graph structure ensures we never have 0 for `y` during |
| 4703 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4704 | DCHECK_NE(y, 0); |
| 4705 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4706 | return (y == -1) ? 0 : x % y; |
| 4707 | } |
| 4708 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4709 | template <typename T> |
| 4710 | T ComputeFP(T x, T y) const { |
| 4711 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4712 | return std::fmod(x, y); |
| 4713 | } |
| 4714 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4715 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4716 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4717 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4718 | } |
| 4719 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4720 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4721 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4722 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4723 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4724 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4725 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4726 | } |
| 4727 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4728 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4729 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4730 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4731 | |
| 4732 | DECLARE_INSTRUCTION(Rem); |
| 4733 | |
| 4734 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4735 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4736 | }; |
| 4737 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4738 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4739 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4740 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4741 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4742 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4743 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4744 | SetRawInputAt(0, value); |
| 4745 | } |
| 4746 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4747 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4748 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4749 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4750 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4751 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4752 | return true; |
| 4753 | } |
| 4754 | |
| 4755 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4756 | bool CanThrow() const OVERRIDE { return true; } |
| 4757 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4758 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4759 | |
| 4760 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4761 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4762 | }; |
| 4763 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4764 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4765 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4766 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4767 | HInstruction* value, |
| 4768 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4769 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4770 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4771 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4772 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4773 | } |
| 4774 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4775 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4776 | 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] | 4777 | return value << (distance & max_shift_distance); |
| 4778 | } |
| 4779 | |
| 4780 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4781 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4782 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4783 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4784 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4785 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4786 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4787 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4788 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4789 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4790 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4791 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4792 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4793 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4794 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4795 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4796 | UNREACHABLE(); |
| 4797 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4798 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4799 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4800 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4801 | UNREACHABLE(); |
| 4802 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4803 | |
| 4804 | DECLARE_INSTRUCTION(Shl); |
| 4805 | |
| 4806 | private: |
| 4807 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4808 | }; |
| 4809 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4810 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4811 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4812 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4813 | HInstruction* value, |
| 4814 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4815 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4816 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4817 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4818 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4819 | } |
| 4820 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4821 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4822 | 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] | 4823 | return value >> (distance & max_shift_distance); |
| 4824 | } |
| 4825 | |
| 4826 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4827 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4828 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4829 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4830 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4831 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4832 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4833 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4834 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4835 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4836 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4837 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4838 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4839 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4840 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4841 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4842 | UNREACHABLE(); |
| 4843 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4844 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4845 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4846 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4847 | UNREACHABLE(); |
| 4848 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4849 | |
| 4850 | DECLARE_INSTRUCTION(Shr); |
| 4851 | |
| 4852 | private: |
| 4853 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4854 | }; |
| 4855 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4856 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4857 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4858 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4859 | HInstruction* value, |
| 4860 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4861 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4862 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4863 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4864 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4865 | } |
| 4866 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4867 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4868 | 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] | 4869 | typedef typename std::make_unsigned<T>::type V; |
| 4870 | V ux = static_cast<V>(value); |
| 4871 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4872 | } |
| 4873 | |
| 4874 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4875 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4876 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4877 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4878 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4879 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4880 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4881 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4882 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4883 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4884 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4885 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4886 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4887 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4888 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4889 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4890 | UNREACHABLE(); |
| 4891 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4892 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4893 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4894 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4895 | UNREACHABLE(); |
| 4896 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4897 | |
| 4898 | DECLARE_INSTRUCTION(UShr); |
| 4899 | |
| 4900 | private: |
| 4901 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4902 | }; |
| 4903 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4904 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4905 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4906 | HAnd(Primitive::Type result_type, |
| 4907 | HInstruction* left, |
| 4908 | HInstruction* right, |
| 4909 | uint32_t dex_pc = kNoDexPc) |
| 4910 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4911 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4912 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4913 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4914 | 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] | 4915 | |
| 4916 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4917 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4918 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4919 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4920 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4921 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4922 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4923 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4924 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4925 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4926 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4927 | UNREACHABLE(); |
| 4928 | } |
| 4929 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4930 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4931 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4932 | UNREACHABLE(); |
| 4933 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4934 | |
| 4935 | DECLARE_INSTRUCTION(And); |
| 4936 | |
| 4937 | private: |
| 4938 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4939 | }; |
| 4940 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4941 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4942 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4943 | HOr(Primitive::Type result_type, |
| 4944 | HInstruction* left, |
| 4945 | HInstruction* right, |
| 4946 | uint32_t dex_pc = kNoDexPc) |
| 4947 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4948 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4949 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4950 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4951 | 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] | 4952 | |
| 4953 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4954 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4955 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4956 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4957 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4958 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4959 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4960 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4961 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4962 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4963 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4964 | UNREACHABLE(); |
| 4965 | } |
| 4966 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4967 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4968 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4969 | UNREACHABLE(); |
| 4970 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4971 | |
| 4972 | DECLARE_INSTRUCTION(Or); |
| 4973 | |
| 4974 | private: |
| 4975 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4976 | }; |
| 4977 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4978 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4979 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4980 | HXor(Primitive::Type result_type, |
| 4981 | HInstruction* left, |
| 4982 | HInstruction* right, |
| 4983 | uint32_t dex_pc = kNoDexPc) |
| 4984 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4985 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4986 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4987 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4988 | 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] | 4989 | |
| 4990 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4991 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4992 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4993 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4994 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4995 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4996 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4997 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4998 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4999 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5000 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5001 | UNREACHABLE(); |
| 5002 | } |
| 5003 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5004 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5005 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5006 | UNREACHABLE(); |
| 5007 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5008 | |
| 5009 | DECLARE_INSTRUCTION(Xor); |
| 5010 | |
| 5011 | private: |
| 5012 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 5013 | }; |
| 5014 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5015 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5016 | public: |
| 5017 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5018 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5019 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 5020 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5021 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5022 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5023 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5024 | 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] | 5025 | typedef typename std::make_unsigned<T>::type V; |
| 5026 | V ux = static_cast<V>(value); |
| 5027 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5028 | return static_cast<T>(ux); |
| 5029 | } else { |
| 5030 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5031 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 5032 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5033 | } |
| 5034 | } |
| 5035 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5036 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5037 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5038 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5039 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5040 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5041 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5042 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5043 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5044 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5045 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5046 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5047 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5048 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5049 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5050 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5051 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5052 | UNREACHABLE(); |
| 5053 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5054 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5055 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5056 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5057 | UNREACHABLE(); |
| 5058 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5059 | |
| 5060 | DECLARE_INSTRUCTION(Ror); |
| 5061 | |
| 5062 | private: |
| 5063 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 5064 | }; |
| 5065 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5066 | // The value of a parameter in this method. Its location depends on |
| 5067 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5068 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5069 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5070 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5071 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5072 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5073 | Primitive::Type parameter_type, |
| 5074 | bool is_this = false) |
| 5075 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5076 | dex_file_(dex_file), |
| 5077 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5078 | index_(index) { |
| 5079 | SetPackedFlag<kFlagIsThis>(is_this); |
| 5080 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 5081 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5082 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5083 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5084 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5085 | uint8_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5086 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5087 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5088 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 5089 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5090 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5091 | DECLARE_INSTRUCTION(ParameterValue); |
| 5092 | |
| 5093 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5094 | // Whether or not the parameter value corresponds to 'this' argument. |
| 5095 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 5096 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 5097 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 5098 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 5099 | "Too many packed fields."); |
| 5100 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5101 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5102 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5103 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5104 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5105 | const uint8_t index_; |
| 5106 | |
| 5107 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 5108 | }; |
| 5109 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5110 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5111 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5112 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5113 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5114 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5115 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5116 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5117 | return true; |
| 5118 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5119 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5120 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5121 | |
| 5122 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5123 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5124 | } |
| 5125 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5126 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5127 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5128 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5129 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5130 | UNREACHABLE(); |
| 5131 | } |
| 5132 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5133 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5134 | UNREACHABLE(); |
| 5135 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5136 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5137 | DECLARE_INSTRUCTION(Not); |
| 5138 | |
| 5139 | private: |
| 5140 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 5141 | }; |
| 5142 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5143 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5144 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5145 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5146 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5147 | |
| 5148 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5149 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5150 | return true; |
| 5151 | } |
| 5152 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5153 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5154 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5155 | return !x; |
| 5156 | } |
| 5157 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5158 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5159 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5160 | } |
| 5161 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5162 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5163 | UNREACHABLE(); |
| 5164 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5165 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5166 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5167 | UNREACHABLE(); |
| 5168 | } |
| 5169 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5170 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5171 | UNREACHABLE(); |
| 5172 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5173 | |
| 5174 | DECLARE_INSTRUCTION(BooleanNot); |
| 5175 | |
| 5176 | private: |
| 5177 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 5178 | }; |
| 5179 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5180 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5181 | public: |
| 5182 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 5183 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5184 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5185 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5186 | // Invariant: We should never generate a conversion to a Boolean value. |
| 5187 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | HInstruction* GetInput() const { return InputAt(0); } |
| 5191 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 5192 | Primitive::Type GetResultType() const { return GetType(); } |
| 5193 | |
| 5194 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5195 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5196 | return true; |
| 5197 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5198 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5199 | // Try to statically evaluate the conversion and return a HConstant |
| 5200 | // containing the result. If the input cannot be converted, return nullptr. |
| 5201 | HConstant* TryStaticEvaluation() const; |
| 5202 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5203 | DECLARE_INSTRUCTION(TypeConversion); |
| 5204 | |
| 5205 | private: |
| 5206 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 5207 | }; |
| 5208 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5209 | static constexpr uint32_t kNoRegNumber = -1; |
| 5210 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5211 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5212 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5213 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 5214 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5215 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5216 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5217 | SetRawInputAt(0, value); |
| 5218 | } |
| 5219 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5220 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5221 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5222 | return true; |
| 5223 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5224 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5225 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5226 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5227 | bool CanThrow() const OVERRIDE { return true; } |
| 5228 | |
| 5229 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5230 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5231 | |
| 5232 | DECLARE_INSTRUCTION(NullCheck); |
| 5233 | |
| 5234 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5235 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 5236 | }; |
| 5237 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5238 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5239 | // 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] | 5240 | class FieldInfo : public ValueObject { |
| 5241 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5242 | FieldInfo(ArtField* field, |
| 5243 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5244 | Primitive::Type field_type, |
| 5245 | bool is_volatile, |
| 5246 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5247 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5248 | const DexFile& dex_file) |
| 5249 | : field_(field), |
| 5250 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5251 | field_type_(field_type), |
| 5252 | is_volatile_(is_volatile), |
| 5253 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5254 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5255 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5256 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5257 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5258 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5259 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5260 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5261 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5262 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5263 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5264 | |
| 5265 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5266 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5267 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5268 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5269 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5270 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5271 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5272 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5273 | }; |
| 5274 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5275 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5276 | public: |
| 5277 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5278 | ArtField* field, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5279 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5280 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5281 | bool is_volatile, |
| 5282 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5283 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5284 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5285 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5286 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5287 | field_info_(field, |
| 5288 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5289 | field_type, |
| 5290 | is_volatile, |
| 5291 | field_idx, |
| 5292 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5293 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5294 | SetRawInputAt(0, value); |
| 5295 | } |
| 5296 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5297 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5298 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5299 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5300 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5301 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5302 | } |
| 5303 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5304 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5305 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5309 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5310 | } |
| 5311 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5312 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5313 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5314 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5315 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5316 | |
| 5317 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5318 | |
| 5319 | private: |
| 5320 | const FieldInfo field_info_; |
| 5321 | |
| 5322 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5323 | }; |
| 5324 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5325 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5326 | public: |
| 5327 | HInstanceFieldSet(HInstruction* object, |
| 5328 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5329 | ArtField* field, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5330 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5331 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5332 | bool is_volatile, |
| 5333 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5334 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5335 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5336 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5337 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5338 | field_info_(field, |
| 5339 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5340 | field_type, |
| 5341 | is_volatile, |
| 5342 | field_idx, |
| 5343 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5344 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5345 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5346 | SetRawInputAt(0, object); |
| 5347 | SetRawInputAt(1, value); |
| 5348 | } |
| 5349 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5350 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5351 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5352 | } |
| 5353 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5354 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5355 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5356 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5357 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5358 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5359 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5360 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5361 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5362 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5363 | |
| 5364 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5365 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5366 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5367 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5368 | "Too many packed fields."); |
| 5369 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5370 | const FieldInfo field_info_; |
| 5371 | |
| 5372 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5373 | }; |
| 5374 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5375 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5376 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5377 | HArrayGet(HInstruction* array, |
| 5378 | HInstruction* index, |
| 5379 | Primitive::Type type, |
| 5380 | uint32_t dex_pc, |
| 5381 | bool is_string_char_at = false) |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5382 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5383 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5384 | SetRawInputAt(0, array); |
| 5385 | SetRawInputAt(1, index); |
| 5386 | } |
| 5387 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5388 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5389 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5390 | return true; |
| 5391 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5392 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5393 | // TODO: We can be smarter here. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5394 | // Currently, unless the array is the result of NewArray, the array access is always |
| 5395 | // preceded by some form of null NullCheck necessary for the bounds check, usually |
| 5396 | // implicit null check on the ArrayLength input to BoundsCheck or Deoptimize for |
| 5397 | // dynamic BCE. There are cases when these could be removed to produce better code. |
| 5398 | // If we ever add optimizations to do so we should allow an implicit check here |
| 5399 | // (as long as the address falls in the first page). |
| 5400 | // |
| 5401 | // As an example of such fancy optimization, we could eliminate BoundsCheck for |
| 5402 | // a = cond ? new int[1] : null; |
| 5403 | // a[0]; // The Phi does not need bounds check for either input. |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5404 | return false; |
| 5405 | } |
| 5406 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5407 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5408 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5409 | if (kIsDebugBuild && result) { |
| 5410 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5411 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5412 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5413 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5414 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5415 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5416 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5417 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5418 | } |
| 5419 | } |
| 5420 | return result; |
| 5421 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5422 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5423 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5424 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5425 | HInstruction* GetArray() const { return InputAt(0); } |
| 5426 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5427 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5428 | DECLARE_INSTRUCTION(ArrayGet); |
| 5429 | |
| 5430 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5431 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5432 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5433 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5434 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5435 | // a flag, so that code generators don't need to do the locking. |
| 5436 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5437 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5438 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5439 | "Too many packed fields."); |
| 5440 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5441 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5442 | }; |
| 5443 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5444 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5445 | public: |
| 5446 | HArraySet(HInstruction* array, |
| 5447 | HInstruction* index, |
| 5448 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5449 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5450 | uint32_t dex_pc) |
| 5451 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5452 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5453 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5454 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5455 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5456 | SetRawInputAt(0, array); |
| 5457 | SetRawInputAt(1, index); |
| 5458 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5459 | // Make a best guess now, may be refined during SSA building. |
| 5460 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5461 | } |
| 5462 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5463 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5464 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5465 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5466 | } |
| 5467 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5468 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5469 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5470 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5471 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5472 | // TODO: Same as for ArrayGet. |
| 5473 | return false; |
| 5474 | } |
| 5475 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5476 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5477 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5478 | } |
| 5479 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5480 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5481 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5482 | } |
| 5483 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5484 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5485 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5486 | } |
| 5487 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5488 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5489 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5490 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5491 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5492 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5493 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5494 | HInstruction* GetArray() const { return InputAt(0); } |
| 5495 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5496 | HInstruction* GetValue() const { return InputAt(2); } |
| 5497 | |
| 5498 | Primitive::Type GetComponentType() const { |
| 5499 | // The Dex format does not type floating point index operations. Since the |
| 5500 | // `expected_component_type_` is set during building and can therefore not |
| 5501 | // be correct, we also check what is the value type. If it is a floating |
| 5502 | // point type, we must use that type. |
| 5503 | Primitive::Type value_type = GetValue()->GetType(); |
| 5504 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5505 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5506 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5507 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5508 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5509 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5510 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5511 | } |
| 5512 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5513 | void ComputeSideEffects() { |
| 5514 | Primitive::Type type = GetComponentType(); |
| 5515 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5516 | SideEffectsForArchRuntimeCalls(type))); |
| 5517 | } |
| 5518 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5519 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5520 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5521 | } |
| 5522 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5523 | DECLARE_INSTRUCTION(ArraySet); |
| 5524 | |
| 5525 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5526 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5527 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5528 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5529 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5530 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5531 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5532 | // Cached information for the reference_type_info_ so that codegen |
| 5533 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5534 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5535 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5536 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5537 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5538 | using ExpectedComponentTypeField = |
| 5539 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5540 | |
| 5541 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5542 | }; |
| 5543 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5544 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5545 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5546 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5547 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5548 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5549 | // Note that arrays do not change length, so the instruction does not |
| 5550 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5551 | SetRawInputAt(0, array); |
| 5552 | } |
| 5553 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5554 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5555 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5556 | return true; |
| 5557 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5558 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5559 | return obj == InputAt(0); |
| 5560 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5561 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5562 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5563 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5564 | DECLARE_INSTRUCTION(ArrayLength); |
| 5565 | |
| 5566 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5567 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5568 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5569 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5570 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5571 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5572 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5573 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5574 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5575 | "Too many packed fields."); |
| 5576 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5577 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5578 | }; |
| 5579 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5580 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5581 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5582 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5583 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5584 | HBoundsCheck(HInstruction* index, |
| 5585 | HInstruction* length, |
| 5586 | uint32_t dex_pc, |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5587 | bool string_char_at = false) |
| 5588 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5589 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5590 | SetPackedFlag<kFlagIsStringCharAt>(string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5591 | SetRawInputAt(0, index); |
| 5592 | SetRawInputAt(1, length); |
| 5593 | } |
| 5594 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5595 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5596 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5597 | return true; |
| 5598 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5599 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5600 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5601 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5602 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5603 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5604 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5605 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5606 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5607 | |
| 5608 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5609 | |
| 5610 | private: |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5611 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5612 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5613 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5614 | }; |
| 5615 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5616 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5617 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5618 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5619 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5620 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5621 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5622 | return true; |
| 5623 | } |
| 5624 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5625 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5626 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5627 | |
| 5628 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5629 | |
| 5630 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5631 | // Only used for code generation, in order to share the same slow path between back edges |
| 5632 | // of a same loop. |
| 5633 | SlowPathCode* slow_path_; |
| 5634 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5635 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5636 | }; |
| 5637 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5638 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5639 | // It ensures that we can generate line number and local variables at this point. |
| 5640 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5641 | public: |
| 5642 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5643 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5644 | |
| 5645 | bool NeedsEnvironment() const OVERRIDE { |
| 5646 | return true; |
| 5647 | } |
| 5648 | |
| 5649 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5650 | |
| 5651 | private: |
| 5652 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5653 | }; |
| 5654 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5655 | /** |
| 5656 | * Instruction to load a Class object. |
| 5657 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5658 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5659 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5660 | // Determines how to load the Class. |
| 5661 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5662 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 5663 | kInvalid = -1, |
| 5664 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5665 | // Use the Class* from the method's own ArtMethod*. |
| 5666 | kReferrersClass, |
| 5667 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5668 | // Use PC-relative boot image Class* address that will be known at link time. |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5669 | // Used for boot image classes referenced by boot image code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5670 | kBootImageLinkTimePcRelative, |
| 5671 | |
| 5672 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5673 | // 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] | 5674 | kBootImageAddress, |
| 5675 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5676 | // Load from an entry in the .bss section using a PC-relative load. |
| 5677 | // Used for classes outside boot image when .bss is accessible with a PC-relative load. |
| 5678 | kBssEntry, |
| 5679 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5680 | // Load from the root table associated with the JIT compiled method. |
| 5681 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5682 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5683 | // Load using a simple runtime call. This is the fall-back load kind when |
| 5684 | // the codegen is unable to use another appropriate kind. |
| 5685 | kRuntimeCall, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5686 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5687 | kLast = kRuntimeCall |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5688 | }; |
| 5689 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5690 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5691 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5692 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5693 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5694 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5695 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5696 | bool needs_access_check) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5697 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5698 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5699 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5700 | dex_file_(dex_file), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5701 | klass_(klass), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5702 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5703 | // Referrers class should not need access check. We never inline unverified |
| 5704 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5705 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5706 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5707 | SetPackedField<LoadKindField>( |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5708 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kRuntimeCall); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5709 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 5710 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5711 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5712 | } |
| 5713 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5714 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5715 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5716 | LoadKind GetLoadKind() const { |
| 5717 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5718 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5719 | |
| 5720 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5721 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5722 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5723 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5724 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5725 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5726 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5727 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5728 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5729 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5730 | } |
| 5731 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5732 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5733 | // The entrypoint the code generator is going to call does not do |
| 5734 | // clinit of the class. |
| 5735 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5736 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5737 | } |
| 5738 | |
| 5739 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5740 | return NeedsAccessCheck() || |
| 5741 | MustGenerateClinitCheck() || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5742 | GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5743 | GetLoadKind() == LoadKind::kBssEntry; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5744 | } |
| 5745 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5746 | bool CanThrow() const OVERRIDE { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5747 | return NeedsAccessCheck() || |
| 5748 | MustGenerateClinitCheck() || |
| 5749 | // If the class is in the boot image, the lookup in the runtime call cannot throw. |
| 5750 | // This keeps CanThrow() consistent between non-PIC (using kBootImageAddress) and |
| 5751 | // PIC and subsequently avoids a DCE behavior dependency on the PIC option. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5752 | ((GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5753 | GetLoadKind() == LoadKind::kBssEntry) && |
| 5754 | !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5755 | } |
| 5756 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5757 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5758 | return loaded_class_rti_; |
| 5759 | } |
| 5760 | |
| 5761 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5762 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5763 | DCHECK(rti.IsExact()); |
| 5764 | loaded_class_rti_ = rti; |
| 5765 | } |
| 5766 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5767 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5768 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5769 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5770 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5771 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5772 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5773 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5774 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5775 | return SideEffects::CanTriggerGC(); |
| 5776 | } |
| 5777 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5778 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5779 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5780 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5781 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5782 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5783 | void MarkInBootImage() { |
| 5784 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 5785 | } |
| 5786 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5787 | void AddSpecialInput(HInstruction* special_input); |
| 5788 | |
| 5789 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5790 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5791 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5792 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 5793 | } |
| 5794 | |
| 5795 | Primitive::Type GetType() const OVERRIDE { |
| 5796 | return Primitive::kPrimNot; |
| 5797 | } |
| 5798 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5799 | Handle<mirror::Class> GetClass() const { |
| 5800 | return klass_; |
| 5801 | } |
| 5802 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5803 | DECLARE_INSTRUCTION(LoadClass); |
| 5804 | |
| 5805 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5806 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5807 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5808 | // Whether this instruction must generate the initialization check. |
| 5809 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5810 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5811 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 5812 | static constexpr size_t kFieldLoadKindSize = |
| 5813 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5814 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5815 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5816 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 5817 | |
| 5818 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5819 | return load_kind == LoadKind::kReferrersClass || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5820 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5821 | load_kind == LoadKind::kBssEntry || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5822 | load_kind == LoadKind::kRuntimeCall; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5823 | } |
| 5824 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5825 | void SetLoadKindInternal(LoadKind load_kind); |
| 5826 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5827 | // The special input is the HCurrentMethod for kRuntimeCall or kReferrersClass. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5828 | // 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] | 5829 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5830 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5831 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5832 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 5833 | // - The compiling method's dex file if the class is defined there too. |
| 5834 | // - The compiling method's dex file if the class is referenced there. |
| 5835 | // - The dex file where the class is defined. When the load kind can only be |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5836 | // kBssEntry or kRuntimeCall, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5837 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5838 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5839 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5840 | Handle<mirror::Class> klass_; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5841 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5842 | ReferenceTypeInfo loaded_class_rti_; |
| 5843 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5844 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5845 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5846 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 5847 | |
| 5848 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5849 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5850 | // The special input is used for PC-relative loads on some architectures, |
| 5851 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5852 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5853 | GetLoadKind() == LoadKind::kBootImageAddress || |
| 5854 | GetLoadKind() == LoadKind::kBssEntry) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5855 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5856 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 5857 | special_input->AddUseAt(this, 0); |
| 5858 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5859 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5860 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5861 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5862 | // Determines how to load the String. |
| 5863 | enum class LoadKind { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5864 | // Use PC-relative boot image String* address that will be known at link time. |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5865 | // Used for boot image strings referenced by boot image code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5866 | kBootImageLinkTimePcRelative, |
| 5867 | |
| 5868 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5869 | // 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] | 5870 | kBootImageAddress, |
| 5871 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5872 | // Load from an entry in the .bss section using a PC-relative load. |
| 5873 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 5874 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5875 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5876 | // Load from the root table associated with the JIT compiled method. |
| 5877 | kJitTableAddress, |
| 5878 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5879 | // Load using a simple runtime call. This is the fall-back load kind when |
| 5880 | // the codegen is unable to use another appropriate kind. |
| 5881 | kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5882 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5883 | kLast = kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5884 | }; |
| 5885 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5886 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5887 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5888 | const DexFile& dex_file, |
| 5889 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5890 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5891 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5892 | string_index_(string_index), |
| 5893 | dex_file_(dex_file) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5894 | SetPackedField<LoadKindField>(LoadKind::kRuntimeCall); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5895 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5896 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5897 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5898 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5899 | LoadKind GetLoadKind() const { |
| 5900 | return GetPackedField<LoadKindField>(); |
| 5901 | } |
| 5902 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5903 | const DexFile& GetDexFile() const { |
| 5904 | return dex_file_; |
| 5905 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5906 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5907 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5908 | return string_index_; |
| 5909 | } |
| 5910 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5911 | Handle<mirror::String> GetString() const { |
| 5912 | return string_; |
| 5913 | } |
| 5914 | |
| 5915 | void SetString(Handle<mirror::String> str) { |
| 5916 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5917 | } |
| 5918 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5919 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5920 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5921 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5922 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5923 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5924 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5925 | // Will call the runtime if we need to load the string through |
| 5926 | // the dex cache and the string is not guaranteed to be there yet. |
| 5927 | bool NeedsEnvironment() const OVERRIDE { |
| 5928 | LoadKind load_kind = GetLoadKind(); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5929 | if (load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5930 | load_kind == LoadKind::kBootImageAddress || |
| 5931 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5932 | return false; |
| 5933 | } |
Vladimir Marko | 4d1be49 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 5934 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5935 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5936 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5937 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5938 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5939 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5940 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5941 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5942 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5943 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5944 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5945 | return SideEffects::CanTriggerGC(); |
| 5946 | } |
| 5947 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5948 | void AddSpecialInput(HInstruction* special_input); |
| 5949 | |
| 5950 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5951 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5952 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5953 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5954 | } |
| 5955 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5956 | Primitive::Type GetType() const OVERRIDE { |
| 5957 | return Primitive::kPrimNot; |
| 5958 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5959 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5960 | DECLARE_INSTRUCTION(LoadString); |
| 5961 | |
| 5962 | private: |
Vladimir Marko | 4d1be49 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 5963 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5964 | static constexpr size_t kFieldLoadKindSize = |
| 5965 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5966 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5967 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5968 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5969 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5970 | void SetLoadKindInternal(LoadKind load_kind); |
| 5971 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5972 | // The special input is the HCurrentMethod for kRuntimeCall. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5973 | // 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] | 5974 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5975 | HUserRecord<HInstruction*> special_input_; |
| 5976 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5977 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5978 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5979 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5980 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5981 | |
| 5982 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5983 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5984 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5985 | |
| 5986 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5987 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5988 | // The special input is used for PC-relative loads on some architectures, |
| 5989 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5990 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5991 | GetLoadKind() == LoadKind::kBssEntry || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5992 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5993 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5994 | // so use the GetInputRecords() from the base class to set the input record. |
| 5995 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5996 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5997 | special_input->AddUseAt(this, 0); |
| 5998 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5999 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6000 | /** |
| 6001 | * Performs an initialization check on its Class object input. |
| 6002 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6003 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6004 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 6005 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 6006 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6007 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6008 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 6009 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6010 | SetRawInputAt(0, constant); |
| 6011 | } |
| 6012 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6013 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6014 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6015 | return true; |
| 6016 | } |
| 6017 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6018 | bool NeedsEnvironment() const OVERRIDE { |
| 6019 | // May call runtime to initialize the class. |
| 6020 | return true; |
| 6021 | } |
| 6022 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 6023 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6024 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6025 | HLoadClass* GetLoadClass() const { |
| 6026 | DCHECK(InputAt(0)->IsLoadClass()); |
| 6027 | return InputAt(0)->AsLoadClass(); |
| 6028 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6029 | |
| 6030 | DECLARE_INSTRUCTION(ClinitCheck); |
| 6031 | |
| 6032 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6033 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 6034 | }; |
| 6035 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6036 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6037 | public: |
| 6038 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6039 | ArtField* field, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6040 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6041 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6042 | bool is_volatile, |
| 6043 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6044 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6045 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6046 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 6047 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6048 | field_info_(field, |
| 6049 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6050 | field_type, |
| 6051 | is_volatile, |
| 6052 | field_idx, |
| 6053 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6054 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6055 | SetRawInputAt(0, cls); |
| 6056 | } |
| 6057 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6058 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 6059 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6060 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6061 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 6062 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6063 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6064 | } |
| 6065 | |
| 6066 | size_t ComputeHashCode() const OVERRIDE { |
| 6067 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6068 | } |
| 6069 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6070 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6071 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 6072 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6073 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6074 | |
| 6075 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 6076 | |
| 6077 | private: |
| 6078 | const FieldInfo field_info_; |
| 6079 | |
| 6080 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 6081 | }; |
| 6082 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6083 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6084 | public: |
| 6085 | HStaticFieldSet(HInstruction* cls, |
| 6086 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6087 | ArtField* field, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6088 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6089 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6090 | bool is_volatile, |
| 6091 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6092 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6093 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6094 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 6095 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6096 | field_info_(field, |
| 6097 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6098 | field_type, |
| 6099 | is_volatile, |
| 6100 | field_idx, |
| 6101 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6102 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6103 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6104 | SetRawInputAt(0, cls); |
| 6105 | SetRawInputAt(1, value); |
| 6106 | } |
| 6107 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6108 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6109 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 6110 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6111 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6112 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6113 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6114 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6115 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6116 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6117 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6118 | |
| 6119 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6120 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6121 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6122 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6123 | "Too many packed fields."); |
| 6124 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6125 | const FieldInfo field_info_; |
| 6126 | |
| 6127 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 6128 | }; |
| 6129 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6130 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6131 | public: |
| 6132 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 6133 | Primitive::Type field_type, |
| 6134 | uint32_t field_index, |
| 6135 | uint32_t dex_pc) |
| 6136 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6137 | field_index_(field_index) { |
| 6138 | SetRawInputAt(0, obj); |
| 6139 | } |
| 6140 | |
| 6141 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6142 | bool CanThrow() const OVERRIDE { return true; } |
| 6143 | |
| 6144 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6145 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6146 | |
| 6147 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6148 | |
| 6149 | private: |
| 6150 | const uint32_t field_index_; |
| 6151 | |
| 6152 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 6153 | }; |
| 6154 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6155 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6156 | public: |
| 6157 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6158 | HInstruction* value, |
| 6159 | Primitive::Type field_type, |
| 6160 | uint32_t field_index, |
| 6161 | uint32_t dex_pc) |
| 6162 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6163 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6164 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6165 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6166 | SetRawInputAt(0, obj); |
| 6167 | SetRawInputAt(1, value); |
| 6168 | } |
| 6169 | |
| 6170 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6171 | bool CanThrow() const OVERRIDE { return true; } |
| 6172 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6173 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6174 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6175 | |
| 6176 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6177 | |
| 6178 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6179 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6180 | static constexpr size_t kFieldFieldTypeSize = |
| 6181 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6182 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6183 | kFieldFieldType + kFieldFieldTypeSize; |
| 6184 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6185 | "Too many packed fields."); |
| 6186 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6187 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6188 | const uint32_t field_index_; |
| 6189 | |
| 6190 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 6191 | }; |
| 6192 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6193 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6194 | public: |
| 6195 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 6196 | uint32_t field_index, |
| 6197 | uint32_t dex_pc) |
| 6198 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6199 | field_index_(field_index) { |
| 6200 | } |
| 6201 | |
| 6202 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6203 | bool CanThrow() const OVERRIDE { return true; } |
| 6204 | |
| 6205 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6206 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6207 | |
| 6208 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6209 | |
| 6210 | private: |
| 6211 | const uint32_t field_index_; |
| 6212 | |
| 6213 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 6214 | }; |
| 6215 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6216 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6217 | public: |
| 6218 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 6219 | Primitive::Type field_type, |
| 6220 | uint32_t field_index, |
| 6221 | uint32_t dex_pc) |
| 6222 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6223 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6224 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6225 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6226 | SetRawInputAt(0, value); |
| 6227 | } |
| 6228 | |
| 6229 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6230 | bool CanThrow() const OVERRIDE { return true; } |
| 6231 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6232 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6233 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6234 | |
| 6235 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6236 | |
| 6237 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6238 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6239 | static constexpr size_t kFieldFieldTypeSize = |
| 6240 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6241 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6242 | kFieldFieldType + kFieldFieldTypeSize; |
| 6243 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6244 | "Too many packed fields."); |
| 6245 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6246 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6247 | const uint32_t field_index_; |
| 6248 | |
| 6249 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6250 | }; |
| 6251 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6252 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6253 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6254 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6255 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6256 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6257 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6258 | bool CanBeNull() const OVERRIDE { return false; } |
| 6259 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6260 | DECLARE_INSTRUCTION(LoadException); |
| 6261 | |
| 6262 | private: |
| 6263 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6264 | }; |
| 6265 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6266 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6267 | // 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] | 6268 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6269 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6270 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6271 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6272 | |
| 6273 | DECLARE_INSTRUCTION(ClearException); |
| 6274 | |
| 6275 | private: |
| 6276 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6277 | }; |
| 6278 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6279 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6280 | public: |
| 6281 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6282 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6283 | SetRawInputAt(0, exception); |
| 6284 | } |
| 6285 | |
| 6286 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6287 | |
| 6288 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6289 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6290 | bool CanThrow() const OVERRIDE { return true; } |
| 6291 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6292 | |
| 6293 | DECLARE_INSTRUCTION(Throw); |
| 6294 | |
| 6295 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6296 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6297 | }; |
| 6298 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6299 | /** |
| 6300 | * Implementation strategies for the code generator of a HInstanceOf |
| 6301 | * or `HCheckCast`. |
| 6302 | */ |
| 6303 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6304 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6305 | kExactCheck, // Can do a single class compare. |
| 6306 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6307 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6308 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6309 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6310 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6311 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6312 | }; |
| 6313 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6314 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6315 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6316 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6317 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6318 | HInstanceOf(HInstruction* object, |
| 6319 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6320 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6321 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6322 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6323 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6324 | dex_pc) { |
| 6325 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6326 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6327 | SetRawInputAt(0, object); |
| 6328 | SetRawInputAt(1, constant); |
| 6329 | } |
| 6330 | |
| 6331 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6332 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6333 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6334 | return true; |
| 6335 | } |
| 6336 | |
| 6337 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6338 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6339 | } |
| 6340 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6341 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6342 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6343 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6344 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6345 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6346 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6347 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6348 | // Mips currently does runtime calls for any other checks. |
| 6349 | return check_kind != TypeCheckKind::kExactCheck; |
| 6350 | } |
| 6351 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6352 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6353 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6354 | } |
| 6355 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6356 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6357 | |
| 6358 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6359 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6360 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6361 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6362 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6363 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6364 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6365 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6366 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6367 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6368 | }; |
| 6369 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6370 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6371 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6372 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6373 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6374 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6375 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6376 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6377 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6378 | SetRawInputAt(0, input); |
| 6379 | } |
| 6380 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6381 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6382 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6383 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6384 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6385 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6386 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6387 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6388 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6389 | } |
| 6390 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6391 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6392 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6393 | DECLARE_INSTRUCTION(BoundType); |
| 6394 | |
| 6395 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6396 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6397 | // is false then CanBeNull() cannot be true). |
| 6398 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6399 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6400 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6401 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6402 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6403 | // 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] | 6404 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6405 | // It is used to bound the type in cases like: |
| 6406 | // if (x instanceof ClassX) { |
| 6407 | // // uper_bound_ will be ClassX |
| 6408 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6409 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6410 | |
| 6411 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6412 | }; |
| 6413 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6414 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6415 | public: |
| 6416 | HCheckCast(HInstruction* object, |
| 6417 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6418 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6419 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6420 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6421 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6422 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6423 | SetRawInputAt(0, object); |
| 6424 | SetRawInputAt(1, constant); |
| 6425 | } |
| 6426 | |
| 6427 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6428 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6429 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6430 | return true; |
| 6431 | } |
| 6432 | |
| 6433 | bool NeedsEnvironment() const OVERRIDE { |
| 6434 | // Instruction may throw a CheckCastError. |
| 6435 | return true; |
| 6436 | } |
| 6437 | |
| 6438 | bool CanThrow() const OVERRIDE { return true; } |
| 6439 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6440 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6441 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6442 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6443 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6444 | |
| 6445 | DECLARE_INSTRUCTION(CheckCast); |
| 6446 | |
| 6447 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6448 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6449 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6450 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6451 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6452 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6453 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6454 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6455 | |
| 6456 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6457 | }; |
| 6458 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6459 | /** |
| 6460 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6461 | * @details We define the combined barrier types that are actually required |
| 6462 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6463 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6464 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6465 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6466 | * The current recipe is as follows: |
| 6467 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6468 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6469 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6470 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6471 | * class has final fields. |
| 6472 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6473 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6474 | */ |
| 6475 | enum MemBarrierKind { |
| 6476 | kAnyStore, |
| 6477 | kLoadAny, |
| 6478 | kStoreStore, |
| 6479 | kAnyAny, |
| 6480 | kNTStoreStore, |
| 6481 | kLastBarrierKind = kNTStoreStore |
| 6482 | }; |
| 6483 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6484 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6485 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6486 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6487 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6488 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6489 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6490 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6491 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6492 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6493 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6494 | |
| 6495 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6496 | |
| 6497 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6498 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6499 | static constexpr size_t kFieldBarrierKindSize = |
| 6500 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6501 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6502 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6503 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6504 | "Too many packed fields."); |
| 6505 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6506 | |
| 6507 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6508 | }; |
| 6509 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6510 | // A constructor fence orders all prior stores to fields that could be accessed via a final field of |
| 6511 | // the specified object(s), with respect to any subsequent store that might "publish" |
| 6512 | // (i.e. make visible) the specified object to another thread. |
| 6513 | // |
| 6514 | // JLS 17.5.1 "Semantics of final fields" states that a freeze action happens |
| 6515 | // for all final fields (that were set) at the end of the invoked constructor. |
| 6516 | // |
| 6517 | // The constructor fence models the freeze actions for the final fields of an object |
| 6518 | // being constructed (semantically at the end of the constructor). Constructor fences |
| 6519 | // have a per-object affinity; two separate objects being constructed get two separate |
| 6520 | // constructor fences. |
| 6521 | // |
| 6522 | // (Note: that if calling a super-constructor or forwarding to another constructor, |
| 6523 | // the freezes would happen at the end of *that* constructor being invoked). |
| 6524 | // |
| 6525 | // The memory model guarantees that when the object being constructed is "published" after |
| 6526 | // constructor completion (i.e. escapes the current thread via a store), then any final field |
| 6527 | // writes must be observable on other threads (once they observe that publication). |
| 6528 | // |
| 6529 | // Further, anything written before the freeze, and read by dereferencing through the final field, |
| 6530 | // must also be visible (so final object field could itself have an object with non-final fields; |
| 6531 | // yet the freeze must also extend to them). |
| 6532 | // |
| 6533 | // Constructor example: |
| 6534 | // |
| 6535 | // class HasFinal { |
| 6536 | // final int field; Optimizing IR for <init>()V: |
| 6537 | // HasFinal() { |
| 6538 | // field = 123; HInstanceFieldSet(this, HasFinal.field, 123) |
| 6539 | // // freeze(this.field); HConstructorFence(this) |
| 6540 | // } HReturn |
| 6541 | // } |
| 6542 | // |
| 6543 | // HConstructorFence can serve double duty as a fence for new-instance/new-array allocations of |
| 6544 | // already-initialized classes; in that case the allocation must act as a "default-initializer" |
| 6545 | // of the object which effectively writes the class pointer "final field". |
| 6546 | // |
| 6547 | // For example, we can model default-initialiation as roughly the equivalent of the following: |
| 6548 | // |
| 6549 | // class Object { |
| 6550 | // private final Class header; |
| 6551 | // } |
| 6552 | // |
| 6553 | // Java code: Optimizing IR: |
| 6554 | // |
| 6555 | // T new_instance<T>() { |
| 6556 | // Object obj = allocate_memory(T.class.size); obj = HInvoke(art_quick_alloc_object, T) |
| 6557 | // obj.header = T.class; // header write is done by above call. |
| 6558 | // // freeze(obj.header) HConstructorFence(obj) |
| 6559 | // return (T)obj; |
| 6560 | // } |
| 6561 | // |
| 6562 | // See also: |
| 6563 | // * CompilerDriver::RequiresConstructorBarrier |
| 6564 | // * QuasiAtomic::ThreadFenceForConstructor |
| 6565 | // |
| 6566 | class HConstructorFence FINAL : public HVariableInputSizeInstruction { |
| 6567 | // A fence has variable inputs because the inputs can be removed |
| 6568 | // after prepare_for_register_allocation phase. |
| 6569 | // (TODO: In the future a fence could freeze multiple objects |
| 6570 | // after merging two fences together.) |
| 6571 | public: |
| 6572 | // `fence_object` is the reference that needs to be protected for correct publication. |
| 6573 | // |
| 6574 | // It makes sense in the following situations: |
| 6575 | // * <init> constructors, it's the "this" parameter (i.e. HParameterValue, s.t. IsThis() == true). |
| 6576 | // * new-instance-like instructions, it's the return value (i.e. HNewInstance). |
| 6577 | // |
| 6578 | // After construction the `fence_object` becomes the 0th input. |
| 6579 | // This is not an input in a real sense, but just a convenient place to stash the information |
| 6580 | // about the associated object. |
| 6581 | HConstructorFence(HInstruction* fence_object, |
| 6582 | uint32_t dex_pc, |
| 6583 | ArenaAllocator* arena) |
| 6584 | // We strongly suspect there is not a more accurate way to describe the fine-grained reordering |
| 6585 | // constraints described in the class header. We claim that these SideEffects constraints |
| 6586 | // enforce a superset of the real constraints. |
| 6587 | // |
| 6588 | // The ordering described above is conservatively modeled with SideEffects as follows: |
| 6589 | // |
| 6590 | // * To prevent reordering of the publication stores: |
| 6591 | // ----> "Reads of objects" is the initial SideEffect. |
| 6592 | // * For every primitive final field store in the constructor: |
| 6593 | // ----> Union that field's type as a read (e.g. "Read of T") into the SideEffect. |
| 6594 | // * If there are any stores to reference final fields in the constructor: |
| 6595 | // ----> Use a more conservative "AllReads" SideEffect because any stores to any references |
| 6596 | // that are reachable from `fence_object` also need to be prevented for reordering |
| 6597 | // (and we do not want to do alias analysis to figure out what those stores are). |
| 6598 | // |
| 6599 | // In the implementation, this initially starts out as an "all reads" side effect; this is an |
| 6600 | // even more conservative approach than the one described above, and prevents all of the |
| 6601 | // above reordering without analyzing any of the instructions in the constructor. |
| 6602 | // |
| 6603 | // If in a later phase we discover that there are no writes to reference final fields, |
| 6604 | // we can refine the side effect to a smaller set of type reads (see above constraints). |
| 6605 | : HVariableInputSizeInstruction(SideEffects::AllReads(), |
| 6606 | dex_pc, |
| 6607 | arena, |
| 6608 | /* number_of_inputs */ 1, |
| 6609 | kArenaAllocConstructorFenceInputs) { |
| 6610 | DCHECK(fence_object != nullptr); |
| 6611 | SetRawInputAt(0, fence_object); |
| 6612 | } |
| 6613 | |
| 6614 | // The object associated with this constructor fence. |
| 6615 | // |
| 6616 | // (Note: This will be null after the prepare_for_register_allocation phase, |
| 6617 | // as all constructor fence inputs are removed there). |
| 6618 | HInstruction* GetFenceObject() const { |
| 6619 | return InputAt(0); |
| 6620 | } |
| 6621 | |
| 6622 | // Find all the HConstructorFence uses (`fence_use`) for `this` and: |
| 6623 | // - Delete `fence_use` from `this`'s use list. |
| 6624 | // - Delete `this` from `fence_use`'s inputs list. |
| 6625 | // - If the `fence_use` is dead, remove it from the graph. |
| 6626 | // |
| 6627 | // A fence is considered dead once it no longer has any uses |
| 6628 | // and all of the inputs are dead. |
| 6629 | // |
| 6630 | // This must *not* be called during/after prepare_for_register_allocation, |
| 6631 | // because that removes all the inputs to the fences but the fence is actually |
| 6632 | // still considered live. |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 6633 | // |
| 6634 | // Returns how many HConstructorFence instructions were removed from graph. |
| 6635 | static size_t RemoveConstructorFences(HInstruction* instruction); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6636 | |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame^] | 6637 | // Combine all inputs of `this` and `other` instruction and remove |
| 6638 | // `other` from the graph. |
| 6639 | // |
| 6640 | // Inputs are unique after the merge. |
| 6641 | // |
| 6642 | // Requirement: `this` must not be the same as `other. |
| 6643 | void Merge(HConstructorFence* other); |
| 6644 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 6645 | // Check if this constructor fence is protecting |
| 6646 | // an HNewInstance or HNewArray that is also the immediate |
| 6647 | // predecessor of `this`. |
| 6648 | // |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame^] | 6649 | // If `ignore_inputs` is true, then the immediate predecessor doesn't need |
| 6650 | // to be one of the inputs of `this`. |
| 6651 | // |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 6652 | // Returns the associated HNewArray or HNewInstance, |
| 6653 | // or null otherwise. |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame^] | 6654 | HInstruction* GetAssociatedAllocation(bool ignore_inputs = false); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 6655 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6656 | DECLARE_INSTRUCTION(ConstructorFence); |
| 6657 | |
| 6658 | private: |
| 6659 | DISALLOW_COPY_AND_ASSIGN(HConstructorFence); |
| 6660 | }; |
| 6661 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6662 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6663 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6664 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6665 | kEnter, |
| 6666 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6667 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6668 | }; |
| 6669 | |
| 6670 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6671 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6672 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6673 | dex_pc) { |
| 6674 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6675 | SetRawInputAt(0, object); |
| 6676 | } |
| 6677 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6678 | // Instruction may go into runtime, so we need an environment. |
| 6679 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6680 | |
| 6681 | bool CanThrow() const OVERRIDE { |
| 6682 | // Verifier guarantees that monitor-exit cannot throw. |
| 6683 | // This is important because it allows the HGraphBuilder to remove |
| 6684 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6685 | return IsEnter(); |
| 6686 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6687 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6688 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6689 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6690 | |
| 6691 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6692 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6693 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6694 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6695 | static constexpr size_t kFieldOperationKindSize = |
| 6696 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6697 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6698 | kFieldOperationKind + kFieldOperationKindSize; |
| 6699 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6700 | "Too many packed fields."); |
| 6701 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6702 | |
| 6703 | private: |
| 6704 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6705 | }; |
| 6706 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6707 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6708 | public: |
| 6709 | HSelect(HInstruction* condition, |
| 6710 | HInstruction* true_value, |
| 6711 | HInstruction* false_value, |
| 6712 | uint32_t dex_pc) |
| 6713 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6714 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6715 | |
| 6716 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6717 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6718 | // that architectures which implement HSelect as a conditional move also |
| 6719 | // will not need to invert the condition. |
| 6720 | SetRawInputAt(0, false_value); |
| 6721 | SetRawInputAt(1, true_value); |
| 6722 | SetRawInputAt(2, condition); |
| 6723 | } |
| 6724 | |
| 6725 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6726 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6727 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6728 | |
| 6729 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6730 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6731 | return true; |
| 6732 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6733 | |
| 6734 | bool CanBeNull() const OVERRIDE { |
| 6735 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6736 | } |
| 6737 | |
| 6738 | DECLARE_INSTRUCTION(Select); |
| 6739 | |
| 6740 | private: |
| 6741 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6742 | }; |
| 6743 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6744 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6745 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6746 | MoveOperands(Location source, |
| 6747 | Location destination, |
| 6748 | Primitive::Type type, |
| 6749 | HInstruction* instruction) |
| 6750 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6751 | |
| 6752 | Location GetSource() const { return source_; } |
| 6753 | Location GetDestination() const { return destination_; } |
| 6754 | |
| 6755 | void SetSource(Location value) { source_ = value; } |
| 6756 | void SetDestination(Location value) { destination_ = value; } |
| 6757 | |
| 6758 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6759 | // destination (but not the source). |
| 6760 | Location MarkPending() { |
| 6761 | DCHECK(!IsPending()); |
| 6762 | Location dest = destination_; |
| 6763 | destination_ = Location::NoLocation(); |
| 6764 | return dest; |
| 6765 | } |
| 6766 | |
| 6767 | void ClearPending(Location dest) { |
| 6768 | DCHECK(IsPending()); |
| 6769 | destination_ = dest; |
| 6770 | } |
| 6771 | |
| 6772 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6773 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6774 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6775 | } |
| 6776 | |
| 6777 | // True if this blocks a move from the given location. |
| 6778 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6779 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6780 | } |
| 6781 | |
| 6782 | // A move is redundant if it's been eliminated, if its source and |
| 6783 | // destination are the same, or if its destination is unneeded. |
| 6784 | bool IsRedundant() const { |
| 6785 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6786 | } |
| 6787 | |
| 6788 | // We clear both operands to indicate move that's been eliminated. |
| 6789 | void Eliminate() { |
| 6790 | source_ = destination_ = Location::NoLocation(); |
| 6791 | } |
| 6792 | |
| 6793 | bool IsEliminated() const { |
| 6794 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6795 | return source_.IsInvalid(); |
| 6796 | } |
| 6797 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6798 | Primitive::Type GetType() const { return type_; } |
| 6799 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6800 | bool Is64BitMove() const { |
| 6801 | return Primitive::Is64BitType(type_); |
| 6802 | } |
| 6803 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6804 | HInstruction* GetInstruction() const { return instruction_; } |
| 6805 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6806 | private: |
| 6807 | Location source_; |
| 6808 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6809 | // The type this move is for. |
| 6810 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6811 | // The instruction this move is assocatied with. Null when this move is |
| 6812 | // for moving an input in the expected locations of user (including a phi user). |
| 6813 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6814 | // in the same parallel move. |
| 6815 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6816 | }; |
| 6817 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6818 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6819 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6820 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6821 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6822 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6823 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6824 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6825 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6826 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6827 | moves_.reserve(kDefaultNumberOfMoves); |
| 6828 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6829 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6830 | void AddMove(Location source, |
| 6831 | Location destination, |
| 6832 | Primitive::Type type, |
| 6833 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6834 | DCHECK(source.IsValid()); |
| 6835 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6836 | if (kIsDebugBuild) { |
| 6837 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6838 | for (const MoveOperands& move : moves_) { |
| 6839 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6840 | // Special case the situation where the move is for the spill slot |
| 6841 | // of the instruction. |
| 6842 | if ((GetPrevious() == instruction) |
| 6843 | || ((GetPrevious() == nullptr) |
| 6844 | && instruction->IsPhi() |
| 6845 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6846 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6847 | << "Doing parallel moves for the same instruction."; |
| 6848 | } else { |
| 6849 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6850 | } |
| 6851 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6852 | } |
| 6853 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6854 | for (const MoveOperands& move : moves_) { |
| 6855 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6856 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6857 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6858 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6859 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6860 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6861 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6862 | } |
| 6863 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6864 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6865 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6866 | } |
| 6867 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6868 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6869 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6870 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6871 | |
| 6872 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6873 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6874 | |
| 6875 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6876 | }; |
| 6877 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6878 | } // namespace art |
| 6879 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 6880 | #include "nodes_vector.h" |
| 6881 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6882 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6883 | #include "nodes_shared.h" |
| 6884 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6885 | #ifdef ART_ENABLE_CODEGEN_mips |
| 6886 | #include "nodes_mips.h" |
| 6887 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6888 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6889 | #include "nodes_x86.h" |
| 6890 | #endif |
| 6891 | |
| 6892 | namespace art { |
| 6893 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 6894 | class OptimizingCompilerStats; |
| 6895 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6896 | class HGraphVisitor : public ValueObject { |
| 6897 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 6898 | explicit HGraphVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 6899 | : stats_(stats), |
| 6900 | graph_(graph) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6901 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6902 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6903 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6904 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6905 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6906 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6907 | void VisitInsertionOrder(); |
| 6908 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6909 | // Visit the graph following dominator tree reverse post-order. |
| 6910 | void VisitReversePostOrder(); |
| 6911 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6912 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6913 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6914 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6915 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6916 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6917 | |
| 6918 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6919 | |
| 6920 | #undef DECLARE_VISIT_INSTRUCTION |
| 6921 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 6922 | protected: |
| 6923 | OptimizingCompilerStats* stats_; |
| 6924 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6925 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6926 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6927 | |
| 6928 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6929 | }; |
| 6930 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6931 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6932 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 6933 | explicit HGraphDelegateVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 6934 | : HGraphVisitor(graph, stats) {} |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6935 | virtual ~HGraphDelegateVisitor() {} |
| 6936 | |
| 6937 | // Visit functions that delegate to to super class. |
| 6938 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6939 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6940 | |
| 6941 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6942 | |
| 6943 | #undef DECLARE_VISIT_INSTRUCTION |
| 6944 | |
| 6945 | private: |
| 6946 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6947 | }; |
| 6948 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6949 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6950 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6951 | // block id. |
| 6952 | class HBlocksInLoopIterator : public ValueObject { |
| 6953 | public: |
| 6954 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6955 | : blocks_in_loop_(info.GetBlocks()), |
| 6956 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6957 | index_(0) { |
| 6958 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6959 | Advance(); |
| 6960 | } |
| 6961 | } |
| 6962 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6963 | bool Done() const { return index_ == blocks_.size(); } |
| 6964 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6965 | void Advance() { |
| 6966 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6967 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6968 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6969 | break; |
| 6970 | } |
| 6971 | } |
| 6972 | } |
| 6973 | |
| 6974 | private: |
| 6975 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6976 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6977 | size_t index_; |
| 6978 | |
| 6979 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6980 | }; |
| 6981 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6982 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6983 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6984 | // post order. |
| 6985 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6986 | public: |
| 6987 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6988 | : blocks_in_loop_(info.GetBlocks()), |
| 6989 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6990 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6991 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6992 | Advance(); |
| 6993 | } |
| 6994 | } |
| 6995 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6996 | bool Done() const { return index_ == blocks_.size(); } |
| 6997 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6998 | void Advance() { |
| 6999 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7000 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 7001 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7002 | break; |
| 7003 | } |
| 7004 | } |
| 7005 | } |
| 7006 | |
| 7007 | private: |
| 7008 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7009 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7010 | size_t index_; |
| 7011 | |
| 7012 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 7013 | }; |
| 7014 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7015 | // Returns int64_t value of a properly typed constant. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7016 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7017 | if (constant->IsIntConstant()) { |
| 7018 | return constant->AsIntConstant()->GetValue(); |
| 7019 | } else if (constant->IsLongConstant()) { |
| 7020 | return constant->AsLongConstant()->GetValue(); |
| 7021 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 7022 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7023 | return 0; |
| 7024 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7025 | } |
| 7026 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7027 | // Returns true iff instruction is an integral constant (and sets value on success). |
| 7028 | inline bool IsInt64AndGet(HInstruction* instruction, /*out*/ int64_t* value) { |
| 7029 | if (instruction->IsIntConstant()) { |
| 7030 | *value = instruction->AsIntConstant()->GetValue(); |
| 7031 | return true; |
| 7032 | } else if (instruction->IsLongConstant()) { |
| 7033 | *value = instruction->AsLongConstant()->GetValue(); |
| 7034 | return true; |
| 7035 | } else if (instruction->IsNullConstant()) { |
| 7036 | *value = 0; |
| 7037 | return true; |
| 7038 | } |
| 7039 | return false; |
| 7040 | } |
| 7041 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7042 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 7043 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 7044 | inline const H##type* HInstruction::As##type() const { \ |
| 7045 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 7046 | } \ |
| 7047 | inline H##type* HInstruction::As##type() { \ |
| 7048 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 7049 | } |
| 7050 | |
| 7051 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7052 | #undef INSTRUCTION_TYPE_CHECK |
| 7053 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 7054 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 7055 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 7056 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 7057 | size_t number_of_new_blocks, |
| 7058 | size_t after) { |
| 7059 | DCHECK_LT(after, blocks->size()); |
| 7060 | size_t old_size = blocks->size(); |
| 7061 | size_t new_size = old_size + number_of_new_blocks; |
| 7062 | blocks->resize(new_size); |
| 7063 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 7064 | } |
| 7065 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7066 | /* |
| 7067 | * Hunt "under the hood" of array lengths (leading to array references), |
| 7068 | * null checks (also leading to array references), and new arrays |
| 7069 | * (leading to the actual length). This makes it more likely related |
| 7070 | * instructions become actually comparable. |
| 7071 | */ |
| 7072 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 7073 | while (instruction->IsArrayLength() || |
| 7074 | instruction->IsNullCheck() || |
| 7075 | instruction->IsNewArray()) { |
| 7076 | instruction = instruction->IsNewArray() |
| 7077 | ? instruction->AsNewArray()->GetLength() |
| 7078 | : instruction->InputAt(0); |
| 7079 | } |
| 7080 | return instruction; |
| 7081 | } |
| 7082 | |
Artem Serov | 21c7e6f | 2017-07-27 16:04:42 +0100 | [diff] [blame] | 7083 | void RemoveEnvironmentUses(HInstruction* instruction); |
| 7084 | bool HasEnvironmentUsedByOthers(HInstruction* instruction); |
| 7085 | void ResetEnvironmentInputRecords(HInstruction* instruction); |
| 7086 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7087 | } // namespace art |
| 7088 | |
| 7089 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |