Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_NODES_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_NODES_H_ |
| 19 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 20 | #include <algorithm> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 21 | #include <array> |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 22 | #include <type_traits> |
| 23 | |
Mathieu Chartier | e5d80f8 | 2015-10-15 17:47:48 -0700 | [diff] [blame] | 24 | #include "base/arena_bit_vector.h" |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 25 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 26 | #include "base/arena_object.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 27 | #include "base/array_ref.h" |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 28 | #include "base/iteration_range.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 29 | #include "base/stl_util.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 30 | #include "base/transform_array_ref.h" |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 31 | #include "dex_file.h" |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 32 | #include "dex_file_types.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 33 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 34 | #include "handle.h" |
| 35 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 36 | #include "invoke_type.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 37 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 38 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 39 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 40 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 41 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 42 | #include "primitive.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 43 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 44 | |
| 45 | namespace art { |
| 46 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 47 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 48 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 49 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 50 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 51 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 52 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 53 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 54 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 55 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 56 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 57 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 58 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 59 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 60 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 61 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 62 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 63 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 64 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 65 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 66 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 67 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 68 | namespace mirror { |
| 69 | class DexCache; |
| 70 | } // namespace mirror |
| 71 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 72 | static const int kDefaultNumberOfBlocks = 8; |
| 73 | static const int kDefaultNumberOfSuccessors = 2; |
| 74 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 75 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 76 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 77 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 78 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 79 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 80 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 81 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 82 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 83 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 84 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 85 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 86 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 87 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 88 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 89 | static constexpr uint32_t kNoDexPc = -1; |
| 90 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 91 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 92 | // For the purposes of the compiler, the dex files must actually be the same object |
| 93 | // if we want to safely treat them as the same. This is especially important for JIT |
| 94 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 95 | // times and provide different class resolution but no two class loaders should ever |
| 96 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 97 | // all sorts of weird failures. |
| 98 | return &lhs == &rhs; |
| 99 | } |
| 100 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 101 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 102 | // All types. |
| 103 | kCondEQ, // == |
| 104 | kCondNE, // != |
| 105 | // Signed integers and floating-point numbers. |
| 106 | kCondLT, // < |
| 107 | kCondLE, // <= |
| 108 | kCondGT, // > |
| 109 | kCondGE, // >= |
| 110 | // Unsigned integers. |
| 111 | kCondB, // < |
| 112 | kCondBE, // <= |
| 113 | kCondA, // > |
| 114 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 115 | // First and last aliases. |
| 116 | kCondFirst = kCondEQ, |
| 117 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 120 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 121 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 122 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 123 | kAnalysisFailThrowCatchLoop, |
| 124 | kAnalysisFailAmbiguousArrayOp, |
| 125 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 128 | template <typename T> |
| 129 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 130 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 131 | } |
| 132 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 133 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 134 | public: |
| 135 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 136 | |
| 137 | void AddInstruction(HInstruction* instruction); |
| 138 | void RemoveInstruction(HInstruction* instruction); |
| 139 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 140 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 141 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 142 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 143 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 144 | // Return true if this list contains `instruction`. |
| 145 | bool Contains(HInstruction* instruction) const; |
| 146 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 147 | // Return true if `instruction1` is found before `instruction2` in |
| 148 | // this instruction list and false otherwise. Abort if none |
| 149 | // of these instructions is found. |
| 150 | bool FoundBefore(const HInstruction* instruction1, |
| 151 | const HInstruction* instruction2) const; |
| 152 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 153 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 154 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 155 | |
| 156 | // Update the block of all instructions to be `block`. |
| 157 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 158 | |
| 159 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 160 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 161 | void Add(const HInstructionList& instruction_list); |
| 162 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 163 | // Return the number of instructions in the list. This is an expensive operation. |
| 164 | size_t CountSize() const; |
| 165 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 166 | private: |
| 167 | HInstruction* first_instruction_; |
| 168 | HInstruction* last_instruction_; |
| 169 | |
| 170 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 171 | friend class HGraph; |
| 172 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 173 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 174 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 175 | |
| 176 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 177 | }; |
| 178 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 179 | class ReferenceTypeInfo : ValueObject { |
| 180 | public: |
| 181 | typedef Handle<mirror::Class> TypeHandle; |
| 182 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 183 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 184 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 185 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 186 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 187 | } |
| 188 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 189 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 190 | return ReferenceTypeInfo(type_handle, is_exact); |
| 191 | } |
| 192 | |
| 193 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 194 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 195 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 196 | return handle.GetReference() != nullptr; |
| 197 | } |
| 198 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 199 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 200 | return IsValidHandle(type_handle_); |
| 201 | } |
| 202 | |
| 203 | bool IsExact() const { return is_exact_; } |
| 204 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 205 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 206 | DCHECK(IsValid()); |
| 207 | return GetTypeHandle()->IsObjectClass(); |
| 208 | } |
| 209 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 210 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 211 | DCHECK(IsValid()); |
| 212 | return GetTypeHandle()->IsStringClass(); |
| 213 | } |
| 214 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 215 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 216 | DCHECK(IsValid()); |
| 217 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 218 | } |
| 219 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 220 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 221 | DCHECK(IsValid()); |
| 222 | return GetTypeHandle()->IsInterface(); |
| 223 | } |
| 224 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 225 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 226 | DCHECK(IsValid()); |
| 227 | return GetTypeHandle()->IsArrayClass(); |
| 228 | } |
| 229 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 230 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 231 | DCHECK(IsValid()); |
| 232 | return GetTypeHandle()->IsPrimitiveArray(); |
| 233 | } |
| 234 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 235 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 236 | DCHECK(IsValid()); |
| 237 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 238 | } |
| 239 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 240 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 241 | DCHECK(IsValid()); |
| 242 | if (!IsExact()) return false; |
| 243 | if (!IsArrayClass()) return false; |
| 244 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 245 | } |
| 246 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 247 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 248 | DCHECK(IsValid()); |
| 249 | if (!IsExact()) return false; |
| 250 | if (!IsArrayClass()) return false; |
| 251 | if (!rti.IsArrayClass()) return false; |
| 252 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 253 | rti.GetTypeHandle()->GetComponentType()); |
| 254 | } |
| 255 | |
| 256 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 257 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 258 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 259 | DCHECK(IsValid()); |
| 260 | DCHECK(rti.IsValid()); |
| 261 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 262 | } |
| 263 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 264 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 265 | DCHECK(IsValid()); |
| 266 | DCHECK(rti.IsValid()); |
| 267 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 268 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 269 | } |
| 270 | |
| 271 | // Returns true if the type information provide the same amount of details. |
| 272 | // Note that it does not mean that the instructions have the same actual type |
| 273 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 274 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 275 | if (!IsValid() && !rti.IsValid()) { |
| 276 | // Invalid types are equal. |
| 277 | return true; |
| 278 | } |
| 279 | if (!IsValid() || !rti.IsValid()) { |
| 280 | // One is valid, the other not. |
| 281 | return false; |
| 282 | } |
| 283 | return IsExact() == rti.IsExact() |
| 284 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 285 | } |
| 286 | |
| 287 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 288 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 289 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 290 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 291 | |
| 292 | // The class of the object. |
| 293 | TypeHandle type_handle_; |
| 294 | // Whether or not the type is exact or a superclass of the actual type. |
| 295 | // Whether or not we have any information about this type. |
| 296 | bool is_exact_; |
| 297 | }; |
| 298 | |
| 299 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 300 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 301 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 302 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 303 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 304 | HGraph(ArenaAllocator* arena, |
| 305 | const DexFile& dex_file, |
| 306 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 307 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 308 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 309 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 310 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 311 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 312 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 313 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 314 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 315 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 316 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 317 | entry_block_(nullptr), |
| 318 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 319 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 320 | number_of_vregs_(0), |
| 321 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 322 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 323 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 324 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 325 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 326 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 327 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 328 | dex_file_(dex_file), |
| 329 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 330 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 331 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 332 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 333 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 334 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 335 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 336 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 337 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 338 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 339 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 340 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 341 | osr_(osr), |
| 342 | cha_single_implementation_list_(arena->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 343 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 344 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 345 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 346 | // 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] | 347 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 348 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 349 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 350 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 351 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 352 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 353 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 354 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 355 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 356 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 357 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 358 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 359 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 360 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 361 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 362 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 363 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 364 | void ComputeDominanceInformation(); |
| 365 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 366 | void ClearLoopInformation(); |
| 367 | void FindBackEdges(ArenaBitVector* visited); |
| 368 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 369 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 370 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 371 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 372 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 373 | // 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] | 374 | // 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] | 375 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 376 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 377 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 378 | // order and loop information. |
| 379 | void ComputeTryBlockInformation(); |
| 380 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 381 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 382 | // Returns the instruction to replace the invoke expression or null if the |
| 383 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 384 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 385 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 386 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 387 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 388 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 389 | // should be the new back edge. |
| 390 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 391 | HBasicBlock* reference, |
| 392 | bool replace_if_back_edge); |
| 393 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 394 | // Need to add a couple of blocks to test if the loop body is entered and |
| 395 | // put deoptimization instructions, etc. |
| 396 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 397 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 398 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 399 | // other blocks and has no instructions or phis. |
| 400 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 401 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 402 | // Splits the edge between `block` and `successor` while preserving the |
| 403 | // indices in the predecessor/successor lists. If there are multiple edges |
| 404 | // between the blocks, the lowest indices are used. |
| 405 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 406 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 407 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 408 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 409 | void SimplifyLoop(HBasicBlock* header); |
| 410 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 411 | int32_t GetNextInstructionId() { |
| 412 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 413 | return current_instruction_id_++; |
| 414 | } |
| 415 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 416 | int32_t GetCurrentInstructionId() const { |
| 417 | return current_instruction_id_; |
| 418 | } |
| 419 | |
| 420 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 421 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 422 | current_instruction_id_ = id; |
| 423 | } |
| 424 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 425 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 426 | return maximum_number_of_out_vregs_; |
| 427 | } |
| 428 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 429 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 430 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 431 | } |
| 432 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 433 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 434 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 435 | } |
| 436 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 437 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 438 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 439 | } |
| 440 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 441 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 442 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 443 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 444 | } |
| 445 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 446 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 447 | number_of_vregs_ = number_of_vregs; |
| 448 | } |
| 449 | |
| 450 | uint16_t GetNumberOfVRegs() const { |
| 451 | return number_of_vregs_; |
| 452 | } |
| 453 | |
| 454 | void SetNumberOfInVRegs(uint16_t value) { |
| 455 | number_of_in_vregs_ = value; |
| 456 | } |
| 457 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 458 | uint16_t GetNumberOfInVRegs() const { |
| 459 | return number_of_in_vregs_; |
| 460 | } |
| 461 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 462 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 463 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 464 | return number_of_vregs_ - number_of_in_vregs_; |
| 465 | } |
| 466 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 467 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 468 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 469 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 470 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 471 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 472 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 473 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 474 | } |
| 475 | |
| 476 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 477 | return ReverseRange(GetReversePostOrder()); |
| 478 | } |
| 479 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 480 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 481 | return linear_order_; |
| 482 | } |
| 483 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 484 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 485 | return ReverseRange(GetLinearOrder()); |
| 486 | } |
| 487 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 488 | bool HasBoundsChecks() const { |
| 489 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 490 | } |
| 491 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 492 | void SetHasBoundsChecks(bool value) { |
| 493 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 494 | } |
| 495 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 496 | bool ShouldGenerateConstructorBarrier() const { |
| 497 | return should_generate_constructor_barrier_; |
| 498 | } |
| 499 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 500 | bool IsDebuggable() const { return debuggable_; } |
| 501 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 502 | // 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] | 503 | // already, it is created and inserted into the graph. This method is only for |
| 504 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 505 | 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] | 506 | |
| 507 | // TODO: This is problematic for the consistency of reference type propagation |
| 508 | // because it can be created anytime after the pass and thus it will be left |
| 509 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 510 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 511 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 512 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 513 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 514 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 515 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 516 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 517 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 518 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 519 | 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] | 520 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 521 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 522 | 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] | 523 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 524 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 525 | HCurrentMethod* GetCurrentMethod(); |
| 526 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 527 | const DexFile& GetDexFile() const { |
| 528 | return dex_file_; |
| 529 | } |
| 530 | |
| 531 | uint32_t GetMethodIdx() const { |
| 532 | return method_idx_; |
| 533 | } |
| 534 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 535 | InvokeType GetInvokeType() const { |
| 536 | return invoke_type_; |
| 537 | } |
| 538 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 539 | InstructionSet GetInstructionSet() const { |
| 540 | return instruction_set_; |
| 541 | } |
| 542 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 543 | bool IsCompilingOsr() const { return osr_; } |
| 544 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 545 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 546 | return cha_single_implementation_list_; |
| 547 | } |
| 548 | |
| 549 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 550 | cha_single_implementation_list_.insert(method); |
| 551 | } |
| 552 | |
| 553 | bool HasShouldDeoptimizeFlag() const { |
| 554 | // TODO: if all CHA guards can be eliminated, there is no need for the flag |
| 555 | // even if cha_single_implementation_list_ is not empty. |
| 556 | return !cha_single_implementation_list_.empty(); |
| 557 | } |
| 558 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 559 | bool HasTryCatch() const { return has_try_catch_; } |
| 560 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 561 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 562 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 563 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 564 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 565 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 566 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 567 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 568 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 569 | // The instruction has been inserted into the graph, either as a constant, or |
| 570 | // before cursor. |
| 571 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 572 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 573 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 574 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 575 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 576 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 577 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 578 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 579 | template <class InstructionType, typename ValueType> |
| 580 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 581 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 582 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 583 | // Try to find an existing constant of the given value. |
| 584 | InstructionType* constant = nullptr; |
| 585 | auto cached_constant = cache->find(value); |
| 586 | if (cached_constant != cache->end()) { |
| 587 | constant = cached_constant->second; |
| 588 | } |
| 589 | |
| 590 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 591 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 592 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 593 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 594 | cache->Overwrite(value, constant); |
| 595 | InsertConstant(constant); |
| 596 | } |
| 597 | return constant; |
| 598 | } |
| 599 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 600 | void InsertConstant(HConstant* instruction); |
| 601 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 602 | // Cache a float constant into the graph. This method should only be |
| 603 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 604 | void CacheFloatConstant(HFloatConstant* constant); |
| 605 | |
| 606 | // See CacheFloatConstant comment. |
| 607 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 608 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 609 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 610 | |
| 611 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 612 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 613 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 614 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 615 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 616 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 617 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 618 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 619 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 620 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 621 | HBasicBlock* entry_block_; |
| 622 | HBasicBlock* exit_block_; |
| 623 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 624 | // 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] | 625 | uint16_t maximum_number_of_out_vregs_; |
| 626 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 627 | // The number of virtual registers in this method. Contains the parameters. |
| 628 | uint16_t number_of_vregs_; |
| 629 | |
| 630 | // The number of virtual registers used by parameters of this method. |
| 631 | uint16_t number_of_in_vregs_; |
| 632 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 633 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 634 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 635 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 636 | // Has bounds checks. We can totally skip BCE if it's false. |
| 637 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 638 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 639 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 640 | // try/catch-related passes if false. |
| 641 | bool has_try_catch_; |
| 642 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 643 | // Flag whether there are any irreducible loops in the graph. |
| 644 | bool has_irreducible_loops_; |
| 645 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 646 | // Indicates whether the graph should be compiled in a way that |
| 647 | // ensures full debuggability. If false, we can apply more |
| 648 | // aggressive optimizations that may limit the level of debugging. |
| 649 | const bool debuggable_; |
| 650 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 651 | // 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] | 652 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 653 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 654 | // The dex file from which the method is from. |
| 655 | const DexFile& dex_file_; |
| 656 | |
| 657 | // The method index in the dex file. |
| 658 | const uint32_t method_idx_; |
| 659 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 660 | // If inlined, this encodes how the callee is being invoked. |
| 661 | const InvokeType invoke_type_; |
| 662 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 663 | // Whether the graph has been transformed to SSA form. Only used |
| 664 | // in debug mode to ensure we are not using properties only valid |
| 665 | // for non-SSA form (like the number of temporaries). |
| 666 | bool in_ssa_form_; |
| 667 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 668 | const bool should_generate_constructor_barrier_; |
| 669 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 670 | const InstructionSet instruction_set_; |
| 671 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 672 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 673 | HNullConstant* cached_null_constant_; |
| 674 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 675 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 676 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 677 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 678 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 679 | HCurrentMethod* cached_current_method_; |
| 680 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 681 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 682 | // for example for methods whose declaring class could not be resolved |
| 683 | // (such as when the superclass could not be found). |
| 684 | ArtMethod* art_method_; |
| 685 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 686 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 687 | // collection pointer to passes which may create NullConstant. |
| 688 | ReferenceTypeInfo inexact_object_rti_; |
| 689 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 690 | // Whether we are compiling this graph for on stack replacement: this will |
| 691 | // make all loops seen as irreducible and emit special stack maps to mark |
| 692 | // compiled code entries which the interpreter can directly jump to. |
| 693 | const bool osr_; |
| 694 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 695 | // List of methods that are assumed to have single implementation. |
| 696 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 697 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 698 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 699 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 700 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 701 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 702 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 703 | }; |
| 704 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 705 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 706 | public: |
| 707 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 708 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 709 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 710 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 711 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 712 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 713 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 714 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 715 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 716 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 717 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 718 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 719 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 720 | |
| 721 | void Dump(std::ostream& os); |
| 722 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 723 | HBasicBlock* GetHeader() const { |
| 724 | return header_; |
| 725 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 726 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 727 | void SetHeader(HBasicBlock* block) { |
| 728 | header_ = block; |
| 729 | } |
| 730 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 731 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 732 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 733 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 734 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 735 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 736 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 737 | } |
| 738 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 739 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 740 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 741 | } |
| 742 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 743 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 744 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 745 | } |
| 746 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 747 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 748 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 751 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 752 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 753 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 754 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 755 | } |
| 756 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 757 | // Returns the lifetime position of the back edge that has the |
| 758 | // greatest lifetime position. |
| 759 | size_t GetLifetimeEnd() const; |
| 760 | |
| 761 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 762 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 763 | } |
| 764 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 765 | // Finds blocks that are part of this loop. |
| 766 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 767 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 768 | // Returns whether this loop information contains `block`. |
| 769 | // Note that this loop information *must* be populated before entering this function. |
| 770 | bool Contains(const HBasicBlock& block) const; |
| 771 | |
| 772 | // Returns whether this loop information is an inner loop of `other`. |
| 773 | // Note that `other` *must* be populated before entering this function. |
| 774 | bool IsIn(const HLoopInformation& other) const; |
| 775 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 776 | // Returns true if instruction is not defined within this loop. |
| 777 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 778 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 779 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 780 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 781 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 782 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 783 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 784 | void ClearAllBlocks() { |
| 785 | blocks_.ClearAllBits(); |
| 786 | } |
| 787 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 788 | bool HasBackEdgeNotDominatedByHeader() const; |
| 789 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 790 | bool IsPopulated() const { |
| 791 | return blocks_.GetHighestBitSet() != -1; |
| 792 | } |
| 793 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 794 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 795 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 796 | bool HasExitEdge() const; |
| 797 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 798 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 799 | // Internal recursive implementation of `Populate`. |
| 800 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 801 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 802 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 803 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 804 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 805 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 806 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 807 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 808 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 809 | |
| 810 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 811 | }; |
| 812 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 813 | // Stores try/catch information for basic blocks. |
| 814 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 815 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 816 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 817 | public: |
| 818 | // Try block information constructor. |
| 819 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 820 | : try_entry_(&try_entry), |
| 821 | catch_dex_file_(nullptr), |
| 822 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 823 | DCHECK(try_entry_ != nullptr); |
| 824 | } |
| 825 | |
| 826 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 827 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 828 | : try_entry_(nullptr), |
| 829 | catch_dex_file_(&dex_file), |
| 830 | catch_type_index_(catch_type_index) {} |
| 831 | |
| 832 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 833 | |
| 834 | const HTryBoundary& GetTryEntry() const { |
| 835 | DCHECK(IsTryBlock()); |
| 836 | return *try_entry_; |
| 837 | } |
| 838 | |
| 839 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 840 | |
| 841 | bool IsCatchAllTypeIndex() const { |
| 842 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 843 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 844 | } |
| 845 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 846 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 847 | DCHECK(IsCatchBlock()); |
| 848 | return catch_type_index_; |
| 849 | } |
| 850 | |
| 851 | const DexFile& GetCatchDexFile() const { |
| 852 | DCHECK(IsCatchBlock()); |
| 853 | return *catch_dex_file_; |
| 854 | } |
| 855 | |
| 856 | private: |
| 857 | // One of possibly several TryBoundary instructions entering the block's try. |
| 858 | // Only set for try blocks. |
| 859 | const HTryBoundary* try_entry_; |
| 860 | |
| 861 | // Exception type information. Only set for catch blocks. |
| 862 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 863 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 864 | }; |
| 865 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 866 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 867 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 868 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 869 | // A block in a method. Contains the list of instructions represented |
| 870 | // as a double linked list. Each block knows its predecessors and |
| 871 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 872 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 873 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 874 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 875 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 876 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 877 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 878 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 879 | loop_information_(nullptr), |
| 880 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 881 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 882 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 883 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 884 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 885 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 886 | try_catch_information_(nullptr) { |
| 887 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 888 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 889 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 890 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 891 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 892 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 893 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 896 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 897 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 898 | } |
| 899 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 900 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 901 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 902 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 903 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 904 | return ContainsElement(successors_, block, start_from); |
| 905 | } |
| 906 | |
| 907 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 908 | return dominated_blocks_; |
| 909 | } |
| 910 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 911 | bool IsEntryBlock() const { |
| 912 | return graph_->GetEntryBlock() == this; |
| 913 | } |
| 914 | |
| 915 | bool IsExitBlock() const { |
| 916 | return graph_->GetExitBlock() == this; |
| 917 | } |
| 918 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 919 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 920 | bool IsSingleTryBoundary() const; |
| 921 | |
| 922 | // Returns true if this block emits nothing but a jump. |
| 923 | bool IsSingleJump() const { |
| 924 | HLoopInformation* loop_info = GetLoopInformation(); |
| 925 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 926 | // Back edges generate a suspend check. |
| 927 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 928 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 929 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 930 | void AddBackEdge(HBasicBlock* back_edge) { |
| 931 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 932 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 933 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 934 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 935 | loop_information_->AddBackEdge(back_edge); |
| 936 | } |
| 937 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 938 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 939 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 940 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 941 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 942 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 943 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 944 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 945 | HBasicBlock* GetDominator() const { return dominator_; } |
| 946 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 947 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 948 | |
| 949 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 950 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 951 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 952 | |
| 953 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 954 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 955 | } |
| 956 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 957 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 958 | |
| 959 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 960 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 963 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 964 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 965 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 966 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 967 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 968 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 969 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 970 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 971 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 972 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 973 | successors_.push_back(block); |
| 974 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 975 | } |
| 976 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 977 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 978 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 979 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 980 | new_block->predecessors_.push_back(this); |
| 981 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 982 | } |
| 983 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 984 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 985 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 986 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 987 | new_block->successors_.push_back(this); |
| 988 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 991 | // Insert `this` between `predecessor` and `successor. This method |
| 992 | // preserves the indicies, and will update the first edge found between |
| 993 | // `predecessor` and `successor`. |
| 994 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 995 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 996 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 997 | successor->predecessors_[predecessor_index] = this; |
| 998 | predecessor->successors_[successor_index] = this; |
| 999 | successors_.push_back(successor); |
| 1000 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1001 | } |
| 1002 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1003 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1004 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1005 | } |
| 1006 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1007 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1008 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1011 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1012 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1016 | predecessors_.push_back(block); |
| 1017 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1018 | } |
| 1019 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1020 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1021 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1022 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1023 | } |
| 1024 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1025 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1026 | DCHECK_EQ(successors_.size(), 2u); |
| 1027 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1028 | } |
| 1029 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1030 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1031 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1032 | } |
| 1033 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1034 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1035 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1036 | } |
| 1037 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1038 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1039 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1040 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1044 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1045 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1049 | // predecessors is at index `idx`. |
| 1050 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1051 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1052 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1053 | } |
| 1054 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1055 | // Create a new block between this block and its predecessors. The new block |
| 1056 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1057 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1058 | // loop and try/catch information are not updated. |
| 1059 | HBasicBlock* CreateImmediateDominator(); |
| 1060 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1061 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1062 | // created, latter block. Note that this method will add the block to the |
| 1063 | // graph, create a Goto at the end of the former block and will create an edge |
| 1064 | // 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] | 1065 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1066 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1067 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1068 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1069 | // created block. Note that this method just updates raw block information, |
| 1070 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1071 | // update the graph, reverse post order, loop information, nor make sure the |
| 1072 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1073 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1074 | |
| 1075 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1076 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1077 | |
| 1078 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1079 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1080 | // that this method does not update the graph, reverse post order, loop |
| 1081 | // information, nor make sure the blocks are consistent (for example ending |
| 1082 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1083 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1084 | |
| 1085 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1086 | // of `this` are moved to `other`. |
| 1087 | // Note that this method does not update the graph, reverse post order, loop |
| 1088 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1089 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1090 | void ReplaceWith(HBasicBlock* other); |
| 1091 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1092 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1093 | // order, links to predecessors, successors, dominators and deletes the block |
| 1094 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1095 | // predecessor of `other` and vice versa. |
| 1096 | void MergeWith(HBasicBlock* other); |
| 1097 | |
| 1098 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1099 | // removes it from all loops it is included in and eventually from the graph. |
| 1100 | // The block must not dominate any other block. Predecessors and successors |
| 1101 | // are safely updated. |
| 1102 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1103 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1104 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1105 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1106 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1107 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1108 | // Replace instruction `initial` with `replacement` within this block. |
| 1109 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1110 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1111 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1112 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1113 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1114 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1115 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1116 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1117 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1118 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1119 | |
| 1120 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1121 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1122 | } |
| 1123 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1124 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1125 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1126 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1129 | bool IsFirstPredecessorBackEdge() const { |
| 1130 | DCHECK(IsLoopHeader()); |
| 1131 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1132 | } |
| 1133 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1134 | HLoopInformation* GetLoopInformation() const { |
| 1135 | return loop_information_; |
| 1136 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1137 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1138 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1139 | // 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] | 1140 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1141 | void SetInLoop(HLoopInformation* info) { |
| 1142 | if (IsLoopHeader()) { |
| 1143 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1144 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1145 | loop_information_ = info; |
| 1146 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1147 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1148 | // Note that a non loop header having a loop information means this loop information |
| 1149 | // has already been populated |
| 1150 | loop_information_ = info; |
| 1151 | } else { |
| 1152 | // Block is part of an inner loop. Do not update the loop information. |
| 1153 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1154 | // at this point, because this method is being called while populating `info`. |
| 1155 | } |
| 1156 | } |
| 1157 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1158 | // Raw update of the loop information. |
| 1159 | void SetLoopInformation(HLoopInformation* info) { |
| 1160 | loop_information_ = info; |
| 1161 | } |
| 1162 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1163 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1164 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1165 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1166 | |
| 1167 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1168 | try_catch_information_ = try_catch_information; |
| 1169 | } |
| 1170 | |
| 1171 | bool IsTryBlock() const { |
| 1172 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1173 | } |
| 1174 | |
| 1175 | bool IsCatchBlock() const { |
| 1176 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1177 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1178 | |
| 1179 | // Returns the try entry that this block's successors should have. They will |
| 1180 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1181 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1182 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1183 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1184 | bool HasThrowingInstructions() const; |
| 1185 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1186 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1187 | bool Dominates(HBasicBlock* block) const; |
| 1188 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1189 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1190 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1191 | |
| 1192 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1193 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1194 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1195 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1196 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1197 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1198 | bool HasSinglePhi() const; |
| 1199 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1200 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1201 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1202 | ArenaVector<HBasicBlock*> predecessors_; |
| 1203 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1204 | HInstructionList instructions_; |
| 1205 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1206 | HLoopInformation* loop_information_; |
| 1207 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1208 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1209 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1210 | // The dex program counter of the first instruction of this block. |
| 1211 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1212 | size_t lifetime_start_; |
| 1213 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1214 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1215 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1216 | friend class HGraph; |
| 1217 | friend class HInstruction; |
| 1218 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1219 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1220 | }; |
| 1221 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1222 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1223 | // from the innermost to the outermost. |
| 1224 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1225 | public: |
| 1226 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1227 | : current_(block.GetLoopInformation()) {} |
| 1228 | |
| 1229 | bool Done() const { return current_ == nullptr; } |
| 1230 | |
| 1231 | void Advance() { |
| 1232 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1233 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | HLoopInformation* Current() const { |
| 1237 | DCHECK(!Done()); |
| 1238 | return current_; |
| 1239 | } |
| 1240 | |
| 1241 | private: |
| 1242 | HLoopInformation* current_; |
| 1243 | |
| 1244 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1245 | }; |
| 1246 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1247 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1248 | M(Above, Condition) \ |
| 1249 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1250 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1251 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1252 | M(ArrayGet, Instruction) \ |
| 1253 | M(ArrayLength, Instruction) \ |
| 1254 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1255 | M(Below, Condition) \ |
| 1256 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1257 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1258 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1259 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1260 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1261 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1262 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1263 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1264 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1265 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1266 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1267 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1268 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1269 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1270 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1271 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1272 | M(Exit, Instruction) \ |
| 1273 | M(FloatConstant, Constant) \ |
| 1274 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1275 | M(GreaterThan, Condition) \ |
| 1276 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1277 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1278 | M(InstanceFieldGet, Instruction) \ |
| 1279 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1280 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1281 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1282 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1283 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1284 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1285 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1286 | M(LessThan, Condition) \ |
| 1287 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1288 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1289 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1290 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1291 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1292 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1293 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1294 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1295 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1296 | M(Neg, UnaryOperation) \ |
| 1297 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1298 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1299 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1300 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1301 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1302 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1303 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1304 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1305 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1306 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1307 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1308 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1309 | M(Return, Instruction) \ |
| 1310 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1311 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1312 | M(Shl, BinaryOperation) \ |
| 1313 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1314 | M(StaticFieldGet, Instruction) \ |
| 1315 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1316 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1317 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1318 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1319 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1320 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1321 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1322 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1323 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1324 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1325 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1326 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1327 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1328 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1329 | /* |
| 1330 | * Instructions, shared across several (not all) architectures. |
| 1331 | */ |
| 1332 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1333 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1334 | #else |
| 1335 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1336 | M(BitwiseNegatedRight, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1337 | M(MultiplyAccumulate, Instruction) \ |
| 1338 | M(IntermediateAddress, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1339 | #endif |
| 1340 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1341 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1342 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1343 | #else |
| 1344 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1345 | M(ArmDexCacheArraysBase, Instruction) |
| 1346 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1347 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1348 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1349 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1350 | #else |
| 1351 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1352 | M(Arm64DataProcWithShifterOp, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1353 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1354 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1355 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1356 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1357 | #else |
| 1358 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1359 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1360 | M(MipsDexCacheArraysBase, Instruction) \ |
| 1361 | M(MipsPackedSwitch, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1362 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1363 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1364 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1365 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1366 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1367 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1368 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1369 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1370 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1371 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1372 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1373 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1374 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1375 | |
| 1376 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1377 | |
| 1378 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1379 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1380 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1381 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1382 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1383 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1384 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1385 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1386 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1387 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1388 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1389 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1390 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1391 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1392 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1393 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1394 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1395 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1396 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1397 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1398 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1399 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1400 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1401 | #undef FORWARD_DECLARATION |
| 1402 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1403 | #define DECLARE_INSTRUCTION(type) \ |
| 1404 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1405 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1406 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1407 | return other->Is##type(); \ |
| 1408 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1409 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1410 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1411 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1412 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1413 | const H##type* As##type() const { return this; } \ |
| 1414 | H##type* As##type() { return this; } |
| 1415 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1416 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1417 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1418 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1419 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1420 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1421 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1422 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1423 | // Hook for the IntrusiveForwardList<>. |
| 1424 | // TODO: Hide this better. |
| 1425 | IntrusiveForwardListHook hook; |
| 1426 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1427 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1428 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1429 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1430 | |
| 1431 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1432 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1433 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1434 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1435 | |
| 1436 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1437 | }; |
| 1438 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1439 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1440 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1441 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1442 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1443 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1444 | // by the used instructions. |
| 1445 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1446 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1447 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1448 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1449 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1450 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1451 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1452 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1453 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1454 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1455 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1459 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1460 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1461 | |
| 1462 | private: |
| 1463 | // Instruction used by the user. |
| 1464 | HInstruction* instruction_; |
| 1465 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1466 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1467 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1468 | }; |
| 1469 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1470 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1471 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1472 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1473 | struct HInputExtractor { |
| 1474 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1475 | return record.GetInstruction(); |
| 1476 | } |
| 1477 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1478 | return record.GetInstruction(); |
| 1479 | } |
| 1480 | }; |
| 1481 | |
| 1482 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1483 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1484 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1485 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1486 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1487 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1488 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1489 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1490 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1491 | * modify the value of a reference field read [although it may modify the |
| 1492 | * reference fetch prior to reading the field, which is represented by its own |
| 1493 | * write/read dependence]). The analysis makes conservative points-to |
| 1494 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1495 | * the same, and any reference read depends on any reference read without |
| 1496 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1497 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1498 | * The internal representation uses 38-bit and is described in the table below. |
| 1499 | * The first line indicates the side effect, and for field/array accesses the |
| 1500 | * second line indicates the type of the access (in the order of the |
| 1501 | * Primitive::Type enum). |
| 1502 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1503 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1504 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1505 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1506 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1507 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1508 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1509 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1510 | * |
| 1511 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1512 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1513 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1514 | class SideEffects : public ValueObject { |
| 1515 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1516 | SideEffects() : flags_(0) {} |
| 1517 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1518 | static SideEffects None() { |
| 1519 | return SideEffects(0); |
| 1520 | } |
| 1521 | |
| 1522 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1523 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1524 | } |
| 1525 | |
| 1526 | static SideEffects AllChanges() { |
| 1527 | return SideEffects(kAllChangeBits); |
| 1528 | } |
| 1529 | |
| 1530 | static SideEffects AllDependencies() { |
| 1531 | return SideEffects(kAllDependOnBits); |
| 1532 | } |
| 1533 | |
| 1534 | static SideEffects AllExceptGCDependency() { |
| 1535 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1536 | } |
| 1537 | |
| 1538 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1539 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1540 | } |
| 1541 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1542 | static SideEffects AllWrites() { |
| 1543 | return SideEffects(kAllWrites); |
| 1544 | } |
| 1545 | |
| 1546 | static SideEffects AllReads() { |
| 1547 | return SideEffects(kAllReads); |
| 1548 | } |
| 1549 | |
| 1550 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1551 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1552 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1553 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1554 | } |
| 1555 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1556 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1557 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1558 | } |
| 1559 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1560 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1561 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1562 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1563 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1567 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1570 | static SideEffects CanTriggerGC() { |
| 1571 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1572 | } |
| 1573 | |
| 1574 | static SideEffects DependsOnGC() { |
| 1575 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1576 | } |
| 1577 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1578 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1579 | SideEffects Union(SideEffects other) const { |
| 1580 | return SideEffects(flags_ | other.flags_); |
| 1581 | } |
| 1582 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1583 | SideEffects Exclusion(SideEffects other) const { |
| 1584 | return SideEffects(flags_ & ~other.flags_); |
| 1585 | } |
| 1586 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1587 | void Add(SideEffects other) { |
| 1588 | flags_ |= other.flags_; |
| 1589 | } |
| 1590 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1591 | bool Includes(SideEffects other) const { |
| 1592 | return (other.flags_ & flags_) == other.flags_; |
| 1593 | } |
| 1594 | |
| 1595 | bool HasSideEffects() const { |
| 1596 | return (flags_ & kAllChangeBits); |
| 1597 | } |
| 1598 | |
| 1599 | bool HasDependencies() const { |
| 1600 | return (flags_ & kAllDependOnBits); |
| 1601 | } |
| 1602 | |
| 1603 | // Returns true if there are no side effects or dependencies. |
| 1604 | bool DoesNothing() const { |
| 1605 | return flags_ == 0; |
| 1606 | } |
| 1607 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1608 | // Returns true if something is written. |
| 1609 | bool DoesAnyWrite() const { |
| 1610 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1611 | } |
| 1612 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1613 | // Returns true if something is read. |
| 1614 | bool DoesAnyRead() const { |
| 1615 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1616 | } |
| 1617 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1618 | // Returns true if potentially everything is written and read |
| 1619 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1620 | bool DoesAllReadWrite() const { |
| 1621 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1622 | } |
| 1623 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1624 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1625 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1628 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1629 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1630 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1631 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1635 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1636 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1637 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1638 | for (int s = kLastBit; s >= 0; s--) { |
| 1639 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1640 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1641 | // This is a bit for the GC side effect. |
| 1642 | if (current_bit_is_set) { |
| 1643 | flags += "GC"; |
| 1644 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1645 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1646 | } else { |
| 1647 | // This is a bit for the array/field analysis. |
| 1648 | // The underscore character stands for the 'can trigger GC' bit. |
| 1649 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1650 | if (current_bit_is_set) { |
| 1651 | flags += kDebug[s]; |
| 1652 | } |
| 1653 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1654 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1655 | flags += "|"; |
| 1656 | } |
| 1657 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1658 | } |
| 1659 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1660 | } |
| 1661 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1662 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1663 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1664 | private: |
| 1665 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1666 | |
| 1667 | static constexpr int kFieldWriteOffset = 0; |
| 1668 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1669 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1670 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1671 | |
| 1672 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1673 | |
| 1674 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1675 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1676 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1677 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1678 | |
| 1679 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1680 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1681 | |
| 1682 | // Aliases. |
| 1683 | |
| 1684 | static_assert(kChangeBits == kDependOnBits, |
| 1685 | "the 'change' bits should match the 'depend on' bits."); |
| 1686 | |
| 1687 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1688 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1689 | static constexpr uint64_t kAllWrites = |
| 1690 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1691 | static constexpr uint64_t kAllReads = |
| 1692 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1693 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1694 | // Translates type to bit flag. |
| 1695 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1696 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1697 | const uint64_t one = 1; |
| 1698 | const int shift = type; // 0-based consecutive enum |
| 1699 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1700 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1701 | return one << (type + offset); |
| 1702 | } |
| 1703 | |
| 1704 | // Private constructor on direct flags value. |
| 1705 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1706 | |
| 1707 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1708 | }; |
| 1709 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1710 | // 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] | 1711 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1712 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1713 | HEnvironment(ArenaAllocator* arena, |
| 1714 | size_t number_of_vregs, |
| 1715 | const DexFile& dex_file, |
| 1716 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1717 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1718 | InvokeType invoke_type, |
| 1719 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1720 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1721 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1722 | parent_(nullptr), |
| 1723 | dex_file_(dex_file), |
| 1724 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1725 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1726 | invoke_type_(invoke_type), |
| 1727 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1728 | } |
| 1729 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1730 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1731 | : HEnvironment(arena, |
| 1732 | to_copy.Size(), |
| 1733 | to_copy.GetDexFile(), |
| 1734 | to_copy.GetMethodIdx(), |
| 1735 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1736 | to_copy.GetInvokeType(), |
| 1737 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1738 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1739 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1740 | if (parent_ != nullptr) { |
| 1741 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1742 | } else { |
| 1743 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1744 | parent_->CopyFrom(parent); |
| 1745 | if (parent->GetParent() != nullptr) { |
| 1746 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1747 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1748 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1751 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1752 | void CopyFrom(HEnvironment* environment); |
| 1753 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1754 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1755 | // input to the loop phi instead. This is for inserting instructions that |
| 1756 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1757 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1758 | |
| 1759 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1760 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1764 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1765 | } |
| 1766 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1767 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1768 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1769 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1770 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1771 | HEnvironment* GetParent() const { return parent_; } |
| 1772 | |
| 1773 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1774 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1778 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | uint32_t GetDexPc() const { |
| 1782 | return dex_pc_; |
| 1783 | } |
| 1784 | |
| 1785 | uint32_t GetMethodIdx() const { |
| 1786 | return method_idx_; |
| 1787 | } |
| 1788 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1789 | InvokeType GetInvokeType() const { |
| 1790 | return invoke_type_; |
| 1791 | } |
| 1792 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1793 | const DexFile& GetDexFile() const { |
| 1794 | return dex_file_; |
| 1795 | } |
| 1796 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1797 | HInstruction* GetHolder() const { |
| 1798 | return holder_; |
| 1799 | } |
| 1800 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1801 | |
| 1802 | bool IsFromInlinedInvoke() const { |
| 1803 | return GetParent() != nullptr; |
| 1804 | } |
| 1805 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1806 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1807 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1808 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1809 | HEnvironment* parent_; |
| 1810 | const DexFile& dex_file_; |
| 1811 | const uint32_t method_idx_; |
| 1812 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1813 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1814 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1815 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1816 | HInstruction* const holder_; |
| 1817 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1818 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1819 | |
| 1820 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1821 | }; |
| 1822 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1823 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1824 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1825 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1826 | : previous_(nullptr), |
| 1827 | next_(nullptr), |
| 1828 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1829 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1830 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1831 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1832 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1833 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1834 | locations_(nullptr), |
| 1835 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1836 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1837 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1838 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1839 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1840 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1841 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1842 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1843 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1844 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1845 | enum InstructionKind { |
| 1846 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1847 | }; |
| 1848 | #undef DECLARE_KIND |
| 1849 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1850 | HInstruction* GetNext() const { return next_; } |
| 1851 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1852 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1853 | HInstruction* GetNextDisregardingMoves() const; |
| 1854 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1855 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1856 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1857 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1858 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1859 | bool IsInBlock() const { return block_ != nullptr; } |
| 1860 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1861 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1862 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1863 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1864 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1865 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1866 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1867 | |
| 1868 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1869 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1870 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1871 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1872 | } |
| 1873 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1874 | HInputsRef GetInputs() { |
| 1875 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1876 | } |
| 1877 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1878 | HConstInputsRef GetInputs() const { |
| 1879 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1883 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1884 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 1885 | bool HasInput(HInstruction* input) const { |
| 1886 | for (const HInstruction* i : GetInputs()) { |
| 1887 | if (i == input) { |
| 1888 | return true; |
| 1889 | } |
| 1890 | } |
| 1891 | return false; |
| 1892 | } |
| 1893 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1894 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1895 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1896 | } |
| 1897 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1898 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1899 | virtual const char* DebugName() const = 0; |
| 1900 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1901 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1902 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1903 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1904 | |
| 1905 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1906 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1907 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1908 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1909 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1910 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1911 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1912 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1913 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1914 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1915 | // Does not apply for all instructions, but having this at top level greatly |
| 1916 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1917 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1918 | virtual bool CanBeNull() const { |
| 1919 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1920 | return true; |
| 1921 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1922 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1923 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1924 | return false; |
| 1925 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1926 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1927 | virtual bool IsActualObject() const { |
| 1928 | return GetType() == Primitive::kPrimNot; |
| 1929 | } |
| 1930 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1931 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1932 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1933 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1934 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1935 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1936 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1937 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1938 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1939 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1940 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1941 | // Note: fixup_end remains valid across push_front(). |
| 1942 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1943 | HUseListNode<HInstruction*>* new_node = |
| 1944 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1945 | uses_.push_front(*new_node); |
| 1946 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1949 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1950 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1951 | // Note: env_fixup_end remains valid across push_front(). |
| 1952 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 1953 | HUseListNode<HEnvironment*>* new_node = |
| 1954 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 1955 | env_uses_.push_front(*new_node); |
| 1956 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1957 | } |
| 1958 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1959 | void RemoveAsUserOfInput(size_t input) { |
| 1960 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1961 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1962 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1963 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1964 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1965 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1966 | void RemoveAsUserOfAllInputs() { |
| 1967 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 1968 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1969 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1970 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 1971 | } |
| 1972 | } |
| 1973 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1974 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1975 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1976 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1977 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 1978 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 1979 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1980 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1981 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1982 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1983 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 1984 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1985 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 1986 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1987 | !CanThrow() && |
| 1988 | !IsSuspendCheck() && |
| 1989 | !IsControlFlow() && |
| 1990 | !IsNativeDebugInfo() && |
| 1991 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 1992 | // If we added an explicit barrier then we should keep it. |
| 1993 | !IsMemoryBarrier(); |
| 1994 | } |
| 1995 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 1996 | bool IsDeadAndRemovable() const { |
| 1997 | return IsRemovable() && !HasUses(); |
| 1998 | } |
| 1999 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2000 | // Does this instruction strictly dominate `other_instruction`? |
| 2001 | // Returns false if this instruction and `other_instruction` are the same. |
| 2002 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2003 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2004 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2005 | int GetId() const { return id_; } |
| 2006 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2007 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2008 | int GetSsaIndex() const { return ssa_index_; } |
| 2009 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2010 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2011 | |
| 2012 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2013 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2014 | // Set the `environment_` field. Raw because this method does not |
| 2015 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2016 | void SetRawEnvironment(HEnvironment* environment) { |
| 2017 | DCHECK(environment_ == nullptr); |
| 2018 | DCHECK_EQ(environment->GetHolder(), this); |
| 2019 | environment_ = environment; |
| 2020 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2021 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2022 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2023 | DCHECK(environment_ != nullptr); |
| 2024 | DCHECK_EQ(environment->GetHolder(), this); |
| 2025 | DCHECK(environment->GetParent() == nullptr); |
| 2026 | environment->parent_ = environment_; |
| 2027 | environment_ = environment; |
| 2028 | } |
| 2029 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2030 | void RemoveEnvironment(); |
| 2031 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2032 | // Set the environment of this instruction, copying it from `environment`. While |
| 2033 | // copying, the uses lists are being updated. |
| 2034 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2035 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2036 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2037 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2038 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2039 | if (environment->GetParent() != nullptr) { |
| 2040 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2041 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2042 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2043 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2044 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2045 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2046 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2047 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2048 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2049 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2050 | if (environment->GetParent() != nullptr) { |
| 2051 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2052 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2055 | // Returns the number of entries in the environment. Typically, that is the |
| 2056 | // number of dex registers in a method. It could be more in case of inlining. |
| 2057 | size_t EnvironmentSize() const; |
| 2058 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2059 | LocationSummary* GetLocations() const { return locations_; } |
| 2060 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2061 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2062 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2063 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2064 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2065 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2066 | // uses of this instruction by `other` are *not* updated. |
| 2067 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2068 | ReplaceWith(other); |
| 2069 | other->ReplaceInput(this, use_index); |
| 2070 | } |
| 2071 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2072 | // Move `this` instruction before `cursor`. |
| 2073 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2074 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2075 | // Move `this` before its first user and out of any loops. If there is no |
| 2076 | // out-of-loop user that dominates all other users, move the instruction |
| 2077 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2078 | // |
| 2079 | // This can be used only on non-throwing instructions with no side effects that |
| 2080 | // have at least one use but no environment uses. |
| 2081 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2082 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2083 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2084 | bool Is##type() const; \ |
| 2085 | const H##type* As##type() const; \ |
| 2086 | H##type* As##type(); |
| 2087 | |
| 2088 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2089 | #undef INSTRUCTION_TYPE_CHECK |
| 2090 | |
| 2091 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2092 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2093 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2094 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2095 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2096 | #undef INSTRUCTION_TYPE_CHECK |
| 2097 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2098 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2099 | // TODO: this method is used by LICM and GVN with possibly different |
| 2100 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2101 | virtual bool CanBeMoved() const { return false; } |
| 2102 | |
| 2103 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2104 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2105 | return false; |
| 2106 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2107 | |
| 2108 | // Returns whether any data encoded in the two instructions is equal. |
| 2109 | // This method does not look at the inputs. Both instructions must be |
| 2110 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2111 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2112 | return false; |
| 2113 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2114 | |
| 2115 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2116 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2117 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2118 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2119 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2120 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2121 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2122 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2123 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2124 | InstructionKind GetKind() const PURE; |
| 2125 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2126 | |
| 2127 | virtual size_t ComputeHashCode() const { |
| 2128 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2129 | for (const HInstruction* input : GetInputs()) { |
| 2130 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2131 | } |
| 2132 | return result; |
| 2133 | } |
| 2134 | |
| 2135 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2136 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2137 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2138 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2139 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2140 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2141 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2142 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2143 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2144 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2145 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2146 | |
| 2147 | // Returns whether the code generation of the instruction will require to have access |
| 2148 | // to the current method. Such instructions are: |
| 2149 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2150 | // 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] | 2151 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2152 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2153 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2154 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2157 | // Returns whether the code generation of the instruction will require to have access |
| 2158 | // to the dex cache of the current method's declaring class via the current method. |
| 2159 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2160 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2161 | // Does this instruction have any use in an environment before |
| 2162 | // control flow hits 'other'? |
| 2163 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2164 | |
| 2165 | // Remove all references to environment uses of this instruction. |
| 2166 | // The caller must ensure that this is safe to do. |
| 2167 | void RemoveEnvironmentUsers(); |
| 2168 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2169 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2170 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2171 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2172 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2173 | // If set, the machine code for this instruction is assumed to be generated by |
| 2174 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2175 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2176 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2177 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2178 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2179 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2180 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2181 | return GetInputRecords()[i]; |
| 2182 | } |
| 2183 | |
| 2184 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2185 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2186 | input_records[index] = input; |
| 2187 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2188 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2189 | uint32_t GetPackedFields() const { |
| 2190 | return packed_fields_; |
| 2191 | } |
| 2192 | |
| 2193 | template <size_t flag> |
| 2194 | bool GetPackedFlag() const { |
| 2195 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2196 | } |
| 2197 | |
| 2198 | template <size_t flag> |
| 2199 | void SetPackedFlag(bool value = true) { |
| 2200 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2201 | } |
| 2202 | |
| 2203 | template <typename BitFieldType> |
| 2204 | typename BitFieldType::value_type GetPackedField() const { |
| 2205 | return BitFieldType::Decode(packed_fields_); |
| 2206 | } |
| 2207 | |
| 2208 | template <typename BitFieldType> |
| 2209 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2210 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2211 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2212 | } |
| 2213 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2214 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2215 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2216 | auto before_use_node = uses_.before_begin(); |
| 2217 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2218 | HInstruction* user = use_node->GetUser(); |
| 2219 | size_t input_index = use_node->GetIndex(); |
| 2220 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2221 | before_use_node = use_node; |
| 2222 | } |
| 2223 | } |
| 2224 | |
| 2225 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2226 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2227 | if (next != uses_.end()) { |
| 2228 | HInstruction* next_user = next->GetUser(); |
| 2229 | size_t next_index = next->GetIndex(); |
| 2230 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2231 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2236 | auto before_env_use_node = env_uses_.before_begin(); |
| 2237 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2238 | HEnvironment* user = env_use_node->GetUser(); |
| 2239 | size_t input_index = env_use_node->GetIndex(); |
| 2240 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2241 | before_env_use_node = env_use_node; |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2246 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2247 | if (next != env_uses_.end()) { |
| 2248 | HEnvironment* next_user = next->GetUser(); |
| 2249 | size_t next_index = next->GetIndex(); |
| 2250 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2251 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2252 | } |
| 2253 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2254 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2255 | HInstruction* previous_; |
| 2256 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2257 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2258 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2259 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2260 | // An instruction gets an id when it is added to the graph. |
| 2261 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2262 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2263 | int id_; |
| 2264 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2265 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2266 | int ssa_index_; |
| 2267 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2268 | // Packed fields. |
| 2269 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2270 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2271 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2272 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2273 | |
| 2274 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2275 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2276 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2277 | // The environment associated with this instruction. Not null if the instruction |
| 2278 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2279 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2280 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2281 | // Set by the code generator. |
| 2282 | LocationSummary* locations_; |
| 2283 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2284 | // Set by the liveness analysis. |
| 2285 | LiveInterval* live_interval_; |
| 2286 | |
| 2287 | // Set by the liveness analysis, this is the position in a linear |
| 2288 | // order of blocks where this instruction's live interval start. |
| 2289 | size_t lifetime_position_; |
| 2290 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2291 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2292 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2293 | // The reference handle part of the reference type info. |
| 2294 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2295 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2296 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2297 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2298 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2299 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2300 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2301 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2302 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2303 | |
| 2304 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2305 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2306 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2307 | |
| 2308 | class HInstructionIterator : public ValueObject { |
| 2309 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2310 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2311 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2312 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2315 | bool Done() const { return instruction_ == nullptr; } |
| 2316 | HInstruction* Current() const { return instruction_; } |
| 2317 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2318 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2319 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | private: |
| 2323 | HInstruction* instruction_; |
| 2324 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2325 | |
| 2326 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2327 | }; |
| 2328 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2329 | class HBackwardInstructionIterator : public ValueObject { |
| 2330 | public: |
| 2331 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2332 | : instruction_(instructions.last_instruction_) { |
| 2333 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2334 | } |
| 2335 | |
| 2336 | bool Done() const { return instruction_ == nullptr; } |
| 2337 | HInstruction* Current() const { return instruction_; } |
| 2338 | void Advance() { |
| 2339 | instruction_ = next_; |
| 2340 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2341 | } |
| 2342 | |
| 2343 | private: |
| 2344 | HInstruction* instruction_; |
| 2345 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2346 | |
| 2347 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2348 | }; |
| 2349 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2350 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2351 | class HTemplateInstruction: public HInstruction { |
| 2352 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2353 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2354 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2355 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2356 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2357 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2358 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2359 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2360 | } |
| 2361 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2362 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2363 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2364 | |
| 2365 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2366 | }; |
| 2367 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2368 | // HTemplateInstruction specialization for N=0. |
| 2369 | template<> |
| 2370 | class HTemplateInstruction<0>: public HInstruction { |
| 2371 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2372 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2373 | : HInstruction(side_effects, dex_pc) {} |
| 2374 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2375 | virtual ~HTemplateInstruction() {} |
| 2376 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2377 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2378 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2379 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | private: |
| 2383 | friend class SsaBuilder; |
| 2384 | }; |
| 2385 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2386 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2387 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2388 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2389 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2390 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2391 | this->template SetPackedField<TypeField>(type); |
| 2392 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2393 | virtual ~HExpression() {} |
| 2394 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2395 | Primitive::Type GetType() const OVERRIDE { |
| 2396 | return TypeField::Decode(this->GetPackedFields()); |
| 2397 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2398 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2399 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2400 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2401 | static constexpr size_t kFieldTypeSize = |
| 2402 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2403 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2404 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2405 | "Too many packed fields."); |
| 2406 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2407 | }; |
| 2408 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2409 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2410 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2411 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2412 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2413 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2414 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2415 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2416 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2417 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2418 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2419 | |
| 2420 | private: |
| 2421 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2422 | }; |
| 2423 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2424 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2425 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2426 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2427 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2428 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2429 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2430 | SetRawInputAt(0, value); |
| 2431 | } |
| 2432 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2433 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2434 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2435 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2436 | |
| 2437 | private: |
| 2438 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2439 | }; |
| 2440 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2441 | class HPhi FINAL : public HInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2442 | public: |
| 2443 | HPhi(ArenaAllocator* arena, |
| 2444 | uint32_t reg_number, |
| 2445 | size_t number_of_inputs, |
| 2446 | Primitive::Type type, |
| 2447 | uint32_t dex_pc = kNoDexPc) |
| 2448 | : HInstruction(SideEffects::None(), dex_pc), |
| 2449 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
| 2450 | reg_number_(reg_number) { |
| 2451 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2452 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2453 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2454 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2455 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2456 | SetPackedFlag<kFlagIsLive>(true); |
| 2457 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2458 | } |
| 2459 | |
| 2460 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2461 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2462 | return Primitive::PrimitiveKind(type); |
| 2463 | } |
| 2464 | |
| 2465 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2466 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2467 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2468 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2469 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2470 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2471 | |
| 2472 | void AddInput(HInstruction* input); |
| 2473 | void RemoveInputAt(size_t index); |
| 2474 | |
| 2475 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2476 | void SetType(Primitive::Type new_type) { |
| 2477 | // Make sure that only valid type changes occur. The following are allowed: |
| 2478 | // (1) int -> float/ref (primitive type propagation), |
| 2479 | // (2) long -> double (primitive type propagation). |
| 2480 | DCHECK(GetType() == new_type || |
| 2481 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2482 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2483 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2484 | SetPackedField<TypeField>(new_type); |
| 2485 | } |
| 2486 | |
| 2487 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2488 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2489 | |
| 2490 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2491 | |
| 2492 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2493 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2494 | bool IsDead() const { return !IsLive(); } |
| 2495 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2496 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2497 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2498 | return other != nullptr |
| 2499 | && other->IsPhi() |
| 2500 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2501 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2502 | } |
| 2503 | |
| 2504 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2505 | // An equivalent phi is a phi having the same dex register and type. |
| 2506 | // It assumes that phis with the same dex register are adjacent. |
| 2507 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2508 | HInstruction* next = GetNext(); |
| 2509 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2510 | if (next->GetType() == GetType()) { |
| 2511 | return next->AsPhi(); |
| 2512 | } |
| 2513 | next = next->GetNext(); |
| 2514 | } |
| 2515 | return nullptr; |
| 2516 | } |
| 2517 | |
| 2518 | DECLARE_INSTRUCTION(Phi); |
| 2519 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2520 | private: |
| 2521 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2522 | static constexpr size_t kFieldTypeSize = |
| 2523 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2524 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2525 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2526 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2527 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2528 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2529 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2530 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2531 | const uint32_t reg_number_; |
| 2532 | |
| 2533 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2534 | }; |
| 2535 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2536 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2537 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2538 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2539 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2540 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2541 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2542 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2543 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2544 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2545 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2546 | |
| 2547 | private: |
| 2548 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2549 | }; |
| 2550 | |
| 2551 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2552 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2553 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2554 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2555 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2556 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2557 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2558 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2559 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2560 | } |
| 2561 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2562 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2563 | |
| 2564 | private: |
| 2565 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2566 | }; |
| 2567 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2568 | class HConstant : public HExpression<0> { |
| 2569 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2570 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2571 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2572 | |
| 2573 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2574 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2575 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2576 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2577 | // Is this constant 0 in the arithmetic sense? |
| 2578 | virtual bool IsArithmeticZero() const { return false; } |
| 2579 | // Is this constant a 0-bit pattern? |
| 2580 | virtual bool IsZeroBitPattern() const { return false; } |
| 2581 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2582 | virtual bool IsOne() const { return false; } |
| 2583 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2584 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2585 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2586 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2587 | |
| 2588 | private: |
| 2589 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2590 | }; |
| 2591 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2592 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2593 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2594 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2595 | return true; |
| 2596 | } |
| 2597 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2598 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2599 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2600 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2601 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2602 | // The null constant representation is a 0-bit pattern. |
| 2603 | virtual bool IsZeroBitPattern() const { return true; } |
| 2604 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2605 | DECLARE_INSTRUCTION(NullConstant); |
| 2606 | |
| 2607 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2608 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2609 | |
| 2610 | friend class HGraph; |
| 2611 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2612 | }; |
| 2613 | |
| 2614 | // Constants of the type int. Those can be from Dex instructions, or |
| 2615 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2616 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2617 | public: |
| 2618 | int32_t GetValue() const { return value_; } |
| 2619 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2620 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2621 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2622 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2623 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2624 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2625 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2626 | return other->AsIntConstant()->value_ == value_; |
| 2627 | } |
| 2628 | |
| 2629 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2630 | |
| 2631 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2632 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2633 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2634 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2635 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2636 | // Integer constants are used to encode Boolean values as well, |
| 2637 | // where 1 means true and 0 means false. |
| 2638 | bool IsTrue() const { return GetValue() == 1; } |
| 2639 | bool IsFalse() const { return GetValue() == 0; } |
| 2640 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2641 | DECLARE_INSTRUCTION(IntConstant); |
| 2642 | |
| 2643 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2644 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2645 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2646 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2647 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2648 | |
| 2649 | const int32_t value_; |
| 2650 | |
| 2651 | friend class HGraph; |
| 2652 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2653 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2654 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2655 | }; |
| 2656 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2657 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2658 | public: |
| 2659 | int64_t GetValue() const { return value_; } |
| 2660 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2661 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2662 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2663 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2664 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2665 | return other->AsLongConstant()->value_ == value_; |
| 2666 | } |
| 2667 | |
| 2668 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2669 | |
| 2670 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2671 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2672 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2673 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2674 | |
| 2675 | DECLARE_INSTRUCTION(LongConstant); |
| 2676 | |
| 2677 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2678 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2679 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2680 | |
| 2681 | const int64_t value_; |
| 2682 | |
| 2683 | friend class HGraph; |
| 2684 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2685 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2686 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2687 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2688 | public: |
| 2689 | float GetValue() const { return value_; } |
| 2690 | |
| 2691 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2692 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2693 | } |
| 2694 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2695 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2696 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2697 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2698 | } |
| 2699 | |
| 2700 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2701 | |
| 2702 | bool IsMinusOne() const OVERRIDE { |
| 2703 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2704 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2705 | bool IsArithmeticZero() const OVERRIDE { |
| 2706 | return std::fpclassify(value_) == FP_ZERO; |
| 2707 | } |
| 2708 | bool IsArithmeticPositiveZero() const { |
| 2709 | return IsArithmeticZero() && !std::signbit(value_); |
| 2710 | } |
| 2711 | bool IsArithmeticNegativeZero() const { |
| 2712 | return IsArithmeticZero() && std::signbit(value_); |
| 2713 | } |
| 2714 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2715 | 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] | 2716 | } |
| 2717 | bool IsOne() const OVERRIDE { |
| 2718 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2719 | } |
| 2720 | bool IsNaN() const { |
| 2721 | return std::isnan(value_); |
| 2722 | } |
| 2723 | |
| 2724 | DECLARE_INSTRUCTION(FloatConstant); |
| 2725 | |
| 2726 | private: |
| 2727 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2728 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2729 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2730 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2731 | |
| 2732 | const float value_; |
| 2733 | |
| 2734 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2735 | friend class SsaBuilder; |
| 2736 | friend class HGraph; |
| 2737 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2738 | }; |
| 2739 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2740 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2741 | public: |
| 2742 | double GetValue() const { return value_; } |
| 2743 | |
| 2744 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2745 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2746 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2747 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2748 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2749 | } |
| 2750 | |
| 2751 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2752 | |
| 2753 | bool IsMinusOne() const OVERRIDE { |
| 2754 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2755 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2756 | bool IsArithmeticZero() const OVERRIDE { |
| 2757 | return std::fpclassify(value_) == FP_ZERO; |
| 2758 | } |
| 2759 | bool IsArithmeticPositiveZero() const { |
| 2760 | return IsArithmeticZero() && !std::signbit(value_); |
| 2761 | } |
| 2762 | bool IsArithmeticNegativeZero() const { |
| 2763 | return IsArithmeticZero() && std::signbit(value_); |
| 2764 | } |
| 2765 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2766 | 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] | 2767 | } |
| 2768 | bool IsOne() const OVERRIDE { |
| 2769 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2770 | } |
| 2771 | bool IsNaN() const { |
| 2772 | return std::isnan(value_); |
| 2773 | } |
| 2774 | |
| 2775 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2776 | |
| 2777 | private: |
| 2778 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2779 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2780 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2781 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2782 | |
| 2783 | const double value_; |
| 2784 | |
| 2785 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2786 | friend class SsaBuilder; |
| 2787 | friend class HGraph; |
| 2788 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2789 | }; |
| 2790 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2791 | // Conditional branch. A block ending with an HIf instruction must have |
| 2792 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2793 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2794 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2795 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2796 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2797 | SetRawInputAt(0, input); |
| 2798 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2799 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2800 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2801 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2802 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2803 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2807 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2808 | } |
| 2809 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2810 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2811 | |
| 2812 | private: |
| 2813 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2814 | }; |
| 2815 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2816 | |
| 2817 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2818 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2819 | // non-exceptional control flow. |
| 2820 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2821 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2822 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2823 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2824 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2825 | kEntry, |
| 2826 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2827 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2828 | }; |
| 2829 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2830 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2831 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2832 | SetPackedField<BoundaryKindField>(kind); |
| 2833 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2834 | |
| 2835 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2836 | |
| 2837 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2838 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2839 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2840 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2841 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2842 | } |
| 2843 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2844 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2845 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2846 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2847 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2848 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | // If not present already, adds `handler` to its block's list of exception |
| 2852 | // handlers. |
| 2853 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2854 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2855 | GetBlock()->AddSuccessor(handler); |
| 2856 | } |
| 2857 | } |
| 2858 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2859 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2860 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2861 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2862 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2863 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2864 | DECLARE_INSTRUCTION(TryBoundary); |
| 2865 | |
| 2866 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2867 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2868 | static constexpr size_t kFieldBoundaryKindSize = |
| 2869 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2870 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2871 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2872 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2873 | "Too many packed fields."); |
| 2874 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2875 | |
| 2876 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2877 | }; |
| 2878 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2879 | // Deoptimize to interpreter, upon checking a condition. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2880 | class HDeoptimize FINAL : public HTemplateInstruction<1> { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2881 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2882 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2883 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2884 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2885 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2886 | SetRawInputAt(0, cond); |
| 2887 | } |
| 2888 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2889 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2890 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2891 | return true; |
| 2892 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2893 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2894 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2895 | |
| 2896 | DECLARE_INSTRUCTION(Deoptimize); |
| 2897 | |
| 2898 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2899 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2900 | }; |
| 2901 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2902 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 2903 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 2904 | // if it's true, starts to do deoptimization. |
| 2905 | // It has a 4-byte slot on stack. |
| 2906 | // TODO: allocate a register for this flag. |
| 2907 | class HShouldDeoptimizeFlag FINAL : public HExpression<0> { |
| 2908 | public: |
| 2909 | // TODO: use SideEffects to aid eliminating some CHA guards. |
| 2910 | explicit HShouldDeoptimizeFlag(uint32_t dex_pc) |
| 2911 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
| 2912 | } |
| 2913 | |
| 2914 | // We don't eliminate CHA guards yet. |
| 2915 | bool CanBeMoved() const OVERRIDE { return false; } |
| 2916 | |
| 2917 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 2918 | |
| 2919 | private: |
| 2920 | DISALLOW_COPY_AND_ASSIGN(HShouldDeoptimizeFlag); |
| 2921 | }; |
| 2922 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2923 | // Represents the ArtMethod that was passed as a first argument to |
| 2924 | // the method. It is used by instructions that depend on it, like |
| 2925 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2926 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2927 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2928 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2929 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2930 | |
| 2931 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2932 | |
| 2933 | private: |
| 2934 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2935 | }; |
| 2936 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2937 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2938 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2939 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2940 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2941 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2942 | kVTable, |
| 2943 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2944 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2945 | }; |
| 2946 | HClassTableGet(HInstruction* cls, |
| 2947 | Primitive::Type type, |
| 2948 | TableKind kind, |
| 2949 | size_t index, |
| 2950 | uint32_t dex_pc) |
| 2951 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2952 | index_(index) { |
| 2953 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2954 | SetRawInputAt(0, cls); |
| 2955 | } |
| 2956 | |
| 2957 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2958 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2959 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2960 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2961 | } |
| 2962 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2963 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2964 | size_t GetIndex() const { return index_; } |
| 2965 | |
| 2966 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2967 | |
| 2968 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2969 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2970 | static constexpr size_t kFieldTableKindSize = |
| 2971 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2972 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2973 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2974 | "Too many packed fields."); |
| 2975 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2976 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2977 | // The index of the ArtMethod in the table. |
| 2978 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2979 | |
| 2980 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2981 | }; |
| 2982 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2983 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2984 | // have one successor for each entry in the switch table, and the final successor |
| 2985 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2986 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2987 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2988 | HPackedSwitch(int32_t start_value, |
| 2989 | uint32_t num_entries, |
| 2990 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2991 | uint32_t dex_pc = kNoDexPc) |
| 2992 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2993 | start_value_(start_value), |
| 2994 | num_entries_(num_entries) { |
| 2995 | SetRawInputAt(0, input); |
| 2996 | } |
| 2997 | |
| 2998 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2999 | |
| 3000 | int32_t GetStartValue() const { return start_value_; } |
| 3001 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3002 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3003 | |
| 3004 | HBasicBlock* GetDefaultBlock() const { |
| 3005 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3006 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3007 | } |
| 3008 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3009 | |
| 3010 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3011 | const int32_t start_value_; |
| 3012 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3013 | |
| 3014 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 3015 | }; |
| 3016 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3017 | class HUnaryOperation : public HExpression<1> { |
| 3018 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3019 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3020 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3021 | SetRawInputAt(0, input); |
| 3022 | } |
| 3023 | |
| 3024 | HInstruction* GetInput() const { return InputAt(0); } |
| 3025 | Primitive::Type GetResultType() const { return GetType(); } |
| 3026 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3027 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3028 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3029 | return true; |
| 3030 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3031 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3032 | // Try to statically evaluate `this` and return a HConstant |
| 3033 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3034 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3035 | HConstant* TryStaticEvaluation() const; |
| 3036 | |
| 3037 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3038 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3039 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3040 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3041 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3042 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3043 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3044 | |
| 3045 | private: |
| 3046 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 3047 | }; |
| 3048 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3049 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3050 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3051 | HBinaryOperation(Primitive::Type result_type, |
| 3052 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3053 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3054 | SideEffects side_effects = SideEffects::None(), |
| 3055 | uint32_t dex_pc = kNoDexPc) |
| 3056 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3057 | SetRawInputAt(0, left); |
| 3058 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3059 | } |
| 3060 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3061 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3062 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3063 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3064 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3065 | virtual bool IsCommutative() const { return false; } |
| 3066 | |
| 3067 | // Put constant on the right. |
| 3068 | // Returns whether order is changed. |
| 3069 | bool OrderInputsWithConstantOnTheRight() { |
| 3070 | HInstruction* left = InputAt(0); |
| 3071 | HInstruction* right = InputAt(1); |
| 3072 | if (left->IsConstant() && !right->IsConstant()) { |
| 3073 | ReplaceInput(right, 0); |
| 3074 | ReplaceInput(left, 1); |
| 3075 | return true; |
| 3076 | } |
| 3077 | return false; |
| 3078 | } |
| 3079 | |
| 3080 | // Order inputs by instruction id, but favor constant on the right side. |
| 3081 | // This helps GVN for commutative ops. |
| 3082 | void OrderInputs() { |
| 3083 | DCHECK(IsCommutative()); |
| 3084 | HInstruction* left = InputAt(0); |
| 3085 | HInstruction* right = InputAt(1); |
| 3086 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3087 | return; |
| 3088 | } |
| 3089 | if (OrderInputsWithConstantOnTheRight()) { |
| 3090 | return; |
| 3091 | } |
| 3092 | // Order according to instruction id. |
| 3093 | if (left->GetId() > right->GetId()) { |
| 3094 | ReplaceInput(right, 0); |
| 3095 | ReplaceInput(left, 1); |
| 3096 | } |
| 3097 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3098 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3099 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3100 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3101 | return true; |
| 3102 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3103 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3104 | // Try to statically evaluate `this` and return a HConstant |
| 3105 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3106 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3107 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3108 | |
| 3109 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3110 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3111 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3112 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3113 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3114 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3115 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3116 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3117 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3118 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3119 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3120 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3121 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3122 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3123 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3124 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3125 | // 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] | 3126 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3127 | HConstant* GetConstantRight() const; |
| 3128 | |
| 3129 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3130 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3131 | HInstruction* GetLeastConstantLeft() const; |
| 3132 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3133 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3134 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3135 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3136 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3137 | }; |
| 3138 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3139 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3140 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3141 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3142 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3143 | kGtBias, // return 1 for NaN comparisons |
| 3144 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3145 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3146 | }; |
| 3147 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3148 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3149 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3150 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3151 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3152 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3153 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3154 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3155 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3156 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3157 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3158 | // `instruction`, and disregard moves in between. |
| 3159 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3160 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3161 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3162 | |
| 3163 | virtual IfCondition GetCondition() const = 0; |
| 3164 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3165 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3166 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3167 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3168 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3169 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3170 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3171 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3172 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3173 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3174 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3175 | } |
| 3176 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3177 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3178 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3179 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3180 | if (if_cond == kCondNE) { |
| 3181 | return true; |
| 3182 | } else if (if_cond == kCondEQ) { |
| 3183 | return false; |
| 3184 | } |
| 3185 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3189 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3190 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3191 | if (if_cond == kCondEQ) { |
| 3192 | return true; |
| 3193 | } else if (if_cond == kCondNE) { |
| 3194 | return false; |
| 3195 | } |
| 3196 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3197 | } |
| 3198 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3199 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3200 | // Needed if we merge a HCompare into a HCondition. |
| 3201 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3202 | static constexpr size_t kFieldComparisonBiasSize = |
| 3203 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3204 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3205 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3206 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3207 | using ComparisonBiasField = |
| 3208 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3209 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3210 | template <typename T> |
| 3211 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3212 | |
| 3213 | template <typename T> |
| 3214 | int32_t CompareFP(T x, T y) const { |
| 3215 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3216 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3217 | // Handle the bias. |
| 3218 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3219 | } |
| 3220 | |
| 3221 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3222 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3223 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3224 | } |
| 3225 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3226 | private: |
| 3227 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3228 | }; |
| 3229 | |
| 3230 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3231 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3232 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3233 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3234 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3235 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3236 | bool IsCommutative() const OVERRIDE { return true; } |
| 3237 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3238 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3239 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3240 | return MakeConstantCondition(true, GetDexPc()); |
| 3241 | } |
| 3242 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3243 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3244 | } |
| 3245 | // In the following Evaluate methods, a HCompare instruction has |
| 3246 | // been merged into this HEqual instruction; evaluate it as |
| 3247 | // `Compare(x, y) == 0`. |
| 3248 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3249 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3250 | GetDexPc()); |
| 3251 | } |
| 3252 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3253 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3254 | } |
| 3255 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3256 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3257 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3258 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3259 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3260 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3261 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3262 | return kCondEQ; |
| 3263 | } |
| 3264 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3265 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3266 | return kCondNE; |
| 3267 | } |
| 3268 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3269 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3270 | 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] | 3271 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3272 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3273 | }; |
| 3274 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3275 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3276 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3277 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3278 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3279 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3280 | bool IsCommutative() const OVERRIDE { return true; } |
| 3281 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3282 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3283 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3284 | return MakeConstantCondition(false, GetDexPc()); |
| 3285 | } |
| 3286 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3287 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3288 | } |
| 3289 | // In the following Evaluate methods, a HCompare instruction has |
| 3290 | // been merged into this HNotEqual instruction; evaluate it as |
| 3291 | // `Compare(x, y) != 0`. |
| 3292 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3293 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3294 | } |
| 3295 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3296 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3297 | } |
| 3298 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3299 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3300 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3301 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3302 | DECLARE_INSTRUCTION(NotEqual); |
| 3303 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3304 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3305 | return kCondNE; |
| 3306 | } |
| 3307 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3308 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3309 | return kCondEQ; |
| 3310 | } |
| 3311 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3312 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3313 | 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] | 3314 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3315 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3316 | }; |
| 3317 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3318 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3319 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3320 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3321 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3322 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3323 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3324 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3325 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3326 | // In the following Evaluate methods, a HCompare instruction has |
| 3327 | // been merged into this HLessThan instruction; evaluate it as |
| 3328 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3329 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3330 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3331 | } |
| 3332 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3333 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3334 | } |
| 3335 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3336 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3337 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3338 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3339 | DECLARE_INSTRUCTION(LessThan); |
| 3340 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3341 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3342 | return kCondLT; |
| 3343 | } |
| 3344 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3345 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3346 | return kCondGE; |
| 3347 | } |
| 3348 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3349 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3350 | 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] | 3351 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3352 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3353 | }; |
| 3354 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3355 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3356 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3357 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3358 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3359 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3360 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3361 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3362 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3363 | // In the following Evaluate methods, a HCompare instruction has |
| 3364 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3365 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3366 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3367 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3368 | } |
| 3369 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3370 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3371 | } |
| 3372 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3373 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3374 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3375 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3376 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3377 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3378 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3379 | return kCondLE; |
| 3380 | } |
| 3381 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3382 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3383 | return kCondGT; |
| 3384 | } |
| 3385 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3386 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3387 | 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] | 3388 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3389 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3390 | }; |
| 3391 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3392 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3393 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3394 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3395 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3396 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3397 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3398 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3399 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3400 | // In the following Evaluate methods, a HCompare instruction has |
| 3401 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3402 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3403 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3404 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3405 | } |
| 3406 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3407 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3408 | } |
| 3409 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3410 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3411 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3412 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3413 | DECLARE_INSTRUCTION(GreaterThan); |
| 3414 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3415 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3416 | return kCondGT; |
| 3417 | } |
| 3418 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3419 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3420 | return kCondLE; |
| 3421 | } |
| 3422 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3423 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3424 | 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] | 3425 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3426 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3427 | }; |
| 3428 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3429 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3430 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3431 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3432 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3433 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3434 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3435 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3436 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3437 | // In the following Evaluate methods, a HCompare instruction has |
| 3438 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3439 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3440 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3441 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3442 | } |
| 3443 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3444 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3445 | } |
| 3446 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3447 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3448 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3449 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3450 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3451 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3452 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3453 | return kCondGE; |
| 3454 | } |
| 3455 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3456 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3457 | return kCondLT; |
| 3458 | } |
| 3459 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3460 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3461 | 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] | 3462 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3463 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3464 | }; |
| 3465 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3466 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3467 | public: |
| 3468 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3469 | : HCondition(first, second, dex_pc) {} |
| 3470 | |
| 3471 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3472 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3473 | } |
| 3474 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3475 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3476 | } |
| 3477 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3478 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3479 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3480 | UNREACHABLE(); |
| 3481 | } |
| 3482 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3483 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3484 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3485 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | DECLARE_INSTRUCTION(Below); |
| 3489 | |
| 3490 | IfCondition GetCondition() const OVERRIDE { |
| 3491 | return kCondB; |
| 3492 | } |
| 3493 | |
| 3494 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3495 | return kCondAE; |
| 3496 | } |
| 3497 | |
| 3498 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3499 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3500 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3501 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3502 | |
| 3503 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3504 | }; |
| 3505 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3506 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3507 | public: |
| 3508 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3509 | : HCondition(first, second, dex_pc) {} |
| 3510 | |
| 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()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3513 | } |
| 3514 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3515 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3516 | } |
| 3517 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3518 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3519 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3520 | UNREACHABLE(); |
| 3521 | } |
| 3522 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3523 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3524 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3525 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3529 | |
| 3530 | IfCondition GetCondition() const OVERRIDE { |
| 3531 | return kCondBE; |
| 3532 | } |
| 3533 | |
| 3534 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3535 | return kCondA; |
| 3536 | } |
| 3537 | |
| 3538 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3539 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3540 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3541 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3542 | |
| 3543 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3544 | }; |
| 3545 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3546 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3547 | public: |
| 3548 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3549 | : HCondition(first, second, dex_pc) {} |
| 3550 | |
| 3551 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3552 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3553 | } |
| 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(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3556 | } |
| 3557 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3558 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3559 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3560 | UNREACHABLE(); |
| 3561 | } |
| 3562 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3563 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3564 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3565 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | DECLARE_INSTRUCTION(Above); |
| 3569 | |
| 3570 | IfCondition GetCondition() const OVERRIDE { |
| 3571 | return kCondA; |
| 3572 | } |
| 3573 | |
| 3574 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3575 | return kCondBE; |
| 3576 | } |
| 3577 | |
| 3578 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3579 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3580 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3581 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3582 | |
| 3583 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3584 | }; |
| 3585 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3586 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3587 | public: |
| 3588 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3589 | : HCondition(first, second, dex_pc) {} |
| 3590 | |
| 3591 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3592 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3593 | } |
| 3594 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3595 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3596 | } |
| 3597 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3598 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3599 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3600 | UNREACHABLE(); |
| 3601 | } |
| 3602 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3603 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3604 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3605 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3609 | |
| 3610 | IfCondition GetCondition() const OVERRIDE { |
| 3611 | return kCondAE; |
| 3612 | } |
| 3613 | |
| 3614 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3615 | return kCondB; |
| 3616 | } |
| 3617 | |
| 3618 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3619 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3620 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3621 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3622 | |
| 3623 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3624 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3625 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3626 | // Instruction to check how two inputs compare to each other. |
| 3627 | // 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] | 3628 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3629 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3630 | // Note that `comparison_type` is the type of comparison performed |
| 3631 | // between the comparison's inputs, not the type of the instantiated |
| 3632 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3633 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3634 | HInstruction* first, |
| 3635 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3636 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3637 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3638 | : HBinaryOperation(Primitive::kPrimInt, |
| 3639 | first, |
| 3640 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3641 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3642 | dex_pc) { |
| 3643 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3644 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3645 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3646 | } |
| 3647 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3648 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3649 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3650 | |
| 3651 | template <typename T> |
| 3652 | int32_t ComputeFP(T x, T y) const { |
| 3653 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3654 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3655 | // Handle the bias. |
| 3656 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3657 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3658 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3659 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3660 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3661 | // reach this code path when processing a freshly built HIR |
| 3662 | // graph. However HCompare integer instructions can be synthesized |
| 3663 | // by the instruction simplifier to implement IntegerCompare and |
| 3664 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3665 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3666 | } |
| 3667 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3668 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3669 | } |
| 3670 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3671 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3672 | } |
| 3673 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3674 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3675 | } |
| 3676 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3677 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3678 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3679 | } |
| 3680 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3681 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3682 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3683 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3684 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3685 | bool IsGtBias() const { |
| 3686 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3687 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3688 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3689 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3690 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3691 | // Comparisons do not require a runtime call in any back end. |
| 3692 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3693 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3694 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3695 | DECLARE_INSTRUCTION(Compare); |
| 3696 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3697 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3698 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3699 | static constexpr size_t kFieldComparisonBiasSize = |
| 3700 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3701 | static constexpr size_t kNumberOfComparePackedBits = |
| 3702 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3703 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3704 | using ComparisonBiasField = |
| 3705 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3706 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3707 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3708 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3709 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3710 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3711 | } |
| 3712 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3713 | private: |
| 3714 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3715 | }; |
| 3716 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3717 | class HNewInstance FINAL : public HExpression<2> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3718 | public: |
| 3719 | HNewInstance(HInstruction* cls, |
| 3720 | HCurrentMethod* current_method, |
| 3721 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3722 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3723 | const DexFile& dex_file, |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3724 | bool needs_access_check, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3725 | bool finalizable, |
| 3726 | QuickEntrypointEnum entrypoint) |
| 3727 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3728 | type_index_(type_index), |
| 3729 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3730 | entrypoint_(entrypoint) { |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3731 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3732 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3733 | SetRawInputAt(0, cls); |
| 3734 | SetRawInputAt(1, current_method); |
| 3735 | } |
| 3736 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3737 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3738 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3739 | |
| 3740 | // Calls runtime so needs an environment. |
| 3741 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3742 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3743 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3744 | bool CanThrow() const OVERRIDE { return true; } |
| 3745 | |
| 3746 | // Needs to call into runtime to make sure it's instantiable/accessible. |
| 3747 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3748 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3749 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3750 | |
| 3751 | bool CanBeNull() const OVERRIDE { return false; } |
| 3752 | |
| 3753 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3754 | |
| 3755 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3756 | entrypoint_ = entrypoint; |
| 3757 | } |
| 3758 | |
| 3759 | bool IsStringAlloc() const; |
| 3760 | |
| 3761 | DECLARE_INSTRUCTION(NewInstance); |
| 3762 | |
| 3763 | private: |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3764 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfExpressionPackedBits; |
| 3765 | static constexpr size_t kFlagFinalizable = kFlagNeedsAccessCheck + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3766 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3767 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3768 | "Too many packed fields."); |
| 3769 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3770 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3771 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3772 | QuickEntrypointEnum entrypoint_; |
| 3773 | |
| 3774 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3775 | }; |
| 3776 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3777 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3778 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3779 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3780 | }; |
| 3781 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3782 | enum IntrinsicSideEffects { |
| 3783 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3784 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3785 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3786 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3787 | }; |
| 3788 | |
| 3789 | enum IntrinsicExceptions { |
| 3790 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3791 | kCanThrow // Intrinsic may throw exceptions. |
| 3792 | }; |
| 3793 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3794 | class HInvoke : public HInstruction { |
| 3795 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3796 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3797 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3798 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 3799 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 3800 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 3801 | } |
| 3802 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3803 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3804 | SetRawInputAt(index, argument); |
| 3805 | } |
| 3806 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3807 | // Return the number of arguments. This number can be lower than |
| 3808 | // the number of inputs returned by InputCount(), as some invoke |
| 3809 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3810 | // inputs at the end of their list of inputs. |
| 3811 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3812 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3813 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3814 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3815 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3816 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3817 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3818 | InvokeType GetInvokeType() const { |
| 3819 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3820 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3821 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3822 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3823 | return intrinsic_; |
| 3824 | } |
| 3825 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3826 | void SetIntrinsic(Intrinsics intrinsic, |
| 3827 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3828 | IntrinsicSideEffects side_effects, |
| 3829 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3830 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3831 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3832 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3833 | } |
| 3834 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 3835 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 3836 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3837 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3838 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 3839 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3840 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3841 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3842 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3843 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3844 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3845 | uint32_t* GetIntrinsicOptimizations() { |
| 3846 | return &intrinsic_optimizations_; |
| 3847 | } |
| 3848 | |
| 3849 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3850 | return &intrinsic_optimizations_; |
| 3851 | } |
| 3852 | |
| 3853 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3854 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3855 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
| 3856 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3857 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3858 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3859 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3860 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 3861 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3862 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3863 | static constexpr size_t kFieldReturnType = |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3864 | kFieldInvokeType + kFieldInvokeTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3865 | static constexpr size_t kFieldReturnTypeSize = |
| 3866 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3867 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3868 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3869 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3870 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3871 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3872 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3873 | HInvoke(ArenaAllocator* arena, |
| 3874 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3875 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3876 | Primitive::Type return_type, |
| 3877 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3878 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3879 | ArtMethod* resolved_method, |
| 3880 | InvokeType invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3881 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3882 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3883 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3884 | resolved_method_(resolved_method), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3885 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3886 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3887 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3888 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3889 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3890 | SetPackedField<ReturnTypeField>(return_type); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3891 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3892 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3893 | } |
| 3894 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3895 | uint32_t number_of_arguments_; |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3896 | ArtMethod* const resolved_method_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3897 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3898 | const uint32_t dex_method_index_; |
| 3899 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3900 | |
| 3901 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3902 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3903 | |
| 3904 | private: |
| 3905 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3906 | }; |
| 3907 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3908 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3909 | public: |
| 3910 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3911 | uint32_t number_of_arguments, |
| 3912 | Primitive::Type return_type, |
| 3913 | uint32_t dex_pc, |
| 3914 | uint32_t dex_method_index, |
| 3915 | InvokeType invoke_type) |
| 3916 | : HInvoke(arena, |
| 3917 | number_of_arguments, |
| 3918 | 0u /* number_of_other_inputs */, |
| 3919 | return_type, |
| 3920 | dex_pc, |
| 3921 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 3922 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3923 | invoke_type) { |
| 3924 | } |
| 3925 | |
| 3926 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3927 | |
| 3928 | private: |
| 3929 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3930 | }; |
| 3931 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3932 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3933 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3934 | // Requirements of this method call regarding the class |
| 3935 | // initialization (clinit) check of its declaring class. |
| 3936 | enum class ClinitCheckRequirement { |
| 3937 | kNone, // Class already initialized. |
| 3938 | kExplicit, // Static call having explicit clinit check as last input. |
| 3939 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3940 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3941 | }; |
| 3942 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3943 | // Determines how to load the target ArtMethod*. |
| 3944 | enum class MethodLoadKind { |
| 3945 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3946 | kStringInit, |
| 3947 | |
| 3948 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3949 | kRecursive, |
| 3950 | |
| 3951 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3952 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3953 | kDirectAddress, |
| 3954 | |
| 3955 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3956 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3957 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3958 | // the image relocatable or not. |
| 3959 | kDirectAddressWithFixup, |
| 3960 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3961 | // Load from resolved methods array in the dex cache using a PC-relative load. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3962 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3963 | // may cause class initialization (the entry may point to a resolution method), |
| 3964 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3965 | kDexCachePcRelative, |
| 3966 | |
| 3967 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3968 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3969 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3970 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3971 | kDexCacheViaMethod, |
| 3972 | }; |
| 3973 | |
| 3974 | // Determines the location of the code pointer. |
| 3975 | enum class CodePtrLocation { |
| 3976 | // Recursive call, use local PC-relative call instruction. |
| 3977 | kCallSelf, |
| 3978 | |
| 3979 | // Use PC-relative call instruction patched at link time. |
| 3980 | // Used for calls within an oat file, boot->boot or app->app. |
| 3981 | kCallPCRelative, |
| 3982 | |
| 3983 | // Call to a known target address, embed the direct address in code. |
| 3984 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3985 | kCallDirect, |
| 3986 | |
| 3987 | // Call to a target address that will be known at link time, embed the direct |
| 3988 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3989 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3990 | // the image relocatable or not. |
| 3991 | kCallDirectWithFixup, |
| 3992 | |
| 3993 | // Use code pointer from the ArtMethod*. |
| 3994 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3995 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3996 | kCallArtMethod, |
| 3997 | }; |
| 3998 | |
| 3999 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4000 | MethodLoadKind method_load_kind; |
| 4001 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4002 | // The method load data holds |
| 4003 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4004 | // Note that there are multiple string init methods, each having its own offset. |
| 4005 | // - the method address for kDirectAddress |
| 4006 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4007 | uint64_t method_load_data; |
| 4008 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4009 | }; |
| 4010 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4011 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 4012 | uint32_t number_of_arguments, |
| 4013 | Primitive::Type return_type, |
| 4014 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4015 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4016 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4017 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4018 | InvokeType invoke_type, |
| 4019 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4020 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4021 | : HInvoke(arena, |
| 4022 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4023 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4024 | // potentially one other if the clinit check is explicit, and potentially |
| 4025 | // one other if the method is a string factory. |
| 4026 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4027 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4028 | return_type, |
| 4029 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4030 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4031 | resolved_method, |
| 4032 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4033 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4034 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4035 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4036 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4037 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4038 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4039 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4040 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4041 | |
| 4042 | // Using the current method is the default and once we find a better |
| 4043 | // method load kind, we should not go back to using the current method. |
| 4044 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4045 | |
| 4046 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4047 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4048 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4049 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4050 | dispatch_info_ = dispatch_info; |
| 4051 | } |
| 4052 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4053 | void AddSpecialInput(HInstruction* input) { |
| 4054 | // We allow only one special input. |
| 4055 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4056 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4057 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4058 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4059 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4060 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4061 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4062 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4063 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4064 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4065 | DCHECK(!input_records.empty()); |
| 4066 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4067 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4068 | // Note: `last_input` may be null during arguments setup. |
| 4069 | if (last_input != nullptr) { |
| 4070 | // `last_input` is the last input of a static invoke marked as having |
| 4071 | // an explicit clinit check. It must either be: |
| 4072 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4073 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4074 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4075 | } |
| 4076 | } |
| 4077 | return input_records; |
| 4078 | } |
| 4079 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4080 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4081 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4082 | // TODO: for intrinsics we can generate implicit null checks. |
| 4083 | return false; |
| 4084 | } |
| 4085 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4086 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4087 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4088 | } |
| 4089 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4090 | // Get the index of the special input, if any. |
| 4091 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4092 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4093 | // method pointer; otherwise there may be one platform-specific special input, |
| 4094 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4095 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4096 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4097 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4098 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4099 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4100 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4101 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4102 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4103 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4104 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4105 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 4106 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4107 | bool HasCurrentMethodInput() const { |
| 4108 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4109 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4110 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4111 | return true; |
| 4112 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4113 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4114 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4115 | return false; |
| 4116 | } |
| 4117 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4118 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4119 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4120 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4121 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4122 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | uint64_t GetMethodAddress() const { |
| 4126 | DCHECK(HasMethodAddress()); |
| 4127 | return dispatch_info_.method_load_data; |
| 4128 | } |
| 4129 | |
| 4130 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4131 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4132 | return dispatch_info_.method_load_data; |
| 4133 | } |
| 4134 | |
| 4135 | uint64_t GetDirectCodePtr() const { |
| 4136 | DCHECK(HasDirectCodePtr()); |
| 4137 | return dispatch_info_.direct_code_ptr; |
| 4138 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4139 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4140 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4141 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4142 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4143 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4144 | // Is this instruction a call to a static method? |
| 4145 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4146 | return GetInvokeType() == kStatic; |
| 4147 | } |
| 4148 | |
| 4149 | MethodReference GetTargetMethod() const { |
| 4150 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4151 | } |
| 4152 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4153 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4154 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4155 | // instruction; only relevant for static calls with explicit clinit check. |
| 4156 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4157 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4158 | size_t last_input_index = inputs_.size() - 1u; |
| 4159 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4160 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4161 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4162 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4163 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4164 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4165 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | // 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] | 4169 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4170 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4171 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | // Is this a call to a static method whose declaring class has an |
| 4175 | // implicit intialization check requirement? |
| 4176 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4177 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4178 | } |
| 4179 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4180 | // Does this method load kind need the current method as an input? |
| 4181 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4182 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4183 | } |
| 4184 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4185 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4186 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4187 | protected: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4188 | void InsertInputAt(size_t index, HInstruction* input); |
| 4189 | void RemoveInputAt(size_t index); |
| 4190 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4191 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4192 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4193 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4194 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4195 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4196 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4197 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4198 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4199 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4200 | kFieldClinitCheckRequirement, |
| 4201 | kFieldClinitCheckRequirementSize>; |
| 4202 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4203 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4204 | MethodReference target_method_; |
| 4205 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4206 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4207 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4208 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4209 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4210 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4211 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4212 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4213 | public: |
| 4214 | HInvokeVirtual(ArenaAllocator* arena, |
| 4215 | uint32_t number_of_arguments, |
| 4216 | Primitive::Type return_type, |
| 4217 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4218 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4219 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4220 | uint32_t vtable_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4221 | : HInvoke(arena, |
| 4222 | number_of_arguments, |
| 4223 | 0u, |
| 4224 | return_type, |
| 4225 | dex_pc, |
| 4226 | dex_method_index, |
| 4227 | resolved_method, |
| 4228 | kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4229 | vtable_index_(vtable_index) {} |
| 4230 | |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4231 | bool CanBeNull() const OVERRIDE { |
| 4232 | switch (GetIntrinsic()) { |
| 4233 | case Intrinsics::kThreadCurrentThread: |
| 4234 | case Intrinsics::kStringBufferAppend: |
| 4235 | case Intrinsics::kStringBufferToString: |
| 4236 | case Intrinsics::kStringBuilderAppend: |
| 4237 | case Intrinsics::kStringBuilderToString: |
| 4238 | return false; |
| 4239 | default: |
| 4240 | return HInvoke::CanBeNull(); |
| 4241 | } |
| 4242 | } |
| 4243 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4244 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4245 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4246 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4247 | } |
| 4248 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4249 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4250 | |
| 4251 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4252 | |
| 4253 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4254 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4255 | const uint32_t vtable_index_; |
| 4256 | |
| 4257 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4258 | }; |
| 4259 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4260 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4261 | public: |
| 4262 | HInvokeInterface(ArenaAllocator* arena, |
| 4263 | uint32_t number_of_arguments, |
| 4264 | Primitive::Type return_type, |
| 4265 | uint32_t dex_pc, |
| 4266 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4267 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4268 | uint32_t imt_index) |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4269 | : HInvoke(arena, |
| 4270 | number_of_arguments, |
| 4271 | 0u, |
| 4272 | return_type, |
| 4273 | dex_pc, |
| 4274 | dex_method_index, |
| 4275 | resolved_method, |
| 4276 | kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4277 | imt_index_(imt_index) {} |
| 4278 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4279 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4280 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4281 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4282 | } |
| 4283 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4284 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4285 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4286 | |
| 4287 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4288 | |
| 4289 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4290 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4291 | const uint32_t imt_index_; |
| 4292 | |
| 4293 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4294 | }; |
| 4295 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4296 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4297 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4298 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4299 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4300 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4301 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4302 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4303 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4304 | |
| 4305 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4306 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4307 | } |
| 4308 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4309 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4310 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4311 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4312 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4313 | } |
| 4314 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4315 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4316 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4317 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4318 | DECLARE_INSTRUCTION(Neg); |
| 4319 | |
| 4320 | private: |
| 4321 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4322 | }; |
| 4323 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4324 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4325 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4326 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4327 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4328 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4329 | dex::TypeIndex type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4330 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4331 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4332 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4333 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4334 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4335 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4336 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4337 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4338 | } |
| 4339 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4340 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4341 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4342 | |
| 4343 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4344 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4345 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4346 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4347 | bool CanThrow() const OVERRIDE { return true; } |
| 4348 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4349 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4350 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4351 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4352 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4353 | DECLARE_INSTRUCTION(NewArray); |
| 4354 | |
| 4355 | private: |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4356 | const dex::TypeIndex type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4357 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4358 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4359 | |
| 4360 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4361 | }; |
| 4362 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4363 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4364 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4365 | HAdd(Primitive::Type result_type, |
| 4366 | HInstruction* left, |
| 4367 | HInstruction* right, |
| 4368 | uint32_t dex_pc = kNoDexPc) |
| 4369 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4370 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4371 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4372 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4373 | 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] | 4374 | |
| 4375 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4376 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4377 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4378 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4379 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4380 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4381 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4382 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4383 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4384 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4385 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4386 | } |
| 4387 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4388 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4389 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4390 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4391 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4392 | DECLARE_INSTRUCTION(Add); |
| 4393 | |
| 4394 | private: |
| 4395 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4396 | }; |
| 4397 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4398 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4399 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4400 | HSub(Primitive::Type result_type, |
| 4401 | HInstruction* left, |
| 4402 | HInstruction* right, |
| 4403 | uint32_t dex_pc = kNoDexPc) |
| 4404 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4405 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4406 | 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] | 4407 | |
| 4408 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4409 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4410 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4411 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4412 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4413 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4414 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4415 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4416 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4417 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4418 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4419 | } |
| 4420 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4421 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4422 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4423 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4424 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4425 | DECLARE_INSTRUCTION(Sub); |
| 4426 | |
| 4427 | private: |
| 4428 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4429 | }; |
| 4430 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4431 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4432 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4433 | HMul(Primitive::Type result_type, |
| 4434 | HInstruction* left, |
| 4435 | HInstruction* right, |
| 4436 | uint32_t dex_pc = kNoDexPc) |
| 4437 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4438 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4439 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4440 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4441 | 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] | 4442 | |
| 4443 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4444 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4445 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4446 | } |
| 4447 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4448 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4449 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4450 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4451 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4452 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4453 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4454 | } |
| 4455 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4456 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4457 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4458 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4459 | |
| 4460 | DECLARE_INSTRUCTION(Mul); |
| 4461 | |
| 4462 | private: |
| 4463 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4464 | }; |
| 4465 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4466 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4467 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4468 | HDiv(Primitive::Type result_type, |
| 4469 | HInstruction* left, |
| 4470 | HInstruction* right, |
| 4471 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4472 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4473 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4474 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4475 | T ComputeIntegral(T x, T y) const { |
| 4476 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4477 | // Our graph structure ensures we never have 0 for `y` during |
| 4478 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4479 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4480 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4481 | return (y == -1) ? -x : x / y; |
| 4482 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4483 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4484 | template <typename T> |
| 4485 | T ComputeFP(T x, T y) const { |
| 4486 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4487 | return x / y; |
| 4488 | } |
| 4489 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4490 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4491 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4492 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4493 | } |
| 4494 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4495 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4496 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4497 | } |
| 4498 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4499 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4500 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4501 | } |
| 4502 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4503 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4504 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4505 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4506 | |
| 4507 | DECLARE_INSTRUCTION(Div); |
| 4508 | |
| 4509 | private: |
| 4510 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4511 | }; |
| 4512 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4513 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4514 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4515 | HRem(Primitive::Type result_type, |
| 4516 | HInstruction* left, |
| 4517 | HInstruction* right, |
| 4518 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 4519 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4520 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4521 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4522 | T ComputeIntegral(T x, T y) const { |
| 4523 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4524 | // Our graph structure ensures we never have 0 for `y` during |
| 4525 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4526 | DCHECK_NE(y, 0); |
| 4527 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4528 | return (y == -1) ? 0 : x % y; |
| 4529 | } |
| 4530 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4531 | template <typename T> |
| 4532 | T ComputeFP(T x, T y) const { |
| 4533 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4534 | return std::fmod(x, y); |
| 4535 | } |
| 4536 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4537 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4538 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4539 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4540 | } |
| 4541 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4542 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4543 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4544 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4545 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4546 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4547 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4548 | } |
| 4549 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4550 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4551 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4552 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4553 | |
| 4554 | DECLARE_INSTRUCTION(Rem); |
| 4555 | |
| 4556 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4557 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4558 | }; |
| 4559 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4560 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4561 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4562 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4563 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4564 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4565 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4566 | SetRawInputAt(0, value); |
| 4567 | } |
| 4568 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4569 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4570 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4571 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4572 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4573 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4574 | return true; |
| 4575 | } |
| 4576 | |
| 4577 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4578 | bool CanThrow() const OVERRIDE { return true; } |
| 4579 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4580 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4581 | |
| 4582 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4583 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4584 | }; |
| 4585 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4586 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4587 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4588 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4589 | HInstruction* value, |
| 4590 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4591 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4592 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4593 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4594 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4595 | } |
| 4596 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4597 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4598 | 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] | 4599 | return value << (distance & max_shift_distance); |
| 4600 | } |
| 4601 | |
| 4602 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4603 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4604 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4605 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4606 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4607 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4608 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4609 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4610 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4611 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4612 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4613 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4614 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4615 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4616 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4617 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4618 | UNREACHABLE(); |
| 4619 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4620 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4621 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4622 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4623 | UNREACHABLE(); |
| 4624 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4625 | |
| 4626 | DECLARE_INSTRUCTION(Shl); |
| 4627 | |
| 4628 | private: |
| 4629 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4630 | }; |
| 4631 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4632 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4633 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4634 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4635 | HInstruction* value, |
| 4636 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4637 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4638 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4639 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4640 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4641 | } |
| 4642 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4643 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4644 | 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] | 4645 | return value >> (distance & max_shift_distance); |
| 4646 | } |
| 4647 | |
| 4648 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4649 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4650 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4651 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4652 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4653 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4654 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4655 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4656 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4657 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4658 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4659 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4660 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4661 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4662 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4663 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4664 | UNREACHABLE(); |
| 4665 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4666 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4667 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4668 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4669 | UNREACHABLE(); |
| 4670 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4671 | |
| 4672 | DECLARE_INSTRUCTION(Shr); |
| 4673 | |
| 4674 | private: |
| 4675 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4676 | }; |
| 4677 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4678 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4679 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4680 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4681 | HInstruction* value, |
| 4682 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4683 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4684 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4685 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4686 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4687 | } |
| 4688 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4689 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4690 | 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] | 4691 | typedef typename std::make_unsigned<T>::type V; |
| 4692 | V ux = static_cast<V>(value); |
| 4693 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4694 | } |
| 4695 | |
| 4696 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4697 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4698 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4699 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4700 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4701 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4702 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4703 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4704 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4705 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4706 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4707 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4708 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4709 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4710 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4711 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4712 | UNREACHABLE(); |
| 4713 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4714 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4715 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4716 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4717 | UNREACHABLE(); |
| 4718 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4719 | |
| 4720 | DECLARE_INSTRUCTION(UShr); |
| 4721 | |
| 4722 | private: |
| 4723 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4724 | }; |
| 4725 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4726 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4727 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4728 | HAnd(Primitive::Type result_type, |
| 4729 | HInstruction* left, |
| 4730 | HInstruction* right, |
| 4731 | uint32_t dex_pc = kNoDexPc) |
| 4732 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4733 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4734 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4735 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4736 | 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] | 4737 | |
| 4738 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4739 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4740 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4741 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4742 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4743 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4744 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4745 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4746 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4747 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4748 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4749 | UNREACHABLE(); |
| 4750 | } |
| 4751 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4752 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4753 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4754 | UNREACHABLE(); |
| 4755 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4756 | |
| 4757 | DECLARE_INSTRUCTION(And); |
| 4758 | |
| 4759 | private: |
| 4760 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4761 | }; |
| 4762 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4763 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4764 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4765 | HOr(Primitive::Type result_type, |
| 4766 | HInstruction* left, |
| 4767 | HInstruction* right, |
| 4768 | uint32_t dex_pc = kNoDexPc) |
| 4769 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4770 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4771 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4772 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4773 | 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] | 4774 | |
| 4775 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4776 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4777 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4778 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4779 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4780 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4781 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4782 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4783 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4784 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4785 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4786 | UNREACHABLE(); |
| 4787 | } |
| 4788 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4789 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4790 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4791 | UNREACHABLE(); |
| 4792 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4793 | |
| 4794 | DECLARE_INSTRUCTION(Or); |
| 4795 | |
| 4796 | private: |
| 4797 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4798 | }; |
| 4799 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4800 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4801 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4802 | HXor(Primitive::Type result_type, |
| 4803 | HInstruction* left, |
| 4804 | HInstruction* right, |
| 4805 | uint32_t dex_pc = kNoDexPc) |
| 4806 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4807 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4808 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4809 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4810 | 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] | 4811 | |
| 4812 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4813 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4814 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4815 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4816 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4817 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4818 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4819 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4820 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4821 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4822 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4823 | UNREACHABLE(); |
| 4824 | } |
| 4825 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4826 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4827 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4828 | UNREACHABLE(); |
| 4829 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4830 | |
| 4831 | DECLARE_INSTRUCTION(Xor); |
| 4832 | |
| 4833 | private: |
| 4834 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4835 | }; |
| 4836 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4837 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4838 | public: |
| 4839 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4840 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4841 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4842 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4843 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4844 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4845 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4846 | 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] | 4847 | typedef typename std::make_unsigned<T>::type V; |
| 4848 | V ux = static_cast<V>(value); |
| 4849 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4850 | return static_cast<T>(ux); |
| 4851 | } else { |
| 4852 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4853 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4854 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4855 | } |
| 4856 | } |
| 4857 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4858 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4859 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4860 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4861 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4862 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4863 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4864 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4865 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4866 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4867 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4868 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4869 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4870 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4871 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4872 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4873 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4874 | UNREACHABLE(); |
| 4875 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4876 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4877 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4878 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4879 | UNREACHABLE(); |
| 4880 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4881 | |
| 4882 | DECLARE_INSTRUCTION(Ror); |
| 4883 | |
| 4884 | private: |
| 4885 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4886 | }; |
| 4887 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4888 | // The value of a parameter in this method. Its location depends on |
| 4889 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4890 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4891 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4892 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4893 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4894 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4895 | Primitive::Type parameter_type, |
| 4896 | bool is_this = false) |
| 4897 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4898 | dex_file_(dex_file), |
| 4899 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4900 | index_(index) { |
| 4901 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4902 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4903 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4904 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4905 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4906 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4907 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4908 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4909 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4910 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4911 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4912 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4913 | DECLARE_INSTRUCTION(ParameterValue); |
| 4914 | |
| 4915 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4916 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4917 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4918 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4919 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4920 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4921 | "Too many packed fields."); |
| 4922 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4923 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4924 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4925 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4926 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4927 | const uint8_t index_; |
| 4928 | |
| 4929 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4930 | }; |
| 4931 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4932 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4933 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4934 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4935 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4936 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4937 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4938 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4939 | return true; |
| 4940 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4941 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4942 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4943 | |
| 4944 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4945 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4946 | } |
| 4947 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4948 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4949 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4950 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4951 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4952 | UNREACHABLE(); |
| 4953 | } |
| 4954 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4955 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4956 | UNREACHABLE(); |
| 4957 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4958 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4959 | DECLARE_INSTRUCTION(Not); |
| 4960 | |
| 4961 | private: |
| 4962 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4963 | }; |
| 4964 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4965 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4966 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4967 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4968 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4969 | |
| 4970 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4971 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4972 | return true; |
| 4973 | } |
| 4974 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4975 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4976 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4977 | return !x; |
| 4978 | } |
| 4979 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4980 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4981 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4982 | } |
| 4983 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4984 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4985 | UNREACHABLE(); |
| 4986 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4987 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4988 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4989 | UNREACHABLE(); |
| 4990 | } |
| 4991 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4992 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4993 | UNREACHABLE(); |
| 4994 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4995 | |
| 4996 | DECLARE_INSTRUCTION(BooleanNot); |
| 4997 | |
| 4998 | private: |
| 4999 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 5000 | }; |
| 5001 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5002 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5003 | public: |
| 5004 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 5005 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5006 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5007 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5008 | // Invariant: We should never generate a conversion to a Boolean value. |
| 5009 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | HInstruction* GetInput() const { return InputAt(0); } |
| 5013 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 5014 | Primitive::Type GetResultType() const { return GetType(); } |
| 5015 | |
| 5016 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5017 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5018 | return true; |
| 5019 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5020 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5021 | // Try to statically evaluate the conversion and return a HConstant |
| 5022 | // containing the result. If the input cannot be converted, return nullptr. |
| 5023 | HConstant* TryStaticEvaluation() const; |
| 5024 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5025 | DECLARE_INSTRUCTION(TypeConversion); |
| 5026 | |
| 5027 | private: |
| 5028 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 5029 | }; |
| 5030 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5031 | static constexpr uint32_t kNoRegNumber = -1; |
| 5032 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5033 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5034 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5035 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 5036 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5037 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5038 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5039 | SetRawInputAt(0, value); |
| 5040 | } |
| 5041 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5042 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5043 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5044 | return true; |
| 5045 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5046 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5047 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5048 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5049 | bool CanThrow() const OVERRIDE { return true; } |
| 5050 | |
| 5051 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5052 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5053 | |
| 5054 | DECLARE_INSTRUCTION(NullCheck); |
| 5055 | |
| 5056 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5057 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 5058 | }; |
| 5059 | |
| 5060 | class FieldInfo : public ValueObject { |
| 5061 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5062 | FieldInfo(MemberOffset field_offset, |
| 5063 | Primitive::Type field_type, |
| 5064 | bool is_volatile, |
| 5065 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5066 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5067 | const DexFile& dex_file, |
| 5068 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5069 | : field_offset_(field_offset), |
| 5070 | field_type_(field_type), |
| 5071 | is_volatile_(is_volatile), |
| 5072 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5073 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5074 | dex_file_(dex_file), |
| 5075 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5076 | |
| 5077 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5078 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5079 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5080 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5081 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5082 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5083 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5084 | |
| 5085 | private: |
| 5086 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5087 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5088 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5089 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5090 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5091 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5092 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5093 | }; |
| 5094 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5095 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5096 | public: |
| 5097 | HInstanceFieldGet(HInstruction* value, |
| 5098 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5099 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5100 | bool is_volatile, |
| 5101 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5102 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5103 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5104 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5105 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5106 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5107 | field_info_(field_offset, |
| 5108 | field_type, |
| 5109 | is_volatile, |
| 5110 | field_idx, |
| 5111 | declaring_class_def_index, |
| 5112 | dex_file, |
| 5113 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5114 | SetRawInputAt(0, value); |
| 5115 | } |
| 5116 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5117 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5118 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5119 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5120 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5121 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5122 | } |
| 5123 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5124 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5125 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5126 | } |
| 5127 | |
| 5128 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5129 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5130 | } |
| 5131 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5132 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5133 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5134 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5135 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5136 | |
| 5137 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5138 | |
| 5139 | private: |
| 5140 | const FieldInfo field_info_; |
| 5141 | |
| 5142 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5143 | }; |
| 5144 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5145 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5146 | public: |
| 5147 | HInstanceFieldSet(HInstruction* object, |
| 5148 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5149 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5150 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5151 | bool is_volatile, |
| 5152 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5153 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5154 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5155 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5156 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5157 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5158 | field_info_(field_offset, |
| 5159 | field_type, |
| 5160 | is_volatile, |
| 5161 | field_idx, |
| 5162 | declaring_class_def_index, |
| 5163 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5164 | dex_cache) { |
| 5165 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5166 | SetRawInputAt(0, object); |
| 5167 | SetRawInputAt(1, value); |
| 5168 | } |
| 5169 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5170 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5171 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5172 | } |
| 5173 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5174 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5175 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5176 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5177 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5178 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5179 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5180 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5181 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5182 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5183 | |
| 5184 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5185 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5186 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5187 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5188 | "Too many packed fields."); |
| 5189 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5190 | const FieldInfo field_info_; |
| 5191 | |
| 5192 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5193 | }; |
| 5194 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5195 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5196 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5197 | HArrayGet(HInstruction* array, |
| 5198 | HInstruction* index, |
| 5199 | Primitive::Type type, |
| 5200 | uint32_t dex_pc, |
| 5201 | bool is_string_char_at = false) |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5202 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5203 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5204 | SetRawInputAt(0, array); |
| 5205 | SetRawInputAt(1, index); |
| 5206 | } |
| 5207 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5208 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5209 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5210 | return true; |
| 5211 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5212 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5213 | // TODO: We can be smarter here. |
| 5214 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5215 | // which generates the implicit null check. There are cases when these can be removed |
| 5216 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5217 | // implicit check here (as long as the address falls in the first page). |
| 5218 | return false; |
| 5219 | } |
| 5220 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5221 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5222 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5223 | if (kIsDebugBuild && result) { |
| 5224 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5225 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5226 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5227 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5228 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5229 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5230 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5231 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5232 | } |
| 5233 | } |
| 5234 | return result; |
| 5235 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5236 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5237 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5238 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5239 | HInstruction* GetArray() const { return InputAt(0); } |
| 5240 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5241 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5242 | DECLARE_INSTRUCTION(ArrayGet); |
| 5243 | |
| 5244 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5245 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5246 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5247 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5248 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5249 | // a flag, so that code generators don't need to do the locking. |
| 5250 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5251 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5252 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5253 | "Too many packed fields."); |
| 5254 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5255 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5256 | }; |
| 5257 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5258 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5259 | public: |
| 5260 | HArraySet(HInstruction* array, |
| 5261 | HInstruction* index, |
| 5262 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5263 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5264 | uint32_t dex_pc) |
| 5265 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5266 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5267 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5268 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5269 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5270 | SetRawInputAt(0, array); |
| 5271 | SetRawInputAt(1, index); |
| 5272 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5273 | // Make a best guess now, may be refined during SSA building. |
| 5274 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5275 | } |
| 5276 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5277 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5278 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5279 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5280 | } |
| 5281 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5282 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5283 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5284 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5285 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5286 | // TODO: Same as for ArrayGet. |
| 5287 | return false; |
| 5288 | } |
| 5289 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5290 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5291 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5292 | } |
| 5293 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5294 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5295 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5296 | } |
| 5297 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5298 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5299 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5300 | } |
| 5301 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5302 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5303 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5304 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5305 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5306 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5307 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5308 | HInstruction* GetArray() const { return InputAt(0); } |
| 5309 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5310 | HInstruction* GetValue() const { return InputAt(2); } |
| 5311 | |
| 5312 | Primitive::Type GetComponentType() const { |
| 5313 | // The Dex format does not type floating point index operations. Since the |
| 5314 | // `expected_component_type_` is set during building and can therefore not |
| 5315 | // be correct, we also check what is the value type. If it is a floating |
| 5316 | // point type, we must use that type. |
| 5317 | Primitive::Type value_type = GetValue()->GetType(); |
| 5318 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5319 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5320 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5321 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5322 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5323 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5324 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5325 | } |
| 5326 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5327 | void ComputeSideEffects() { |
| 5328 | Primitive::Type type = GetComponentType(); |
| 5329 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5330 | SideEffectsForArchRuntimeCalls(type))); |
| 5331 | } |
| 5332 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5333 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5334 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5335 | } |
| 5336 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5337 | DECLARE_INSTRUCTION(ArraySet); |
| 5338 | |
| 5339 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5340 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5341 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5342 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5343 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5344 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5345 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5346 | // Cached information for the reference_type_info_ so that codegen |
| 5347 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5348 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5349 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5350 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5351 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5352 | using ExpectedComponentTypeField = |
| 5353 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5354 | |
| 5355 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5356 | }; |
| 5357 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5358 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5359 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5360 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5361 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5362 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5363 | // Note that arrays do not change length, so the instruction does not |
| 5364 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5365 | SetRawInputAt(0, array); |
| 5366 | } |
| 5367 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5368 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5369 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5370 | return true; |
| 5371 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5372 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5373 | return obj == InputAt(0); |
| 5374 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5375 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5376 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5377 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5378 | DECLARE_INSTRUCTION(ArrayLength); |
| 5379 | |
| 5380 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5381 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5382 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5383 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5384 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5385 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5386 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5387 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5388 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5389 | "Too many packed fields."); |
| 5390 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5391 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5392 | }; |
| 5393 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5394 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5395 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5396 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5397 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5398 | HBoundsCheck(HInstruction* index, |
| 5399 | HInstruction* length, |
| 5400 | uint32_t dex_pc, |
| 5401 | uint32_t string_char_at_method_index = DexFile::kDexNoIndex) |
| 5402 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc), |
| 5403 | string_char_at_method_index_(string_char_at_method_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5404 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5405 | SetRawInputAt(0, index); |
| 5406 | SetRawInputAt(1, length); |
| 5407 | } |
| 5408 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5409 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5410 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5411 | return true; |
| 5412 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5413 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5414 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5415 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5416 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5417 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5418 | bool IsStringCharAt() const { return GetStringCharAtMethodIndex() != DexFile::kDexNoIndex; } |
| 5419 | uint32_t GetStringCharAtMethodIndex() const { return string_char_at_method_index_; } |
| 5420 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5421 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5422 | |
| 5423 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5424 | |
| 5425 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5426 | // We treat a String as an array, creating the HBoundsCheck from String.charAt() |
| 5427 | // intrinsic in the instruction simplifier. We want to include the String.charAt() |
| 5428 | // in the stack trace if we actually throw the StringIndexOutOfBoundsException, |
| 5429 | // so we need to create an HEnvironment which will be translated to an InlineInfo |
| 5430 | // indicating the extra stack frame. Since we add this HEnvironment quite late, |
| 5431 | // in the PrepareForRegisterAllocation pass, we need to remember the method index |
| 5432 | // from the invoke as we don't want to look again at the dex bytecode. |
| 5433 | uint32_t string_char_at_method_index_; // DexFile::kDexNoIndex if regular array. |
| 5434 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5435 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5436 | }; |
| 5437 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5438 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5439 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5440 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5441 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5442 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5443 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5444 | return true; |
| 5445 | } |
| 5446 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5447 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5448 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5449 | |
| 5450 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5451 | |
| 5452 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5453 | // Only used for code generation, in order to share the same slow path between back edges |
| 5454 | // of a same loop. |
| 5455 | SlowPathCode* slow_path_; |
| 5456 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5457 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5458 | }; |
| 5459 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5460 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5461 | // It ensures that we can generate line number and local variables at this point. |
| 5462 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5463 | public: |
| 5464 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5465 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5466 | |
| 5467 | bool NeedsEnvironment() const OVERRIDE { |
| 5468 | return true; |
| 5469 | } |
| 5470 | |
| 5471 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5472 | |
| 5473 | private: |
| 5474 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5475 | }; |
| 5476 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5477 | /** |
| 5478 | * Instruction to load a Class object. |
| 5479 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5480 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5481 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5482 | // Determines how to load the Class. |
| 5483 | enum class LoadKind { |
| 5484 | // Use the Class* from the method's own ArtMethod*. |
| 5485 | kReferrersClass, |
| 5486 | |
| 5487 | // Use boot image Class* address that will be known at link time. |
| 5488 | // Used for boot image classes referenced by boot image code in non-PIC mode. |
| 5489 | kBootImageLinkTimeAddress, |
| 5490 | |
| 5491 | // Use PC-relative boot image Class* address that will be known at link time. |
| 5492 | // Used for boot image classes referenced by boot image code in PIC mode. |
| 5493 | kBootImageLinkTimePcRelative, |
| 5494 | |
| 5495 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5496 | // Used for boot image classes referenced by apps in AOT- and JIT-compiled code. |
| 5497 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5498 | // GetIncludePatchInformation(). |
| 5499 | kBootImageAddress, |
| 5500 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5501 | // Load from the root table associated with the JIT compiled method. |
| 5502 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5503 | |
| 5504 | // Load from resolved types array in the dex cache using a PC-relative load. |
| 5505 | // Used for classes outside boot image when we know that we can access |
| 5506 | // the dex cache arrays using a PC-relative load. |
| 5507 | kDexCachePcRelative, |
| 5508 | |
| 5509 | // Load from resolved types array accessed through the class loaded from |
| 5510 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5511 | // all other types are unavailable. |
| 5512 | kDexCacheViaMethod, |
| 5513 | |
| 5514 | kLast = kDexCacheViaMethod |
| 5515 | }; |
| 5516 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5517 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5518 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5519 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5520 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5521 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame^] | 5522 | bool needs_access_check) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5523 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5524 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5525 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5526 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5527 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5528 | // Referrers class should not need access check. We never inline unverified |
| 5529 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5530 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5531 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5532 | SetPackedField<LoadKindField>( |
| 5533 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kDexCacheViaMethod); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5534 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame^] | 5535 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5536 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5537 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5538 | } |
| 5539 | |
| 5540 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5541 | DCHECK(HasAddress(load_kind)); |
| 5542 | load_data_.address = address; |
| 5543 | SetLoadKindInternal(load_kind); |
| 5544 | } |
| 5545 | |
| 5546 | void SetLoadKindWithTypeReference(LoadKind load_kind, |
| 5547 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5548 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5549 | DCHECK(HasTypeReference(load_kind)); |
| 5550 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5551 | DCHECK_EQ(type_index_, type_index); |
| 5552 | SetLoadKindInternal(load_kind); |
| 5553 | } |
| 5554 | |
| 5555 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5556 | const DexFile& dex_file, |
| 5557 | uint32_t element_index) { |
| 5558 | DCHECK(HasDexCacheReference(load_kind)); |
| 5559 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5560 | load_data_.dex_cache_element_index = element_index; |
| 5561 | SetLoadKindInternal(load_kind); |
| 5562 | } |
| 5563 | |
| 5564 | LoadKind GetLoadKind() const { |
| 5565 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5566 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5567 | |
| 5568 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5569 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5570 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5571 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5572 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5573 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5574 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5575 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5576 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5577 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5578 | } |
| 5579 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5580 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5581 | // The entrypoint the code generator is going to call does not do |
| 5582 | // clinit of the class. |
| 5583 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5584 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5585 | } |
| 5586 | |
| 5587 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5588 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5589 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5590 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5591 | } |
| 5592 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5593 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5594 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5595 | } |
| 5596 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5597 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5598 | return loaded_class_rti_; |
| 5599 | } |
| 5600 | |
| 5601 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5602 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5603 | DCHECK(rti.IsExact()); |
| 5604 | loaded_class_rti_ = rti; |
| 5605 | } |
| 5606 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5607 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5608 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5609 | |
| 5610 | uint32_t GetDexCacheElementOffset() const; |
| 5611 | |
| 5612 | uint64_t GetAddress() const { |
| 5613 | DCHECK(HasAddress(GetLoadKind())); |
| 5614 | return load_data_.address; |
| 5615 | } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5616 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5617 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5618 | return !IsReferrersClass(); |
| 5619 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5620 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5621 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5622 | return SideEffects::CanTriggerGC(); |
| 5623 | } |
| 5624 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5625 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5626 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5627 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5628 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5629 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5630 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5631 | void MarkInDexCache() { |
| 5632 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5633 | DCHECK(!NeedsEnvironment()); |
| 5634 | RemoveEnvironment(); |
| 5635 | SetSideEffects(SideEffects::None()); |
| 5636 | } |
| 5637 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5638 | void MarkInBootImage() { |
| 5639 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 5640 | } |
| 5641 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5642 | void AddSpecialInput(HInstruction* special_input); |
| 5643 | |
| 5644 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5645 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5646 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5647 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 5648 | } |
| 5649 | |
| 5650 | Primitive::Type GetType() const OVERRIDE { |
| 5651 | return Primitive::kPrimNot; |
| 5652 | } |
| 5653 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5654 | DECLARE_INSTRUCTION(LoadClass); |
| 5655 | |
| 5656 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5657 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5658 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5659 | static constexpr size_t kFlagIsInBootImage = kFlagIsInDexCache + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5660 | // Whether this instruction must generate the initialization check. |
| 5661 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5662 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5663 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 5664 | static constexpr size_t kFieldLoadKindSize = |
| 5665 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5666 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5667 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5668 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 5669 | |
| 5670 | static bool HasTypeReference(LoadKind load_kind) { |
| 5671 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5672 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5673 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5674 | load_kind == LoadKind::kReferrersClass; |
| 5675 | } |
| 5676 | |
| 5677 | static bool HasAddress(LoadKind load_kind) { |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5678 | return load_kind == LoadKind::kBootImageAddress || |
| 5679 | load_kind == LoadKind::kJitTableAddress; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5680 | } |
| 5681 | |
| 5682 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5683 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5684 | } |
| 5685 | |
| 5686 | void SetLoadKindInternal(LoadKind load_kind); |
| 5687 | |
| 5688 | // The special input is the HCurrentMethod for kDexCacheViaMethod or kReferrersClass. |
| 5689 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5690 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
| 5691 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5692 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5693 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5694 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5695 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5696 | union { |
| 5697 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5698 | uint64_t address; // Up to 64-bit, needed for kJitTableAddress on 64-bit targets. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5699 | } load_data_; |
| 5700 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5701 | ReferenceTypeInfo loaded_class_rti_; |
| 5702 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5703 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5704 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5705 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 5706 | |
| 5707 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5708 | inline uint32_t HLoadClass::GetDexCacheElementOffset() const { |
| 5709 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5710 | return load_data_.dex_cache_element_index; |
| 5711 | } |
| 5712 | |
| 5713 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5714 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5715 | // The special input is used for PC-relative loads on some architectures, |
| 5716 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5717 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5718 | GetLoadKind() == LoadKind::kDexCachePcRelative || |
| 5719 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5720 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5721 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5722 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 5723 | special_input->AddUseAt(this, 0); |
| 5724 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5725 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5726 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5727 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5728 | // Determines how to load the String. |
| 5729 | enum class LoadKind { |
| 5730 | // Use boot image String* address that will be known at link time. |
| 5731 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5732 | kBootImageLinkTimeAddress, |
| 5733 | |
| 5734 | // Use PC-relative boot image String* address that will be known at link time. |
| 5735 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5736 | kBootImageLinkTimePcRelative, |
| 5737 | |
| 5738 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5739 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5740 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5741 | // GetIncludePatchInformation(). |
| 5742 | kBootImageAddress, |
| 5743 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5744 | // Load from an entry in the .bss section using a PC-relative load. |
| 5745 | // Used for strings outside boot image when .bss is accessible with a PC-relative load. |
| 5746 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5747 | |
| 5748 | // Load from resolved strings array accessed through the class loaded from |
| 5749 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5750 | // all other types are unavailable. |
| 5751 | kDexCacheViaMethod, |
| 5752 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5753 | // Load from the root table associated with the JIT compiled method. |
| 5754 | kJitTableAddress, |
| 5755 | |
| 5756 | kLast = kJitTableAddress, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5757 | }; |
| 5758 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5759 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5760 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5761 | const DexFile& dex_file, |
| 5762 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5763 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5764 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5765 | string_index_(string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5766 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5767 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5768 | load_data_.dex_file_ = &dex_file; |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5769 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5770 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5771 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5772 | DCHECK(HasAddress(load_kind)); |
| 5773 | load_data_.address = address; |
| 5774 | SetLoadKindInternal(load_kind); |
| 5775 | } |
| 5776 | |
| 5777 | void SetLoadKindWithStringReference(LoadKind load_kind, |
| 5778 | const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5779 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5780 | DCHECK(HasStringReference(load_kind)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5781 | load_data_.dex_file_ = &dex_file; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5782 | string_index_ = string_index; |
| 5783 | SetLoadKindInternal(load_kind); |
| 5784 | } |
| 5785 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5786 | LoadKind GetLoadKind() const { |
| 5787 | return GetPackedField<LoadKindField>(); |
| 5788 | } |
| 5789 | |
| 5790 | const DexFile& GetDexFile() const; |
| 5791 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5792 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5793 | DCHECK(HasStringReference(GetLoadKind()) || /* For slow paths. */ !IsInDexCache()); |
| 5794 | return string_index_; |
| 5795 | } |
| 5796 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5797 | uint64_t GetAddress() const { |
| 5798 | DCHECK(HasAddress(GetLoadKind())); |
| 5799 | return load_data_.address; |
| 5800 | } |
| 5801 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5802 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5803 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5804 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5805 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5806 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5807 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5808 | // Will call the runtime if we need to load the string through |
| 5809 | // the dex cache and the string is not guaranteed to be there yet. |
| 5810 | bool NeedsEnvironment() const OVERRIDE { |
| 5811 | LoadKind load_kind = GetLoadKind(); |
| 5812 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5813 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5814 | load_kind == LoadKind::kBootImageAddress || |
| 5815 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5816 | return false; |
| 5817 | } |
| 5818 | return !IsInDexCache(); |
| 5819 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5820 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5821 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5822 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5823 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5824 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5825 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5826 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5827 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5828 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5829 | return SideEffects::CanTriggerGC(); |
| 5830 | } |
| 5831 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5832 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5833 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5834 | void MarkInDexCache() { |
| 5835 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5836 | DCHECK(!NeedsEnvironment()); |
| 5837 | RemoveEnvironment(); |
Vladimir Marko | ace7a00 | 2016-04-05 11:18:49 +0100 | [diff] [blame] | 5838 | SetSideEffects(SideEffects::None()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5839 | } |
| 5840 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5841 | void AddSpecialInput(HInstruction* special_input); |
| 5842 | |
| 5843 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5844 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5845 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5846 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5847 | } |
| 5848 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5849 | Primitive::Type GetType() const OVERRIDE { |
| 5850 | return Primitive::kPrimNot; |
| 5851 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5852 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5853 | DECLARE_INSTRUCTION(LoadString); |
| 5854 | |
| 5855 | private: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5856 | static constexpr size_t kFlagIsInDexCache = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5857 | static constexpr size_t kFieldLoadKind = kFlagIsInDexCache + 1; |
| 5858 | static constexpr size_t kFieldLoadKindSize = |
| 5859 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5860 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5861 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5862 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5863 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5864 | static bool HasStringReference(LoadKind load_kind) { |
| 5865 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5866 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5867 | load_kind == LoadKind::kBssEntry || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5868 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5869 | load_kind == LoadKind::kJitTableAddress; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5870 | } |
| 5871 | |
| 5872 | static bool HasAddress(LoadKind load_kind) { |
Vladimir Marko | 54d6a20 | 2016-11-09 12:46:38 +0000 | [diff] [blame] | 5873 | return load_kind == LoadKind::kBootImageAddress; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5874 | } |
| 5875 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5876 | void SetLoadKindInternal(LoadKind load_kind); |
| 5877 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5878 | // The special input is the HCurrentMethod for kDexCacheViaMethod. |
| 5879 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5880 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5881 | HUserRecord<HInstruction*> special_input_; |
| 5882 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5883 | // String index serves also as the hash code and it's also needed for slow-paths, |
| 5884 | // so it must not be overwritten with other load data. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5885 | dex::StringIndex string_index_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5886 | |
| 5887 | union { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5888 | const DexFile* dex_file_; // For string reference. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5889 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5890 | } load_data_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5891 | |
| 5892 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5893 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5894 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5895 | |
| 5896 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5897 | inline const DexFile& HLoadString::GetDexFile() const { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5898 | DCHECK(HasStringReference(GetLoadKind())) << GetLoadKind(); |
| 5899 | return *load_data_.dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5900 | } |
| 5901 | |
| 5902 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5903 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5904 | // The special input is used for PC-relative loads on some architectures, |
| 5905 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5906 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5907 | GetLoadKind() == LoadKind::kBssEntry || |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 5908 | GetLoadKind() == LoadKind::kBootImageLinkTimeAddress || |
| 5909 | GetLoadKind() == LoadKind::kBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5910 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5911 | // so use the GetInputRecords() from the base class to set the input record. |
| 5912 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5913 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5914 | special_input->AddUseAt(this, 0); |
| 5915 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5916 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5917 | /** |
| 5918 | * Performs an initialization check on its Class object input. |
| 5919 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5920 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5921 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5922 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5923 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5924 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5925 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5926 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5927 | SetRawInputAt(0, constant); |
| 5928 | } |
| 5929 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5930 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5931 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5932 | return true; |
| 5933 | } |
| 5934 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5935 | bool NeedsEnvironment() const OVERRIDE { |
| 5936 | // May call runtime to initialize the class. |
| 5937 | return true; |
| 5938 | } |
| 5939 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5940 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5941 | |
| 5942 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5943 | |
| 5944 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5945 | |
| 5946 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5947 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5948 | }; |
| 5949 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5950 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5951 | public: |
| 5952 | HStaticFieldGet(HInstruction* cls, |
| 5953 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5954 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5955 | bool is_volatile, |
| 5956 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5957 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5958 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5959 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5960 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 5961 | : HExpression(field_type, SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5962 | field_info_(field_offset, |
| 5963 | field_type, |
| 5964 | is_volatile, |
| 5965 | field_idx, |
| 5966 | declaring_class_def_index, |
| 5967 | dex_file, |
| 5968 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5969 | SetRawInputAt(0, cls); |
| 5970 | } |
| 5971 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5972 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5973 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5974 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5975 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5976 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5977 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5978 | } |
| 5979 | |
| 5980 | size_t ComputeHashCode() const OVERRIDE { |
| 5981 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5982 | } |
| 5983 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5984 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5985 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5986 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5987 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5988 | |
| 5989 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5990 | |
| 5991 | private: |
| 5992 | const FieldInfo field_info_; |
| 5993 | |
| 5994 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5995 | }; |
| 5996 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5997 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5998 | public: |
| 5999 | HStaticFieldSet(HInstruction* cls, |
| 6000 | HInstruction* value, |
| 6001 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6002 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6003 | bool is_volatile, |
| 6004 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6005 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6006 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6007 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6008 | uint32_t dex_pc) |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 6009 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6010 | field_info_(field_offset, |
| 6011 | field_type, |
| 6012 | is_volatile, |
| 6013 | field_idx, |
| 6014 | declaring_class_def_index, |
| 6015 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6016 | dex_cache) { |
| 6017 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6018 | SetRawInputAt(0, cls); |
| 6019 | SetRawInputAt(1, value); |
| 6020 | } |
| 6021 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6022 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6023 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 6024 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6025 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6026 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6027 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6028 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6029 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6030 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6031 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6032 | |
| 6033 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6034 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6035 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6036 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6037 | "Too many packed fields."); |
| 6038 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6039 | const FieldInfo field_info_; |
| 6040 | |
| 6041 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 6042 | }; |
| 6043 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6044 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6045 | public: |
| 6046 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 6047 | Primitive::Type field_type, |
| 6048 | uint32_t field_index, |
| 6049 | uint32_t dex_pc) |
| 6050 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6051 | field_index_(field_index) { |
| 6052 | SetRawInputAt(0, obj); |
| 6053 | } |
| 6054 | |
| 6055 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6056 | bool CanThrow() const OVERRIDE { return true; } |
| 6057 | |
| 6058 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6059 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6060 | |
| 6061 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6062 | |
| 6063 | private: |
| 6064 | const uint32_t field_index_; |
| 6065 | |
| 6066 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 6067 | }; |
| 6068 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6069 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6070 | public: |
| 6071 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6072 | HInstruction* value, |
| 6073 | Primitive::Type field_type, |
| 6074 | uint32_t field_index, |
| 6075 | uint32_t dex_pc) |
| 6076 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6077 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6078 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6079 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6080 | SetRawInputAt(0, obj); |
| 6081 | SetRawInputAt(1, value); |
| 6082 | } |
| 6083 | |
| 6084 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6085 | bool CanThrow() const OVERRIDE { return true; } |
| 6086 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6087 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6088 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6089 | |
| 6090 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6091 | |
| 6092 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6093 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6094 | static constexpr size_t kFieldFieldTypeSize = |
| 6095 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6096 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6097 | kFieldFieldType + kFieldFieldTypeSize; |
| 6098 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6099 | "Too many packed fields."); |
| 6100 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6101 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6102 | const uint32_t field_index_; |
| 6103 | |
| 6104 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 6105 | }; |
| 6106 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6107 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6108 | public: |
| 6109 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 6110 | uint32_t field_index, |
| 6111 | uint32_t dex_pc) |
| 6112 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6113 | field_index_(field_index) { |
| 6114 | } |
| 6115 | |
| 6116 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6117 | bool CanThrow() const OVERRIDE { return true; } |
| 6118 | |
| 6119 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6120 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6121 | |
| 6122 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6123 | |
| 6124 | private: |
| 6125 | const uint32_t field_index_; |
| 6126 | |
| 6127 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 6128 | }; |
| 6129 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6130 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6131 | public: |
| 6132 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 6133 | Primitive::Type field_type, |
| 6134 | uint32_t field_index, |
| 6135 | uint32_t dex_pc) |
| 6136 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6137 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6138 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6139 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6140 | SetRawInputAt(0, value); |
| 6141 | } |
| 6142 | |
| 6143 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6144 | bool CanThrow() const OVERRIDE { return true; } |
| 6145 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6146 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6147 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6148 | |
| 6149 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6150 | |
| 6151 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6152 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6153 | static constexpr size_t kFieldFieldTypeSize = |
| 6154 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6155 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6156 | kFieldFieldType + kFieldFieldTypeSize; |
| 6157 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6158 | "Too many packed fields."); |
| 6159 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6160 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6161 | const uint32_t field_index_; |
| 6162 | |
| 6163 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6164 | }; |
| 6165 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6166 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6167 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6168 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6169 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6170 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6171 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6172 | bool CanBeNull() const OVERRIDE { return false; } |
| 6173 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6174 | DECLARE_INSTRUCTION(LoadException); |
| 6175 | |
| 6176 | private: |
| 6177 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6178 | }; |
| 6179 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6180 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6181 | // 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] | 6182 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6183 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6184 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6185 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6186 | |
| 6187 | DECLARE_INSTRUCTION(ClearException); |
| 6188 | |
| 6189 | private: |
| 6190 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6191 | }; |
| 6192 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6193 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6194 | public: |
| 6195 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6196 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6197 | SetRawInputAt(0, exception); |
| 6198 | } |
| 6199 | |
| 6200 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6201 | |
| 6202 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6203 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6204 | bool CanThrow() const OVERRIDE { return true; } |
| 6205 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6206 | |
| 6207 | DECLARE_INSTRUCTION(Throw); |
| 6208 | |
| 6209 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6210 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6211 | }; |
| 6212 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6213 | /** |
| 6214 | * Implementation strategies for the code generator of a HInstanceOf |
| 6215 | * or `HCheckCast`. |
| 6216 | */ |
| 6217 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6218 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6219 | kExactCheck, // Can do a single class compare. |
| 6220 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6221 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6222 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6223 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6224 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6225 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6226 | }; |
| 6227 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6228 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6229 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6230 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6231 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6232 | HInstanceOf(HInstruction* object, |
| 6233 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6234 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6235 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6236 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6237 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6238 | dex_pc) { |
| 6239 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6240 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6241 | SetRawInputAt(0, object); |
| 6242 | SetRawInputAt(1, constant); |
| 6243 | } |
| 6244 | |
| 6245 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6246 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6247 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6248 | return true; |
| 6249 | } |
| 6250 | |
| 6251 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6252 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6253 | } |
| 6254 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6255 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6256 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6257 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6258 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6259 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6260 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6261 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6262 | // Mips currently does runtime calls for any other checks. |
| 6263 | return check_kind != TypeCheckKind::kExactCheck; |
| 6264 | } |
| 6265 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6266 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6267 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6268 | } |
| 6269 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6270 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6271 | |
| 6272 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6273 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6274 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6275 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6276 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6277 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6278 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6279 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6280 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6281 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6282 | }; |
| 6283 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6284 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6285 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 6286 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6287 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6288 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6289 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6290 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6291 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6292 | SetRawInputAt(0, input); |
| 6293 | } |
| 6294 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6295 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6296 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6297 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6298 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6299 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6300 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6301 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6302 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6303 | } |
| 6304 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6305 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6306 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6307 | DECLARE_INSTRUCTION(BoundType); |
| 6308 | |
| 6309 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6310 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6311 | // is false then CanBeNull() cannot be true). |
| 6312 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6313 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6314 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6315 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6316 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6317 | // 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] | 6318 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6319 | // It is used to bound the type in cases like: |
| 6320 | // if (x instanceof ClassX) { |
| 6321 | // // uper_bound_ will be ClassX |
| 6322 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6323 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6324 | |
| 6325 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6326 | }; |
| 6327 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6328 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6329 | public: |
| 6330 | HCheckCast(HInstruction* object, |
| 6331 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6332 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6333 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6334 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6335 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6336 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6337 | SetRawInputAt(0, object); |
| 6338 | SetRawInputAt(1, constant); |
| 6339 | } |
| 6340 | |
| 6341 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6342 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6343 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6344 | return true; |
| 6345 | } |
| 6346 | |
| 6347 | bool NeedsEnvironment() const OVERRIDE { |
| 6348 | // Instruction may throw a CheckCastError. |
| 6349 | return true; |
| 6350 | } |
| 6351 | |
| 6352 | bool CanThrow() const OVERRIDE { return true; } |
| 6353 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6354 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6355 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6356 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6357 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6358 | |
| 6359 | DECLARE_INSTRUCTION(CheckCast); |
| 6360 | |
| 6361 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6362 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6363 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6364 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6365 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6366 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6367 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6368 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6369 | |
| 6370 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6371 | }; |
| 6372 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 6373 | /** |
| 6374 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6375 | * @details We define the combined barrier types that are actually required |
| 6376 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6377 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6378 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6379 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6380 | * The current recipe is as follows: |
| 6381 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6382 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6383 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6384 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6385 | * class has final fields. |
| 6386 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6387 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6388 | */ |
| 6389 | enum MemBarrierKind { |
| 6390 | kAnyStore, |
| 6391 | kLoadAny, |
| 6392 | kStoreStore, |
| 6393 | kAnyAny, |
| 6394 | kNTStoreStore, |
| 6395 | kLastBarrierKind = kNTStoreStore |
| 6396 | }; |
| 6397 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6398 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6399 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6400 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6401 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6402 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6403 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6404 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6405 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6406 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6407 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6408 | |
| 6409 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6410 | |
| 6411 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6412 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6413 | static constexpr size_t kFieldBarrierKindSize = |
| 6414 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6415 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6416 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6417 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6418 | "Too many packed fields."); |
| 6419 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6420 | |
| 6421 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6422 | }; |
| 6423 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6424 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6425 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6426 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6427 | kEnter, |
| 6428 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6429 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6430 | }; |
| 6431 | |
| 6432 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6433 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6434 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6435 | dex_pc) { |
| 6436 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6437 | SetRawInputAt(0, object); |
| 6438 | } |
| 6439 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6440 | // Instruction may go into runtime, so we need an environment. |
| 6441 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6442 | |
| 6443 | bool CanThrow() const OVERRIDE { |
| 6444 | // Verifier guarantees that monitor-exit cannot throw. |
| 6445 | // This is important because it allows the HGraphBuilder to remove |
| 6446 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6447 | return IsEnter(); |
| 6448 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6449 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6450 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6451 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6452 | |
| 6453 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6454 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6455 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6456 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6457 | static constexpr size_t kFieldOperationKindSize = |
| 6458 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6459 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6460 | kFieldOperationKind + kFieldOperationKindSize; |
| 6461 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6462 | "Too many packed fields."); |
| 6463 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6464 | |
| 6465 | private: |
| 6466 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6467 | }; |
| 6468 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6469 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6470 | public: |
| 6471 | HSelect(HInstruction* condition, |
| 6472 | HInstruction* true_value, |
| 6473 | HInstruction* false_value, |
| 6474 | uint32_t dex_pc) |
| 6475 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6476 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6477 | |
| 6478 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6479 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6480 | // that architectures which implement HSelect as a conditional move also |
| 6481 | // will not need to invert the condition. |
| 6482 | SetRawInputAt(0, false_value); |
| 6483 | SetRawInputAt(1, true_value); |
| 6484 | SetRawInputAt(2, condition); |
| 6485 | } |
| 6486 | |
| 6487 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6488 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6489 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6490 | |
| 6491 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6492 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6493 | return true; |
| 6494 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6495 | |
| 6496 | bool CanBeNull() const OVERRIDE { |
| 6497 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6498 | } |
| 6499 | |
| 6500 | DECLARE_INSTRUCTION(Select); |
| 6501 | |
| 6502 | private: |
| 6503 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6504 | }; |
| 6505 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6506 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6507 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6508 | MoveOperands(Location source, |
| 6509 | Location destination, |
| 6510 | Primitive::Type type, |
| 6511 | HInstruction* instruction) |
| 6512 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6513 | |
| 6514 | Location GetSource() const { return source_; } |
| 6515 | Location GetDestination() const { return destination_; } |
| 6516 | |
| 6517 | void SetSource(Location value) { source_ = value; } |
| 6518 | void SetDestination(Location value) { destination_ = value; } |
| 6519 | |
| 6520 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6521 | // destination (but not the source). |
| 6522 | Location MarkPending() { |
| 6523 | DCHECK(!IsPending()); |
| 6524 | Location dest = destination_; |
| 6525 | destination_ = Location::NoLocation(); |
| 6526 | return dest; |
| 6527 | } |
| 6528 | |
| 6529 | void ClearPending(Location dest) { |
| 6530 | DCHECK(IsPending()); |
| 6531 | destination_ = dest; |
| 6532 | } |
| 6533 | |
| 6534 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6535 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6536 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6537 | } |
| 6538 | |
| 6539 | // True if this blocks a move from the given location. |
| 6540 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6541 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6542 | } |
| 6543 | |
| 6544 | // A move is redundant if it's been eliminated, if its source and |
| 6545 | // destination are the same, or if its destination is unneeded. |
| 6546 | bool IsRedundant() const { |
| 6547 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6548 | } |
| 6549 | |
| 6550 | // We clear both operands to indicate move that's been eliminated. |
| 6551 | void Eliminate() { |
| 6552 | source_ = destination_ = Location::NoLocation(); |
| 6553 | } |
| 6554 | |
| 6555 | bool IsEliminated() const { |
| 6556 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6557 | return source_.IsInvalid(); |
| 6558 | } |
| 6559 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6560 | Primitive::Type GetType() const { return type_; } |
| 6561 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6562 | bool Is64BitMove() const { |
| 6563 | return Primitive::Is64BitType(type_); |
| 6564 | } |
| 6565 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6566 | HInstruction* GetInstruction() const { return instruction_; } |
| 6567 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6568 | private: |
| 6569 | Location source_; |
| 6570 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6571 | // The type this move is for. |
| 6572 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6573 | // The instruction this move is assocatied with. Null when this move is |
| 6574 | // for moving an input in the expected locations of user (including a phi user). |
| 6575 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6576 | // in the same parallel move. |
| 6577 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6578 | }; |
| 6579 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6580 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6581 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6582 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6583 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6584 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6585 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6586 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6587 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6588 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6589 | moves_.reserve(kDefaultNumberOfMoves); |
| 6590 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6591 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6592 | void AddMove(Location source, |
| 6593 | Location destination, |
| 6594 | Primitive::Type type, |
| 6595 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6596 | DCHECK(source.IsValid()); |
| 6597 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6598 | if (kIsDebugBuild) { |
| 6599 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6600 | for (const MoveOperands& move : moves_) { |
| 6601 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6602 | // Special case the situation where the move is for the spill slot |
| 6603 | // of the instruction. |
| 6604 | if ((GetPrevious() == instruction) |
| 6605 | || ((GetPrevious() == nullptr) |
| 6606 | && instruction->IsPhi() |
| 6607 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6608 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6609 | << "Doing parallel moves for the same instruction."; |
| 6610 | } else { |
| 6611 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6612 | } |
| 6613 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6614 | } |
| 6615 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6616 | for (const MoveOperands& move : moves_) { |
| 6617 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6618 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6619 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6620 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6621 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6622 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6623 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6624 | } |
| 6625 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6626 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6627 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6628 | } |
| 6629 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6630 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6631 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6632 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6633 | |
| 6634 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6635 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6636 | |
| 6637 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6638 | }; |
| 6639 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6640 | } // namespace art |
| 6641 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6642 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6643 | #include "nodes_shared.h" |
| 6644 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6645 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6646 | #include "nodes_arm.h" |
| 6647 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6648 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6649 | #include "nodes_arm64.h" |
| 6650 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6651 | #ifdef ART_ENABLE_CODEGEN_mips |
| 6652 | #include "nodes_mips.h" |
| 6653 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6654 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6655 | #include "nodes_x86.h" |
| 6656 | #endif |
| 6657 | |
| 6658 | namespace art { |
| 6659 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6660 | class HGraphVisitor : public ValueObject { |
| 6661 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6662 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6663 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6664 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6665 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6666 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6667 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6668 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6669 | void VisitInsertionOrder(); |
| 6670 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6671 | // Visit the graph following dominator tree reverse post-order. |
| 6672 | void VisitReversePostOrder(); |
| 6673 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6674 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6675 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6676 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6677 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6678 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6679 | |
| 6680 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6681 | |
| 6682 | #undef DECLARE_VISIT_INSTRUCTION |
| 6683 | |
| 6684 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6685 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6686 | |
| 6687 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6688 | }; |
| 6689 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6690 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6691 | public: |
| 6692 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6693 | virtual ~HGraphDelegateVisitor() {} |
| 6694 | |
| 6695 | // Visit functions that delegate to to super class. |
| 6696 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6697 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6698 | |
| 6699 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6700 | |
| 6701 | #undef DECLARE_VISIT_INSTRUCTION |
| 6702 | |
| 6703 | private: |
| 6704 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6705 | }; |
| 6706 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6707 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6708 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6709 | // block id. |
| 6710 | class HBlocksInLoopIterator : public ValueObject { |
| 6711 | public: |
| 6712 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6713 | : blocks_in_loop_(info.GetBlocks()), |
| 6714 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6715 | index_(0) { |
| 6716 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6717 | Advance(); |
| 6718 | } |
| 6719 | } |
| 6720 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6721 | bool Done() const { return index_ == blocks_.size(); } |
| 6722 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6723 | void Advance() { |
| 6724 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6725 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6726 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6727 | break; |
| 6728 | } |
| 6729 | } |
| 6730 | } |
| 6731 | |
| 6732 | private: |
| 6733 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6734 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6735 | size_t index_; |
| 6736 | |
| 6737 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6738 | }; |
| 6739 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6740 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6741 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6742 | // post order. |
| 6743 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6744 | public: |
| 6745 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6746 | : blocks_in_loop_(info.GetBlocks()), |
| 6747 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6748 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6749 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6750 | Advance(); |
| 6751 | } |
| 6752 | } |
| 6753 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6754 | bool Done() const { return index_ == blocks_.size(); } |
| 6755 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6756 | void Advance() { |
| 6757 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6758 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6759 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6760 | break; |
| 6761 | } |
| 6762 | } |
| 6763 | } |
| 6764 | |
| 6765 | private: |
| 6766 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6767 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6768 | size_t index_; |
| 6769 | |
| 6770 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6771 | }; |
| 6772 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6773 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6774 | if (constant->IsIntConstant()) { |
| 6775 | return constant->AsIntConstant()->GetValue(); |
| 6776 | } else if (constant->IsLongConstant()) { |
| 6777 | return constant->AsLongConstant()->GetValue(); |
| 6778 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6779 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6780 | return 0; |
| 6781 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6782 | } |
| 6783 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6784 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6785 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6786 | inline const H##type* HInstruction::As##type() const { \ |
| 6787 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6788 | } \ |
| 6789 | inline H##type* HInstruction::As##type() { \ |
| 6790 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6791 | } |
| 6792 | |
| 6793 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6794 | #undef INSTRUCTION_TYPE_CHECK |
| 6795 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6796 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6797 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6798 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6799 | size_t number_of_new_blocks, |
| 6800 | size_t after) { |
| 6801 | DCHECK_LT(after, blocks->size()); |
| 6802 | size_t old_size = blocks->size(); |
| 6803 | size_t new_size = old_size + number_of_new_blocks; |
| 6804 | blocks->resize(new_size); |
| 6805 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6806 | } |
| 6807 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6808 | } // namespace art |
| 6809 | |
| 6810 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |