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" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 29 | #include "base/quasi_atomic.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 30 | #include "base/stl_util.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 31 | #include "base/transform_array_ref.h" |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 32 | #include "art_method.h" |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 33 | #include "data_type.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 34 | #include "deoptimization_kind.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 35 | #include "dex/dex_file.h" |
| 36 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 37 | #include "dex/invoke_type.h" |
David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 38 | #include "dex/method_reference.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 39 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 40 | #include "handle.h" |
| 41 | #include "handle_scope.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 42 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 43 | #include "locations.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 44 | #include "mirror/class.h" |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 45 | #include "mirror/method_type.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 46 | #include "offsets.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 47 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 48 | |
| 49 | namespace art { |
| 50 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 51 | class ArenaStack; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 52 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 53 | class HBasicBlock; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 54 | class HConstructorFence; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 55 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 56 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 57 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 58 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 59 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 60 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 61 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 62 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 63 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 64 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 65 | class HNullConstant; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 66 | class HParameterValue; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 67 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 68 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 69 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 70 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 71 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 72 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 73 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 74 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 75 | namespace mirror { |
| 76 | class DexCache; |
| 77 | } // namespace mirror |
| 78 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 79 | static const int kDefaultNumberOfBlocks = 8; |
| 80 | static const int kDefaultNumberOfSuccessors = 2; |
| 81 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 82 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 83 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 84 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 85 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 86 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 87 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 88 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 89 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 90 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 91 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 92 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 93 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 94 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 95 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 96 | static constexpr uint32_t kNoDexPc = -1; |
| 97 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 98 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 99 | // For the purposes of the compiler, the dex files must actually be the same object |
| 100 | // if we want to safely treat them as the same. This is especially important for JIT |
| 101 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 102 | // times and provide different class resolution but no two class loaders should ever |
| 103 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 104 | // all sorts of weird failures. |
| 105 | return &lhs == &rhs; |
| 106 | } |
| 107 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 108 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 109 | // All types. |
| 110 | kCondEQ, // == |
| 111 | kCondNE, // != |
| 112 | // Signed integers and floating-point numbers. |
| 113 | kCondLT, // < |
| 114 | kCondLE, // <= |
| 115 | kCondGT, // > |
| 116 | kCondGE, // >= |
| 117 | // Unsigned integers. |
| 118 | kCondB, // < |
| 119 | kCondBE, // <= |
| 120 | kCondA, // > |
| 121 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 122 | // First and last aliases. |
| 123 | kCondFirst = kCondEQ, |
| 124 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 127 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 128 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 129 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 130 | kAnalysisFailThrowCatchLoop, |
| 131 | kAnalysisFailAmbiguousArrayOp, |
Nicolas Geoffray | 0846a8f | 2018-09-12 15:21:07 +0100 | [diff] [blame] | 132 | kAnalysisFailIrreducibleLoopAndStringInit, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 133 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 136 | template <typename T> |
| 137 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 138 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 139 | } |
| 140 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 141 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 142 | public: |
| 143 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 144 | |
| 145 | void AddInstruction(HInstruction* instruction); |
| 146 | void RemoveInstruction(HInstruction* instruction); |
| 147 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 148 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 149 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 150 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 151 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 152 | // Return true if this list contains `instruction`. |
| 153 | bool Contains(HInstruction* instruction) const; |
| 154 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 155 | // Return true if `instruction1` is found before `instruction2` in |
| 156 | // this instruction list and false otherwise. Abort if none |
| 157 | // of these instructions is found. |
| 158 | bool FoundBefore(const HInstruction* instruction1, |
| 159 | const HInstruction* instruction2) const; |
| 160 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 161 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 162 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 163 | |
| 164 | // Update the block of all instructions to be `block`. |
| 165 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 166 | |
| 167 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 168 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 169 | void Add(const HInstructionList& instruction_list); |
| 170 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 171 | // Return the number of instructions in the list. This is an expensive operation. |
| 172 | size_t CountSize() const; |
| 173 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 174 | private: |
| 175 | HInstruction* first_instruction_; |
| 176 | HInstruction* last_instruction_; |
| 177 | |
| 178 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 179 | friend class HGraph; |
| 180 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 181 | friend class HInstructionIterator; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 182 | friend class HInstructionIteratorHandleChanges; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 183 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 184 | |
| 185 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 186 | }; |
| 187 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 188 | class ReferenceTypeInfo : ValueObject { |
| 189 | public: |
| 190 | typedef Handle<mirror::Class> TypeHandle; |
| 191 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 192 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 193 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 194 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 195 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 196 | } |
| 197 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 198 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 199 | return ReferenceTypeInfo(type_handle, is_exact); |
| 200 | } |
| 201 | |
| 202 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 203 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 204 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 205 | return handle.GetReference() != nullptr; |
| 206 | } |
| 207 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 208 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 209 | return IsValidHandle(type_handle_); |
| 210 | } |
| 211 | |
| 212 | bool IsExact() const { return is_exact_; } |
| 213 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 214 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 215 | DCHECK(IsValid()); |
| 216 | return GetTypeHandle()->IsObjectClass(); |
| 217 | } |
| 218 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 219 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 220 | DCHECK(IsValid()); |
| 221 | return GetTypeHandle()->IsStringClass(); |
| 222 | } |
| 223 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 224 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 225 | DCHECK(IsValid()); |
| 226 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 227 | } |
| 228 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 229 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 230 | DCHECK(IsValid()); |
| 231 | return GetTypeHandle()->IsInterface(); |
| 232 | } |
| 233 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 234 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 235 | DCHECK(IsValid()); |
| 236 | return GetTypeHandle()->IsArrayClass(); |
| 237 | } |
| 238 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 239 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 240 | DCHECK(IsValid()); |
| 241 | return GetTypeHandle()->IsPrimitiveArray(); |
| 242 | } |
| 243 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 244 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 245 | DCHECK(IsValid()); |
| 246 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 247 | } |
| 248 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 249 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 250 | DCHECK(IsValid()); |
| 251 | if (!IsExact()) return false; |
| 252 | if (!IsArrayClass()) return false; |
| 253 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 254 | } |
| 255 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 256 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 257 | DCHECK(IsValid()); |
| 258 | if (!IsExact()) return false; |
| 259 | if (!IsArrayClass()) return false; |
| 260 | if (!rti.IsArrayClass()) return false; |
| 261 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 262 | rti.GetTypeHandle()->GetComponentType()); |
| 263 | } |
| 264 | |
| 265 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 266 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 267 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 268 | DCHECK(IsValid()); |
| 269 | DCHECK(rti.IsValid()); |
| 270 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 271 | } |
| 272 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 273 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 274 | DCHECK(IsValid()); |
| 275 | DCHECK(rti.IsValid()); |
| 276 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 277 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 278 | } |
| 279 | |
| 280 | // Returns true if the type information provide the same amount of details. |
| 281 | // Note that it does not mean that the instructions have the same actual type |
| 282 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 283 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 284 | if (!IsValid() && !rti.IsValid()) { |
| 285 | // Invalid types are equal. |
| 286 | return true; |
| 287 | } |
| 288 | if (!IsValid() || !rti.IsValid()) { |
| 289 | // One is valid, the other not. |
| 290 | return false; |
| 291 | } |
| 292 | return IsExact() == rti.IsExact() |
| 293 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 294 | } |
| 295 | |
| 296 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 297 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 298 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 299 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 300 | |
| 301 | // The class of the object. |
| 302 | TypeHandle type_handle_; |
| 303 | // Whether or not the type is exact or a superclass of the actual type. |
| 304 | // Whether or not we have any information about this type. |
| 305 | bool is_exact_; |
| 306 | }; |
| 307 | |
| 308 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 309 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 310 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 311 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 312 | public: |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 313 | HGraph(ArenaAllocator* allocator, |
| 314 | ArenaStack* arena_stack, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 315 | const DexFile& dex_file, |
| 316 | uint32_t method_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 317 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 318 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 319 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 320 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 321 | int start_instruction_id = 0) |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 322 | : allocator_(allocator), |
| 323 | arena_stack_(arena_stack), |
| 324 | blocks_(allocator->Adapter(kArenaAllocBlockList)), |
| 325 | reverse_post_order_(allocator->Adapter(kArenaAllocReversePostOrder)), |
| 326 | linear_order_(allocator->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 327 | entry_block_(nullptr), |
| 328 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 329 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 330 | number_of_vregs_(0), |
| 331 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 332 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 333 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 334 | has_try_catch_(false), |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 335 | has_simd_(false), |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 336 | has_loops_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 337 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 338 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 339 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 340 | dex_file_(dex_file), |
| 341 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 342 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 343 | in_ssa_form_(false), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 344 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 345 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 346 | cached_null_constant_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 347 | cached_int_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 348 | cached_float_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 349 | cached_long_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 350 | cached_double_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 351 | cached_current_method_(nullptr), |
Nicolas Geoffray | 53fec08 | 2017-03-27 12:56:16 +0100 | [diff] [blame] | 352 | art_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 353 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 354 | osr_(osr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 355 | cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 356 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 357 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 358 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 359 | // 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] | 360 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 361 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 362 | ArenaAllocator* GetAllocator() const { return allocator_; } |
| 363 | ArenaStack* GetArenaStack() const { return arena_stack_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 364 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 365 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 366 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 367 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 368 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 369 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 370 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 371 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 372 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 373 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 374 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 375 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 376 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 377 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 378 | void ComputeDominanceInformation(); |
| 379 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 380 | void ClearLoopInformation(); |
| 381 | void FindBackEdges(ArenaBitVector* visited); |
| 382 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 383 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 384 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 385 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 386 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 387 | // 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] | 388 | // 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] | 389 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 390 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 391 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 392 | // order and loop information. |
| 393 | void ComputeTryBlockInformation(); |
| 394 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 395 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 396 | // Returns the instruction to replace the invoke expression or null if the |
| 397 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 398 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 399 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 400 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 401 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 402 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 403 | // should be the new back edge. |
| 404 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 405 | HBasicBlock* reference, |
| 406 | bool replace_if_back_edge); |
| 407 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 408 | // Need to add a couple of blocks to test if the loop body is entered and |
| 409 | // put deoptimization instructions, etc. |
| 410 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 411 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 412 | // Adds a new loop directly after the loop with the given header and exit. |
| 413 | // Returns the new preheader. |
| 414 | HBasicBlock* TransformLoopForVectorization(HBasicBlock* header, |
| 415 | HBasicBlock* body, |
| 416 | HBasicBlock* exit); |
| 417 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 418 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 419 | // other blocks and has no instructions or phis. |
| 420 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 421 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 422 | // Splits the edge between `block` and `successor` while preserving the |
| 423 | // indices in the predecessor/successor lists. If there are multiple edges |
| 424 | // between the blocks, the lowest indices are used. |
| 425 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 426 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 427 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 428 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
Artem Serov | c73ee37 | 2017-07-31 15:08:40 +0100 | [diff] [blame] | 429 | void OrderLoopHeaderPredecessors(HBasicBlock* header); |
Artem Serov | 09faaea | 2017-12-07 14:36:01 +0000 | [diff] [blame] | 430 | |
| 431 | // Transform a loop into a format with a single preheader. |
| 432 | // |
| 433 | // Each phi in the header should be split: original one in the header should only hold |
| 434 | // inputs reachable from the back edges and a single input from the preheader. The newly created |
| 435 | // phi in the preheader should collate the inputs from the original multiple incoming blocks. |
| 436 | // |
| 437 | // Loops in the graph typically have a single preheader, so this method is used to "repair" loops |
| 438 | // that no longer have this property. |
| 439 | void TransformLoopToSinglePreheaderFormat(HBasicBlock* header); |
| 440 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 441 | void SimplifyLoop(HBasicBlock* header); |
| 442 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 443 | int32_t GetNextInstructionId() { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 444 | CHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 445 | return current_instruction_id_++; |
| 446 | } |
| 447 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 448 | int32_t GetCurrentInstructionId() const { |
| 449 | return current_instruction_id_; |
| 450 | } |
| 451 | |
| 452 | void SetCurrentInstructionId(int32_t id) { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 453 | CHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 454 | current_instruction_id_ = id; |
| 455 | } |
| 456 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 457 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 458 | return maximum_number_of_out_vregs_; |
| 459 | } |
| 460 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 461 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 462 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 463 | } |
| 464 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 465 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 466 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 467 | } |
| 468 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 469 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 470 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 471 | } |
| 472 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 473 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 474 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 475 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 476 | } |
| 477 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 478 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 479 | number_of_vregs_ = number_of_vregs; |
| 480 | } |
| 481 | |
| 482 | uint16_t GetNumberOfVRegs() const { |
| 483 | return number_of_vregs_; |
| 484 | } |
| 485 | |
| 486 | void SetNumberOfInVRegs(uint16_t value) { |
| 487 | number_of_in_vregs_ = value; |
| 488 | } |
| 489 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 490 | uint16_t GetNumberOfInVRegs() const { |
| 491 | return number_of_in_vregs_; |
| 492 | } |
| 493 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 494 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 495 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 496 | return number_of_vregs_ - number_of_in_vregs_; |
| 497 | } |
| 498 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 499 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 500 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 501 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 502 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 503 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 504 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 505 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 506 | } |
| 507 | |
| 508 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 509 | return ReverseRange(GetReversePostOrder()); |
| 510 | } |
| 511 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 512 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 513 | return linear_order_; |
| 514 | } |
| 515 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 516 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 517 | return ReverseRange(GetLinearOrder()); |
| 518 | } |
| 519 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 520 | bool HasBoundsChecks() const { |
| 521 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 522 | } |
| 523 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 524 | void SetHasBoundsChecks(bool value) { |
| 525 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 526 | } |
| 527 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 528 | bool IsDebuggable() const { return debuggable_; } |
| 529 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 530 | // 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] | 531 | // already, it is created and inserted into the graph. This method is only for |
| 532 | // integral types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 533 | HConstant* GetConstant(DataType::Type type, int64_t value, uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 534 | |
| 535 | // TODO: This is problematic for the consistency of reference type propagation |
| 536 | // because it can be created anytime after the pass and thus it will be left |
| 537 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 538 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 539 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 540 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 541 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 542 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 543 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 544 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 545 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 546 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 547 | 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] | 548 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 549 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 550 | 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] | 551 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 552 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 553 | HCurrentMethod* GetCurrentMethod(); |
| 554 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 555 | const DexFile& GetDexFile() const { |
| 556 | return dex_file_; |
| 557 | } |
| 558 | |
| 559 | uint32_t GetMethodIdx() const { |
| 560 | return method_idx_; |
| 561 | } |
| 562 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 563 | // Get the method name (without the signature), e.g. "<init>" |
| 564 | const char* GetMethodName() const; |
| 565 | |
| 566 | // Get the pretty method name (class + name + optionally signature). |
| 567 | std::string PrettyMethod(bool with_signature = true) const; |
| 568 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 569 | InvokeType GetInvokeType() const { |
| 570 | return invoke_type_; |
| 571 | } |
| 572 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 573 | InstructionSet GetInstructionSet() const { |
| 574 | return instruction_set_; |
| 575 | } |
| 576 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 577 | bool IsCompilingOsr() const { return osr_; } |
| 578 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 579 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 580 | return cha_single_implementation_list_; |
| 581 | } |
| 582 | |
| 583 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 584 | cha_single_implementation_list_.insert(method); |
| 585 | } |
| 586 | |
| 587 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 588 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 589 | } |
| 590 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 591 | bool HasTryCatch() const { return has_try_catch_; } |
| 592 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 593 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 594 | bool HasSIMD() const { return has_simd_; } |
| 595 | void SetHasSIMD(bool value) { has_simd_ = value; } |
| 596 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 597 | bool HasLoops() const { return has_loops_; } |
| 598 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 599 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 600 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 601 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 602 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 603 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 604 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 605 | |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 606 | // Returns an instruction with the opposite Boolean value from 'cond'. |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 607 | // The instruction has been inserted into the graph, either as a constant, or |
| 608 | // before cursor. |
| 609 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 610 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 611 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 612 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 613 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 614 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 615 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 616 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 617 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 618 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 619 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 620 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 621 | template <class InstructionType, typename ValueType> |
| 622 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 623 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 624 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 625 | // Try to find an existing constant of the given value. |
| 626 | InstructionType* constant = nullptr; |
| 627 | auto cached_constant = cache->find(value); |
| 628 | if (cached_constant != cache->end()) { |
| 629 | constant = cached_constant->second; |
| 630 | } |
| 631 | |
| 632 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 633 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 634 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 635 | constant = new (allocator_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 636 | cache->Overwrite(value, constant); |
| 637 | InsertConstant(constant); |
| 638 | } |
| 639 | return constant; |
| 640 | } |
| 641 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 642 | void InsertConstant(HConstant* instruction); |
| 643 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 644 | // Cache a float constant into the graph. This method should only be |
| 645 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 646 | void CacheFloatConstant(HFloatConstant* constant); |
| 647 | |
| 648 | // See CacheFloatConstant comment. |
| 649 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 650 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 651 | ArenaAllocator* const allocator_; |
| 652 | ArenaStack* const arena_stack_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 653 | |
| 654 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 655 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 656 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 657 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 658 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 659 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 660 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 661 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 662 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 663 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 664 | HBasicBlock* entry_block_; |
| 665 | HBasicBlock* exit_block_; |
| 666 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 667 | // 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] | 668 | uint16_t maximum_number_of_out_vregs_; |
| 669 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 670 | // The number of virtual registers in this method. Contains the parameters. |
| 671 | uint16_t number_of_vregs_; |
| 672 | |
| 673 | // The number of virtual registers used by parameters of this method. |
| 674 | uint16_t number_of_in_vregs_; |
| 675 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 676 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 677 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 678 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 679 | // Flag whether there are bounds checks in the graph. We can skip |
| 680 | // BCE if it's false. It's only best effort to keep it up to date in |
| 681 | // the presence of code elimination so there might be false positives. |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 682 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 683 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 684 | // Flag whether there are try/catch blocks in the graph. We will skip |
| 685 | // try/catch-related passes if it's false. It's only best effort to keep |
| 686 | // it up to date in the presence of code elimination so there might be |
| 687 | // false positives. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 688 | bool has_try_catch_; |
| 689 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 690 | // Flag whether SIMD instructions appear in the graph. If true, the |
| 691 | // code generators may have to be more careful spilling the wider |
| 692 | // contents of SIMD registers. |
| 693 | bool has_simd_; |
| 694 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 695 | // Flag whether there are any loops in the graph. We can skip loop |
| 696 | // optimization if it's false. It's only best effort to keep it up |
| 697 | // to date in the presence of code elimination so there might be false |
| 698 | // positives. |
| 699 | bool has_loops_; |
| 700 | |
| 701 | // Flag whether there are any irreducible loops in the graph. It's only |
| 702 | // best effort to keep it up to date in the presence of code elimination |
| 703 | // so there might be false positives. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 704 | bool has_irreducible_loops_; |
| 705 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 706 | // Indicates whether the graph should be compiled in a way that |
| 707 | // ensures full debuggability. If false, we can apply more |
| 708 | // aggressive optimizations that may limit the level of debugging. |
| 709 | const bool debuggable_; |
| 710 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 711 | // 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] | 712 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 713 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 714 | // The dex file from which the method is from. |
| 715 | const DexFile& dex_file_; |
| 716 | |
| 717 | // The method index in the dex file. |
| 718 | const uint32_t method_idx_; |
| 719 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 720 | // If inlined, this encodes how the callee is being invoked. |
| 721 | const InvokeType invoke_type_; |
| 722 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 723 | // Whether the graph has been transformed to SSA form. Only used |
| 724 | // in debug mode to ensure we are not using properties only valid |
| 725 | // for non-SSA form (like the number of temporaries). |
| 726 | bool in_ssa_form_; |
| 727 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 728 | // Number of CHA guards in the graph. Used to short-circuit the |
| 729 | // CHA guard optimization pass when there is no CHA guard left. |
| 730 | uint32_t number_of_cha_guards_; |
| 731 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 732 | const InstructionSet instruction_set_; |
| 733 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 734 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 735 | HNullConstant* cached_null_constant_; |
| 736 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 737 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 738 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 739 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 740 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 741 | HCurrentMethod* cached_current_method_; |
| 742 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 743 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 744 | // for example for methods whose declaring class could not be resolved |
| 745 | // (such as when the superclass could not be found). |
| 746 | ArtMethod* art_method_; |
| 747 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 748 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 749 | // collection pointer to passes which may create NullConstant. |
| 750 | ReferenceTypeInfo inexact_object_rti_; |
| 751 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 752 | // Whether we are compiling this graph for on stack replacement: this will |
| 753 | // make all loops seen as irreducible and emit special stack maps to mark |
| 754 | // compiled code entries which the interpreter can directly jump to. |
| 755 | const bool osr_; |
| 756 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 757 | // List of methods that are assumed to have single implementation. |
| 758 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 759 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 760 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 761 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 762 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 763 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 764 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 765 | }; |
| 766 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 767 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 768 | public: |
| 769 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 770 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 771 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 772 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 773 | contains_irreducible_loop_(false), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 774 | back_edges_(graph->GetAllocator()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 775 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 776 | blocks_(graph->GetAllocator(), |
| 777 | graph->GetBlocks().size(), |
| 778 | true, |
| 779 | kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 780 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 781 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 782 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 783 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 784 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 785 | |
| 786 | void Dump(std::ostream& os); |
| 787 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 788 | HBasicBlock* GetHeader() const { |
| 789 | return header_; |
| 790 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 791 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 792 | void SetHeader(HBasicBlock* block) { |
| 793 | header_ = block; |
| 794 | } |
| 795 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 796 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 797 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 798 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 799 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 800 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 801 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 804 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 805 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 806 | } |
| 807 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 808 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 809 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 810 | } |
| 811 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 812 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 813 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 816 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 817 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 818 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 819 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 820 | } |
| 821 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 822 | // Returns the lifetime position of the back edge that has the |
| 823 | // greatest lifetime position. |
| 824 | size_t GetLifetimeEnd() const; |
| 825 | |
| 826 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 827 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 828 | } |
| 829 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 830 | // Finds blocks that are part of this loop. |
| 831 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 832 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 833 | // Updates blocks population of the loop and all of its outer' ones recursively after the |
| 834 | // population of the inner loop is updated. |
| 835 | void PopulateInnerLoopUpwards(HLoopInformation* inner_loop); |
| 836 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 837 | // Returns whether this loop information contains `block`. |
| 838 | // Note that this loop information *must* be populated before entering this function. |
| 839 | bool Contains(const HBasicBlock& block) const; |
| 840 | |
| 841 | // Returns whether this loop information is an inner loop of `other`. |
| 842 | // Note that `other` *must* be populated before entering this function. |
| 843 | bool IsIn(const HLoopInformation& other) const; |
| 844 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 845 | // Returns true if instruction is not defined within this loop. |
| 846 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 847 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 848 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 849 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 850 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 851 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 852 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 853 | void ClearAllBlocks() { |
| 854 | blocks_.ClearAllBits(); |
| 855 | } |
| 856 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 857 | bool HasBackEdgeNotDominatedByHeader() const; |
| 858 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 859 | bool IsPopulated() const { |
| 860 | return blocks_.GetHighestBitSet() != -1; |
| 861 | } |
| 862 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 863 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 864 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 865 | bool HasExitEdge() const; |
| 866 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 867 | // Resets back edge and blocks-in-loop data. |
| 868 | void ResetBasicBlockData() { |
| 869 | back_edges_.clear(); |
| 870 | ClearAllBlocks(); |
| 871 | } |
| 872 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 873 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 874 | // Internal recursive implementation of `Populate`. |
| 875 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 876 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 877 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 878 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 879 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 880 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 881 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 882 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 883 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 884 | |
| 885 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 886 | }; |
| 887 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 888 | // Stores try/catch information for basic blocks. |
| 889 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 890 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 891 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 892 | public: |
| 893 | // Try block information constructor. |
| 894 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 895 | : try_entry_(&try_entry), |
| 896 | catch_dex_file_(nullptr), |
| 897 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 898 | DCHECK(try_entry_ != nullptr); |
| 899 | } |
| 900 | |
| 901 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 902 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 903 | : try_entry_(nullptr), |
| 904 | catch_dex_file_(&dex_file), |
| 905 | catch_type_index_(catch_type_index) {} |
| 906 | |
| 907 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 908 | |
| 909 | const HTryBoundary& GetTryEntry() const { |
| 910 | DCHECK(IsTryBlock()); |
| 911 | return *try_entry_; |
| 912 | } |
| 913 | |
| 914 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 915 | |
| 916 | bool IsCatchAllTypeIndex() const { |
| 917 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 918 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 919 | } |
| 920 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 921 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 922 | DCHECK(IsCatchBlock()); |
| 923 | return catch_type_index_; |
| 924 | } |
| 925 | |
| 926 | const DexFile& GetCatchDexFile() const { |
| 927 | DCHECK(IsCatchBlock()); |
| 928 | return *catch_dex_file_; |
| 929 | } |
| 930 | |
| 931 | private: |
| 932 | // One of possibly several TryBoundary instructions entering the block's try. |
| 933 | // Only set for try blocks. |
| 934 | const HTryBoundary* try_entry_; |
| 935 | |
| 936 | // Exception type information. Only set for catch blocks. |
| 937 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 938 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 939 | }; |
| 940 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 941 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 942 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 943 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 944 | // A block in a method. Contains the list of instructions represented |
| 945 | // as a double linked list. Each block knows its predecessors and |
| 946 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 947 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 948 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 949 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 950 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 951 | : graph_(graph), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 952 | predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), |
| 953 | successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 954 | loop_information_(nullptr), |
| 955 | dominator_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 956 | dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 957 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 958 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 959 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 960 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 961 | try_catch_information_(nullptr) { |
| 962 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 963 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 964 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 965 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 966 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 967 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 968 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 971 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 972 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 973 | } |
| 974 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 975 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 976 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 977 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 978 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 979 | return ContainsElement(successors_, block, start_from); |
| 980 | } |
| 981 | |
| 982 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 983 | return dominated_blocks_; |
| 984 | } |
| 985 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 986 | bool IsEntryBlock() const { |
| 987 | return graph_->GetEntryBlock() == this; |
| 988 | } |
| 989 | |
| 990 | bool IsExitBlock() const { |
| 991 | return graph_->GetExitBlock() == this; |
| 992 | } |
| 993 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 994 | bool IsSingleGoto() const; |
Mads Ager | 16e5289 | 2017-07-14 13:11:37 +0200 | [diff] [blame] | 995 | bool IsSingleReturn() const; |
Mingyao Yang | 46721ef | 2017-10-05 14:45:17 -0700 | [diff] [blame] | 996 | bool IsSingleReturnOrReturnVoidAllowingPhis() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 997 | bool IsSingleTryBoundary() const; |
| 998 | |
| 999 | // Returns true if this block emits nothing but a jump. |
| 1000 | bool IsSingleJump() const { |
| 1001 | HLoopInformation* loop_info = GetLoopInformation(); |
| 1002 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 1003 | // Back edges generate a suspend check. |
| 1004 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 1005 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1006 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1007 | void AddBackEdge(HBasicBlock* back_edge) { |
| 1008 | if (loop_information_ == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1009 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1010 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1011 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1012 | loop_information_->AddBackEdge(back_edge); |
| 1013 | } |
| 1014 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 1015 | // Registers a back edge; if the block was not a loop header before the call associates a newly |
| 1016 | // created loop info with it. |
| 1017 | // |
| 1018 | // Used in SuperblockCloner to preserve LoopInformation object instead of reseting loop |
| 1019 | // info for all blocks during back edges recalculation. |
| 1020 | void AddBackEdgeWhileUpdating(HBasicBlock* back_edge) { |
| 1021 | if (loop_information_ == nullptr || loop_information_->GetHeader() != this) { |
| 1022 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
| 1023 | } |
| 1024 | loop_information_->AddBackEdge(back_edge); |
| 1025 | } |
| 1026 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1027 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1028 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1029 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1030 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1031 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1032 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1033 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1034 | HBasicBlock* GetDominator() const { return dominator_; } |
| 1035 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1036 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 1037 | |
| 1038 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 1039 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 1040 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1041 | |
| 1042 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1043 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 1044 | } |
| 1045 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1046 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1047 | |
| 1048 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1049 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1052 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1053 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1054 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1055 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1056 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1057 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1058 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1059 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1060 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1061 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1062 | successors_.push_back(block); |
| 1063 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1066 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1067 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1068 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1069 | new_block->predecessors_.push_back(this); |
| 1070 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1073 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1074 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1075 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1076 | new_block->successors_.push_back(this); |
| 1077 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1080 | // Insert `this` between `predecessor` and `successor. This method |
| 1081 | // preserves the indicies, and will update the first edge found between |
| 1082 | // `predecessor` and `successor`. |
| 1083 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1084 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1085 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1086 | successor->predecessors_[predecessor_index] = this; |
| 1087 | predecessor->successors_[successor_index] = this; |
| 1088 | successors_.push_back(successor); |
| 1089 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1090 | } |
| 1091 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1092 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1093 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1094 | } |
| 1095 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1096 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1097 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1100 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1101 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1105 | predecessors_.push_back(block); |
| 1106 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1107 | } |
| 1108 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1109 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1110 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1111 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1112 | } |
| 1113 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1114 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1115 | DCHECK_EQ(successors_.size(), 2u); |
| 1116 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1117 | } |
| 1118 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1119 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1120 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1123 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1124 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1125 | } |
| 1126 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1127 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1128 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1129 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1133 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1134 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1138 | // predecessors is at index `idx`. |
| 1139 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1140 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1141 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1142 | } |
| 1143 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1144 | // Create a new block between this block and its predecessors. The new block |
| 1145 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1146 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1147 | // loop and try/catch information are not updated. |
| 1148 | HBasicBlock* CreateImmediateDominator(); |
| 1149 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1150 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1151 | // created, latter block. Note that this method will add the block to the |
| 1152 | // graph, create a Goto at the end of the former block and will create an edge |
| 1153 | // 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] | 1154 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1155 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1156 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1157 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1158 | // created block. Note that this method just updates raw block information, |
| 1159 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1160 | // update the graph, reverse post order, loop information, nor make sure the |
| 1161 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1162 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1163 | |
| 1164 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1165 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1166 | |
| 1167 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1168 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1169 | // that this method does not update the graph, reverse post order, loop |
| 1170 | // information, nor make sure the blocks are consistent (for example ending |
| 1171 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1172 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1173 | |
| 1174 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1175 | // of `this` are moved to `other`. |
| 1176 | // Note that this method does not update the graph, reverse post order, loop |
| 1177 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1178 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1179 | void ReplaceWith(HBasicBlock* other); |
| 1180 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1181 | // Merges the instructions of `other` at the end of `this`. |
| 1182 | void MergeInstructionsWith(HBasicBlock* other); |
| 1183 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1184 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1185 | // order, links to predecessors, successors, dominators and deletes the block |
| 1186 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1187 | // predecessor of `other` and vice versa. |
| 1188 | void MergeWith(HBasicBlock* other); |
| 1189 | |
| 1190 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1191 | // removes it from all loops it is included in and eventually from the graph. |
| 1192 | // The block must not dominate any other block. Predecessors and successors |
| 1193 | // are safely updated. |
| 1194 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1195 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1196 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1197 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1198 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1199 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1200 | // Replace phi `initial` with `replacement` within this block. |
| 1201 | void ReplaceAndRemovePhiWith(HPhi* initial, HPhi* replacement); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1202 | // Replace instruction `initial` with `replacement` within this block. |
| 1203 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1204 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1205 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1206 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1207 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1208 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1209 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1210 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1211 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1212 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1213 | |
| 1214 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1215 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1216 | } |
| 1217 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1218 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1219 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1220 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1221 | } |
| 1222 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1223 | bool IsFirstPredecessorBackEdge() const { |
| 1224 | DCHECK(IsLoopHeader()); |
| 1225 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1226 | } |
| 1227 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1228 | HLoopInformation* GetLoopInformation() const { |
| 1229 | return loop_information_; |
| 1230 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1231 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1232 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1233 | // 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] | 1234 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1235 | void SetInLoop(HLoopInformation* info) { |
| 1236 | if (IsLoopHeader()) { |
| 1237 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1238 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1239 | loop_information_ = info; |
| 1240 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1241 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1242 | // Note that a non loop header having a loop information means this loop information |
| 1243 | // has already been populated |
| 1244 | loop_information_ = info; |
| 1245 | } else { |
| 1246 | // Block is part of an inner loop. Do not update the loop information. |
| 1247 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1248 | // at this point, because this method is being called while populating `info`. |
| 1249 | } |
| 1250 | } |
| 1251 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1252 | // Raw update of the loop information. |
| 1253 | void SetLoopInformation(HLoopInformation* info) { |
| 1254 | loop_information_ = info; |
| 1255 | } |
| 1256 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1257 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1258 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1259 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1260 | |
| 1261 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1262 | try_catch_information_ = try_catch_information; |
| 1263 | } |
| 1264 | |
| 1265 | bool IsTryBlock() const { |
| 1266 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1267 | } |
| 1268 | |
| 1269 | bool IsCatchBlock() const { |
| 1270 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1271 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1272 | |
| 1273 | // Returns the try entry that this block's successors should have. They will |
| 1274 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1275 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1276 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1277 | |
Aart Bik | 75ff2c9 | 2018-04-21 01:28:11 +0000 | [diff] [blame] | 1278 | bool HasThrowingInstructions() const; |
| 1279 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1280 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1281 | bool Dominates(HBasicBlock* block) const; |
| 1282 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1283 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1284 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1285 | |
| 1286 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1287 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1288 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1289 | bool EndsWithControlFlowInstruction() const; |
Aart Bik | 4dc09e7 | 2018-05-11 14:40:31 -0700 | [diff] [blame] | 1290 | bool EndsWithReturn() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1291 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1292 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1293 | bool HasSinglePhi() const; |
| 1294 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1295 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1296 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1297 | ArenaVector<HBasicBlock*> predecessors_; |
| 1298 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1299 | HInstructionList instructions_; |
| 1300 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1301 | HLoopInformation* loop_information_; |
| 1302 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1303 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1304 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1305 | // The dex program counter of the first instruction of this block. |
| 1306 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1307 | size_t lifetime_start_; |
| 1308 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1309 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1310 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1311 | friend class HGraph; |
| 1312 | friend class HInstruction; |
| 1313 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1314 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1315 | }; |
| 1316 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1317 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1318 | // from the innermost to the outermost. |
| 1319 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1320 | public: |
| 1321 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1322 | : current_(block.GetLoopInformation()) {} |
| 1323 | |
| 1324 | bool Done() const { return current_ == nullptr; } |
| 1325 | |
| 1326 | void Advance() { |
| 1327 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1328 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | HLoopInformation* Current() const { |
| 1332 | DCHECK(!Done()); |
| 1333 | return current_; |
| 1334 | } |
| 1335 | |
| 1336 | private: |
| 1337 | HLoopInformation* current_; |
| 1338 | |
| 1339 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1340 | }; |
| 1341 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1342 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1343 | M(Above, Condition) \ |
| 1344 | M(AboveOrEqual, Condition) \ |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 1345 | M(Abs, UnaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1346 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1347 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1348 | M(ArrayGet, Instruction) \ |
| 1349 | M(ArrayLength, Instruction) \ |
| 1350 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1351 | M(Below, Condition) \ |
| 1352 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1353 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1354 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1355 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1356 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1357 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1358 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1359 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1360 | M(Compare, BinaryOperation) \ |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1361 | M(ConstructorFence, Instruction) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1362 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1363 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1364 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1365 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1366 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1367 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1368 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1369 | M(Exit, Instruction) \ |
| 1370 | M(FloatConstant, Constant) \ |
| 1371 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1372 | M(GreaterThan, Condition) \ |
| 1373 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1374 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1375 | M(InstanceFieldGet, Instruction) \ |
| 1376 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1377 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1378 | M(IntConstant, Constant) \ |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 1379 | M(IntermediateAddress, Instruction) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1380 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1381 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1382 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1383 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1384 | M(InvokePolymorphic, Invoke) \ |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1385 | M(InvokeCustom, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1386 | M(LessThan, Condition) \ |
| 1387 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1388 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1389 | M(LoadException, Instruction) \ |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 1390 | M(LoadMethodHandle, Instruction) \ |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 1391 | M(LoadMethodType, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1392 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1393 | M(LongConstant, Constant) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1394 | M(Max, Instruction) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1395 | M(MemoryBarrier, Instruction) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1396 | M(Min, BinaryOperation) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1397 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1398 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1399 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1400 | M(Neg, UnaryOperation) \ |
| 1401 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1402 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1403 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1404 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1405 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1406 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1407 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1408 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1409 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1410 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1411 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1412 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1413 | M(Return, Instruction) \ |
| 1414 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1415 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1416 | M(Shl, BinaryOperation) \ |
| 1417 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1418 | M(StaticFieldGet, Instruction) \ |
| 1419 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1420 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1421 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1422 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1423 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1424 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1425 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1426 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1427 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1428 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1429 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1430 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1431 | M(Xor, BinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1432 | M(VecReplicateScalar, VecUnaryOperation) \ |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1433 | M(VecExtractScalar, VecUnaryOperation) \ |
| 1434 | M(VecReduce, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1435 | M(VecCnv, VecUnaryOperation) \ |
| 1436 | M(VecNeg, VecUnaryOperation) \ |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1437 | M(VecAbs, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1438 | M(VecNot, VecUnaryOperation) \ |
| 1439 | M(VecAdd, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1440 | M(VecHalvingAdd, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1441 | M(VecSub, VecBinaryOperation) \ |
| 1442 | M(VecMul, VecBinaryOperation) \ |
| 1443 | M(VecDiv, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1444 | M(VecMin, VecBinaryOperation) \ |
| 1445 | M(VecMax, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1446 | M(VecAnd, VecBinaryOperation) \ |
| 1447 | M(VecAndNot, VecBinaryOperation) \ |
| 1448 | M(VecOr, VecBinaryOperation) \ |
| 1449 | M(VecXor, VecBinaryOperation) \ |
Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1450 | M(VecSaturationAdd, VecBinaryOperation) \ |
| 1451 | M(VecSaturationSub, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1452 | M(VecShl, VecBinaryOperation) \ |
| 1453 | M(VecShr, VecBinaryOperation) \ |
| 1454 | M(VecUShr, VecBinaryOperation) \ |
Aart Bik | 8de5916 | 2017-04-21 09:42:01 -0700 | [diff] [blame] | 1455 | M(VecSetScalars, VecOperation) \ |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1456 | M(VecMultiplyAccumulate, VecOperation) \ |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1457 | M(VecSADAccumulate, VecOperation) \ |
Artem Serov | aaac0e3 | 2018-08-07 00:52:22 +0100 | [diff] [blame] | 1458 | M(VecDotProd, VecOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1459 | M(VecLoad, VecMemoryOperation) \ |
| 1460 | M(VecStore, VecMemoryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1461 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1462 | /* |
| 1463 | * Instructions, shared across several (not all) architectures. |
| 1464 | */ |
| 1465 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1466 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1467 | #else |
| 1468 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1469 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1470 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1471 | M(MultiplyAccumulate, Instruction) \ |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 1472 | M(IntermediateAddressIndex, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1473 | #endif |
| 1474 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1475 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1476 | |
| 1477 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1478 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1479 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1480 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1481 | #else |
| 1482 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1483 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 1484 | M(MipsPackedSwitch, Instruction) \ |
| 1485 | M(IntermediateArrayAddressIndex, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1486 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1487 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1488 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1489 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1490 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1491 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1492 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1493 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1494 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1495 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1496 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1497 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1498 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1499 | |
| 1500 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1501 | |
| 1502 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1503 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1504 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1505 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1506 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1507 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1508 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1509 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1510 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1511 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1512 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1513 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1514 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1515 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1516 | M(BinaryOperation, Instruction) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1517 | M(Invoke, Instruction) \ |
| 1518 | M(VecOperation, Instruction) \ |
| 1519 | M(VecUnaryOperation, VecOperation) \ |
| 1520 | M(VecBinaryOperation, VecOperation) \ |
| 1521 | M(VecMemoryOperation, VecOperation) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1522 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1523 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1524 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1525 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1526 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1527 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1528 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1529 | #undef FORWARD_DECLARATION |
| 1530 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1531 | #define DECLARE_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1532 | private: \ |
| 1533 | H##type& operator=(const H##type&) = delete; \ |
| 1534 | public: \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1535 | const char* DebugName() const override { return #type; } \ |
| 1536 | HInstruction* Clone(ArenaAllocator* arena) const override { \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1537 | DCHECK(IsClonable()); \ |
| 1538 | return new (arena) H##type(*this->As##type()); \ |
| 1539 | } \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1540 | void Accept(HGraphVisitor* visitor) override |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1541 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1542 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1543 | private: \ |
| 1544 | H##type& operator=(const H##type&) = delete; \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 1545 | public: |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1546 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1547 | #define DEFAULT_COPY_CONSTRUCTOR(type) \ |
| 1548 | explicit H##type(const H##type& other) = default; |
| 1549 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1550 | template <typename T> |
Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 1551 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode>, |
| 1552 | public IntrusiveForwardListNode<HUseListNode<T>> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1553 | public: |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1554 | // Get the instruction which has this use as one of the inputs. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1555 | T GetUser() const { return user_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1556 | // Get the position of the input record that this use corresponds to. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1557 | size_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1558 | // Set the position of the input record that this use corresponds to. |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1559 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1560 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1561 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1562 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1563 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1564 | |
| 1565 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1566 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1567 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1568 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1569 | |
| 1570 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1571 | }; |
| 1572 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1573 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1574 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1575 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1576 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1577 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1578 | // by the used instructions. |
| 1579 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1580 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1581 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1582 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1583 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1584 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1585 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1586 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1587 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1588 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1589 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1593 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1594 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1595 | |
| 1596 | private: |
| 1597 | // Instruction used by the user. |
| 1598 | HInstruction* instruction_; |
| 1599 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1600 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1601 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1602 | }; |
| 1603 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1604 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1605 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1606 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1607 | struct HInputExtractor { |
| 1608 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1609 | return record.GetInstruction(); |
| 1610 | } |
| 1611 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1612 | return record.GetInstruction(); |
| 1613 | } |
| 1614 | }; |
| 1615 | |
| 1616 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1617 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1618 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1619 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1620 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1621 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1622 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1623 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1624 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1625 | * modify the value of a reference field read [although it may modify the |
| 1626 | * reference fetch prior to reading the field, which is represented by its own |
| 1627 | * write/read dependence]). The analysis makes conservative points-to |
| 1628 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1629 | * the same, and any reference read depends on any reference read without |
| 1630 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1631 | * |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1632 | * kDependsOnGCBit is defined in the following way: instructions with kDependsOnGCBit must not be |
| 1633 | * alive across the point where garbage collection might happen. |
| 1634 | * |
| 1635 | * Note: Instructions with kCanTriggerGCBit do not depend on each other. |
| 1636 | * |
| 1637 | * kCanTriggerGCBit must be used for instructions for which GC might happen on the path across |
| 1638 | * those instructions from the compiler perspective (between this instruction and the next one |
| 1639 | * in the IR). |
| 1640 | * |
| 1641 | * Note: Instructions which can cause GC only on a fatal slow path do not need |
| 1642 | * kCanTriggerGCBit as the execution never returns to the instruction next to the exceptional |
| 1643 | * one. However the execution may return to compiled code if there is a catch block in the |
| 1644 | * current method; for this purpose the TryBoundary exit instruction has kCanTriggerGCBit |
| 1645 | * set. |
| 1646 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1647 | * The internal representation uses 38-bit and is described in the table below. |
| 1648 | * The first line indicates the side effect, and for field/array accesses the |
| 1649 | * second line indicates the type of the access (in the order of the |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1650 | * DataType::Type enum). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1651 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1652 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1653 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1654 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1655 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1656 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1657 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1658 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1659 | * |
| 1660 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1661 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1662 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1663 | class SideEffects : public ValueObject { |
| 1664 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1665 | SideEffects() : flags_(0) {} |
| 1666 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1667 | static SideEffects None() { |
| 1668 | return SideEffects(0); |
| 1669 | } |
| 1670 | |
| 1671 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1672 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1673 | } |
| 1674 | |
| 1675 | static SideEffects AllChanges() { |
| 1676 | return SideEffects(kAllChangeBits); |
| 1677 | } |
| 1678 | |
| 1679 | static SideEffects AllDependencies() { |
| 1680 | return SideEffects(kAllDependOnBits); |
| 1681 | } |
| 1682 | |
| 1683 | static SideEffects AllExceptGCDependency() { |
| 1684 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1685 | } |
| 1686 | |
| 1687 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1688 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1689 | } |
| 1690 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1691 | static SideEffects AllWrites() { |
| 1692 | return SideEffects(kAllWrites); |
| 1693 | } |
| 1694 | |
| 1695 | static SideEffects AllReads() { |
| 1696 | return SideEffects(kAllReads); |
| 1697 | } |
| 1698 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1699 | static SideEffects FieldWriteOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1700 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1701 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1702 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1703 | } |
| 1704 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1705 | static SideEffects ArrayWriteOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1706 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1707 | } |
| 1708 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1709 | static SideEffects FieldReadOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1710 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1711 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1712 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1715 | static SideEffects ArrayReadOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1716 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1719 | // Returns whether GC might happen across this instruction from the compiler perspective so |
| 1720 | // the next instruction in the IR would see that. |
| 1721 | // |
| 1722 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1723 | static SideEffects CanTriggerGC() { |
| 1724 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1725 | } |
| 1726 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1727 | // Returns whether the instruction must not be alive across a GC point. |
| 1728 | // |
| 1729 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1730 | static SideEffects DependsOnGC() { |
| 1731 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1732 | } |
| 1733 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1734 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1735 | SideEffects Union(SideEffects other) const { |
| 1736 | return SideEffects(flags_ | other.flags_); |
| 1737 | } |
| 1738 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1739 | SideEffects Exclusion(SideEffects other) const { |
| 1740 | return SideEffects(flags_ & ~other.flags_); |
| 1741 | } |
| 1742 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1743 | void Add(SideEffects other) { |
| 1744 | flags_ |= other.flags_; |
| 1745 | } |
| 1746 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1747 | bool Includes(SideEffects other) const { |
| 1748 | return (other.flags_ & flags_) == other.flags_; |
| 1749 | } |
| 1750 | |
| 1751 | bool HasSideEffects() const { |
| 1752 | return (flags_ & kAllChangeBits); |
| 1753 | } |
| 1754 | |
| 1755 | bool HasDependencies() const { |
| 1756 | return (flags_ & kAllDependOnBits); |
| 1757 | } |
| 1758 | |
| 1759 | // Returns true if there are no side effects or dependencies. |
| 1760 | bool DoesNothing() const { |
| 1761 | return flags_ == 0; |
| 1762 | } |
| 1763 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1764 | // Returns true if something is written. |
| 1765 | bool DoesAnyWrite() const { |
| 1766 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1767 | } |
| 1768 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1769 | // Returns true if something is read. |
| 1770 | bool DoesAnyRead() const { |
| 1771 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1772 | } |
| 1773 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1774 | // Returns true if potentially everything is written and read |
| 1775 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1776 | bool DoesAllReadWrite() const { |
| 1777 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1778 | } |
| 1779 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1780 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1781 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1784 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1785 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1786 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1787 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1791 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1792 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1793 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1794 | for (int s = kLastBit; s >= 0; s--) { |
| 1795 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1796 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1797 | // This is a bit for the GC side effect. |
| 1798 | if (current_bit_is_set) { |
| 1799 | flags += "GC"; |
| 1800 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1801 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1802 | } else { |
| 1803 | // This is a bit for the array/field analysis. |
| 1804 | // The underscore character stands for the 'can trigger GC' bit. |
| 1805 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1806 | if (current_bit_is_set) { |
| 1807 | flags += kDebug[s]; |
| 1808 | } |
| 1809 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1810 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1811 | flags += "|"; |
| 1812 | } |
| 1813 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1814 | } |
| 1815 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1816 | } |
| 1817 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1818 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1819 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1820 | private: |
| 1821 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1822 | |
| 1823 | static constexpr int kFieldWriteOffset = 0; |
| 1824 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1825 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1826 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1827 | |
| 1828 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1829 | |
| 1830 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1831 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1832 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1833 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1834 | |
| 1835 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1836 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1837 | |
| 1838 | // Aliases. |
| 1839 | |
| 1840 | static_assert(kChangeBits == kDependOnBits, |
| 1841 | "the 'change' bits should match the 'depend on' bits."); |
| 1842 | |
| 1843 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1844 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1845 | static constexpr uint64_t kAllWrites = |
| 1846 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1847 | static constexpr uint64_t kAllReads = |
| 1848 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1849 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1850 | // Translates type to bit flag. The type must correspond to a Java type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1851 | static uint64_t TypeFlag(DataType::Type type, int offset) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1852 | int shift; |
| 1853 | switch (type) { |
| 1854 | case DataType::Type::kReference: shift = 0; break; |
| 1855 | case DataType::Type::kBool: shift = 1; break; |
| 1856 | case DataType::Type::kInt8: shift = 2; break; |
| 1857 | case DataType::Type::kUint16: shift = 3; break; |
| 1858 | case DataType::Type::kInt16: shift = 4; break; |
| 1859 | case DataType::Type::kInt32: shift = 5; break; |
| 1860 | case DataType::Type::kInt64: shift = 6; break; |
| 1861 | case DataType::Type::kFloat32: shift = 7; break; |
| 1862 | case DataType::Type::kFloat64: shift = 8; break; |
| 1863 | default: |
| 1864 | LOG(FATAL) << "Unexpected data type " << type; |
| 1865 | UNREACHABLE(); |
| 1866 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1867 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1868 | DCHECK_LT(shift, kArrayWriteOffset); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1869 | return UINT64_C(1) << (shift + offset); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | // Private constructor on direct flags value. |
| 1873 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1874 | |
| 1875 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1876 | }; |
| 1877 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1878 | // 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] | 1879 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1880 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1881 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1882 | size_t number_of_vregs, |
| 1883 | ArtMethod* method, |
| 1884 | uint32_t dex_pc, |
| 1885 | HInstruction* holder) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1886 | : vregs_(number_of_vregs, allocator->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1887 | locations_(allocator->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1888 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1889 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1890 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1891 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1892 | } |
| 1893 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1894 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
| 1895 | const HEnvironment& to_copy, |
| 1896 | HInstruction* holder) |
| 1897 | : HEnvironment(allocator, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1898 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1899 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1900 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1901 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1902 | |
Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 1903 | void AllocateLocations() { |
| 1904 | DCHECK(locations_.empty()); |
| 1905 | locations_.resize(vregs_.size()); |
| 1906 | } |
| 1907 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1908 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1909 | if (parent_ != nullptr) { |
| 1910 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1911 | } else { |
| 1912 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1913 | parent_->CopyFrom(parent); |
| 1914 | if (parent->GetParent() != nullptr) { |
| 1915 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1916 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1917 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 1920 | void CopyFrom(ArrayRef<HInstruction* const> locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1921 | void CopyFrom(HEnvironment* environment); |
| 1922 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1923 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1924 | // input to the loop phi instead. This is for inserting instructions that |
| 1925 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1926 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1927 | |
| 1928 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1929 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1933 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1936 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1937 | |
Artem Serov | ca210e3 | 2017-12-15 13:43:20 +0000 | [diff] [blame] | 1938 | // Replaces the input at the position 'index' with the replacement; the replacement and old |
| 1939 | // input instructions' env_uses_ lists are adjusted. The function works similar to |
| 1940 | // HInstruction::ReplaceInput. |
| 1941 | void ReplaceInput(HInstruction* replacement, size_t index); |
| 1942 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1943 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1944 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1945 | HEnvironment* GetParent() const { return parent_; } |
| 1946 | |
| 1947 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1948 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1952 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | uint32_t GetDexPc() const { |
| 1956 | return dex_pc_; |
| 1957 | } |
| 1958 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1959 | ArtMethod* GetMethod() const { |
| 1960 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1961 | } |
| 1962 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1963 | HInstruction* GetHolder() const { |
| 1964 | return holder_; |
| 1965 | } |
| 1966 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1967 | |
| 1968 | bool IsFromInlinedInvoke() const { |
| 1969 | return GetParent() != nullptr; |
| 1970 | } |
| 1971 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1972 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1973 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1974 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1975 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1976 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1977 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1978 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1979 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1980 | HInstruction* const holder_; |
| 1981 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1982 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1983 | |
| 1984 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1985 | }; |
| 1986 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1987 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1988 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 1989 | #define DECLARE_KIND(type, super) k##type, |
| 1990 | enum InstructionKind { |
Vladimir Marko | e394622 | 2018-05-04 14:18:47 +0100 | [diff] [blame] | 1991 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_KIND) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 1992 | kLastInstructionKind |
| 1993 | }; |
| 1994 | #undef DECLARE_KIND |
| 1995 | |
| 1996 | HInstruction(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 1997 | : HInstruction(kind, DataType::Type::kVoid, side_effects, dex_pc) {} |
| 1998 | |
| 1999 | HInstruction(InstructionKind kind, DataType::Type type, SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2000 | : previous_(nullptr), |
| 2001 | next_(nullptr), |
| 2002 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2003 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2004 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2005 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2006 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2007 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2008 | locations_(nullptr), |
| 2009 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2010 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 2011 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2012 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2013 | SetPackedField<InstructionKindField>(kind); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2014 | SetPackedField<TypeField>(type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2015 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 2016 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2017 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2018 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2019 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2020 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2021 | HInstruction* GetNext() const { return next_; } |
| 2022 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2023 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2024 | HInstruction* GetNextDisregardingMoves() const; |
| 2025 | HInstruction* GetPreviousDisregardingMoves() const; |
| 2026 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2027 | HBasicBlock* GetBlock() const { return block_; } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2028 | ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2029 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 2030 | bool IsInBlock() const { return block_ != nullptr; } |
| 2031 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 2032 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 2033 | bool IsIrreducibleLoopHeaderPhi() const { |
| 2034 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 2035 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2036 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2037 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 2038 | |
| 2039 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 2040 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 2041 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 2042 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 2043 | } |
| 2044 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2045 | HInputsRef GetInputs() { |
| 2046 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2047 | } |
| 2048 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2049 | HConstInputsRef GetInputs() const { |
| 2050 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2054 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2055 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 2056 | bool HasInput(HInstruction* input) const { |
| 2057 | for (const HInstruction* i : GetInputs()) { |
| 2058 | if (i == input) { |
| 2059 | return true; |
| 2060 | } |
| 2061 | } |
| 2062 | return false; |
| 2063 | } |
| 2064 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2065 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 2066 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 2067 | } |
| 2068 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2069 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 2070 | virtual const char* DebugName() const = 0; |
| 2071 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2072 | DataType::Type GetType() const { |
| 2073 | return TypeField::Decode(GetPackedFields()); |
| 2074 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2075 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2076 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2077 | |
| 2078 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2079 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2080 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2081 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2082 | // Can the instruction throw? |
| 2083 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 2084 | // could throw OOME, but it is still OK to remove them if they are unused. |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 2085 | virtual bool CanThrow() const { return false; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2086 | |
| 2087 | // Does the instruction always throw an exception unconditionally? |
| 2088 | virtual bool AlwaysThrows() const { return false; } |
| 2089 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2090 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2091 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2092 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2093 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2094 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2095 | // Does not apply for all instructions, but having this at top level greatly |
| 2096 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 2097 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2098 | virtual bool CanBeNull() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2099 | DCHECK_EQ(GetType(), DataType::Type::kReference) << "CanBeNull only applies to reference types"; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2100 | return true; |
| 2101 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2102 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2103 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 2104 | return false; |
| 2105 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2106 | |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 2107 | // If this instruction will do an implicit null check, return the `HNullCheck` associated |
| 2108 | // with it. Otherwise return null. |
| 2109 | HNullCheck* GetImplicitNullCheck() const { |
| 2110 | // Find the first previous instruction which is not a move. |
| 2111 | HInstruction* first_prev_not_move = GetPreviousDisregardingMoves(); |
| 2112 | if (first_prev_not_move != nullptr && |
| 2113 | first_prev_not_move->IsNullCheck() && |
| 2114 | first_prev_not_move->IsEmittedAtUseSite()) { |
| 2115 | return first_prev_not_move->AsNullCheck(); |
| 2116 | } |
| 2117 | return nullptr; |
| 2118 | } |
| 2119 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2120 | virtual bool IsActualObject() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2121 | return GetType() == DataType::Type::kReference; |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 2124 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2125 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2126 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2127 | DCHECK_EQ(GetType(), DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2128 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 2129 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2130 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2131 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2132 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2133 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2134 | // Note: fixup_end remains valid across push_front(). |
| 2135 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 2136 | HUseListNode<HInstruction*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2137 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HInstruction*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2138 | uses_.push_front(*new_node); |
| 2139 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2142 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2143 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2144 | // Note: env_fixup_end remains valid across push_front(). |
| 2145 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2146 | HUseListNode<HEnvironment*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2147 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HEnvironment*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2148 | env_uses_.push_front(*new_node); |
| 2149 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2150 | } |
| 2151 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2152 | void RemoveAsUserOfInput(size_t input) { |
| 2153 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2154 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2155 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2156 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2157 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2158 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2159 | void RemoveAsUserOfAllInputs() { |
| 2160 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2161 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2162 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2163 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2164 | } |
| 2165 | } |
| 2166 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2167 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2168 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2169 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2170 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2171 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2172 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2173 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2174 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2175 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2176 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2177 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2178 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2179 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2180 | !CanThrow() && |
| 2181 | !IsSuspendCheck() && |
| 2182 | !IsControlFlow() && |
| 2183 | !IsNativeDebugInfo() && |
| 2184 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2185 | // If we added an explicit barrier then we should keep it. |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2186 | !IsMemoryBarrier() && |
| 2187 | !IsConstructorFence(); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2190 | bool IsDeadAndRemovable() const { |
| 2191 | return IsRemovable() && !HasUses(); |
| 2192 | } |
| 2193 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2194 | // Does this instruction strictly dominate `other_instruction`? |
| 2195 | // Returns false if this instruction and `other_instruction` are the same. |
| 2196 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2197 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2198 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2199 | int GetId() const { return id_; } |
| 2200 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2201 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2202 | int GetSsaIndex() const { return ssa_index_; } |
| 2203 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2204 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2205 | |
| 2206 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2207 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2208 | // Set the `environment_` field. Raw because this method does not |
| 2209 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2210 | void SetRawEnvironment(HEnvironment* environment) { |
| 2211 | DCHECK(environment_ == nullptr); |
| 2212 | DCHECK_EQ(environment->GetHolder(), this); |
| 2213 | environment_ = environment; |
| 2214 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2215 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2216 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2217 | DCHECK(environment_ != nullptr); |
| 2218 | DCHECK_EQ(environment->GetHolder(), this); |
| 2219 | DCHECK(environment->GetParent() == nullptr); |
| 2220 | environment->parent_ = environment_; |
| 2221 | environment_ = environment; |
| 2222 | } |
| 2223 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2224 | void RemoveEnvironment(); |
| 2225 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2226 | // Set the environment of this instruction, copying it from `environment`. While |
| 2227 | // copying, the uses lists are being updated. |
| 2228 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2229 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2230 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2231 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2232 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2233 | if (environment->GetParent() != nullptr) { |
| 2234 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2235 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2236 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2237 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2238 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2239 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2240 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2241 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2242 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2243 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2244 | if (environment->GetParent() != nullptr) { |
| 2245 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2246 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2249 | // Returns the number of entries in the environment. Typically, that is the |
| 2250 | // number of dex registers in a method. It could be more in case of inlining. |
| 2251 | size_t EnvironmentSize() const; |
| 2252 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2253 | LocationSummary* GetLocations() const { return locations_; } |
| 2254 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2255 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2256 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2257 | void ReplaceUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 8a62a4c | 2018-07-03 09:39:07 +0100 | [diff] [blame] | 2258 | void ReplaceEnvUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2259 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2260 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2261 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2262 | // uses of this instruction by `other` are *not* updated. |
| 2263 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2264 | ReplaceWith(other); |
| 2265 | other->ReplaceInput(this, use_index); |
| 2266 | } |
| 2267 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2268 | // Move `this` instruction before `cursor` |
| 2269 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2270 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2271 | // Move `this` before its first user and out of any loops. If there is no |
| 2272 | // out-of-loop user that dominates all other users, move the instruction |
| 2273 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2274 | // |
| 2275 | // This can be used only on non-throwing instructions with no side effects that |
| 2276 | // have at least one use but no environment uses. |
| 2277 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2278 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2279 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2280 | bool Is##type() const; |
| 2281 | |
| 2282 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2283 | #undef INSTRUCTION_TYPE_CHECK |
| 2284 | |
| 2285 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2286 | const H##type* As##type() const; \ |
| 2287 | H##type* As##type(); |
| 2288 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2289 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 2290 | #undef INSTRUCTION_TYPE_CAST |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2291 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2292 | // Return a clone of the instruction if it is clonable (shallow copy by default, custom copy |
| 2293 | // if a custom copy-constructor is provided for a particular type). If IsClonable() is false for |
| 2294 | // the instruction then the behaviour of this function is undefined. |
| 2295 | // |
| 2296 | // Note: It is semantically valid to create a clone of the instruction only until |
| 2297 | // prepare_for_register_allocator phase as lifetime, intervals and codegen info are not |
| 2298 | // copied. |
| 2299 | // |
| 2300 | // Note: HEnvironment and some other fields are not copied and are set to default values, see |
| 2301 | // 'explicit HInstruction(const HInstruction& other)' for details. |
| 2302 | virtual HInstruction* Clone(ArenaAllocator* arena ATTRIBUTE_UNUSED) const { |
| 2303 | LOG(FATAL) << "Cloning is not implemented for the instruction " << |
| 2304 | DebugName() << " " << GetId(); |
| 2305 | UNREACHABLE(); |
| 2306 | } |
| 2307 | |
| 2308 | // Return whether instruction can be cloned (copied). |
| 2309 | virtual bool IsClonable() const { return false; } |
| 2310 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2311 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2312 | // TODO: this method is used by LICM and GVN with possibly different |
| 2313 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2314 | virtual bool CanBeMoved() const { return false; } |
| 2315 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2316 | // Returns whether any data encoded in the two instructions is equal. |
| 2317 | // This method does not look at the inputs. Both instructions must be |
| 2318 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2319 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2320 | return false; |
| 2321 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2322 | |
| 2323 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2324 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2325 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2326 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2327 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2328 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2329 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2330 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2331 | // apply the strong requirement for virtual functions, preventing optimizations. |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2332 | InstructionKind GetKind() const { return GetPackedField<InstructionKindField>(); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2333 | |
| 2334 | virtual size_t ComputeHashCode() const { |
| 2335 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2336 | for (const HInstruction* input : GetInputs()) { |
| 2337 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2338 | } |
| 2339 | return result; |
| 2340 | } |
| 2341 | |
| 2342 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2343 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2344 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2345 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2346 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2347 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2348 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2349 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2350 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2351 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2352 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2353 | |
| 2354 | // Returns whether the code generation of the instruction will require to have access |
| 2355 | // to the current method. Such instructions are: |
| 2356 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2357 | // 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] | 2358 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2359 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2360 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2361 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2364 | // Returns whether the code generation of the instruction will require to have access |
| 2365 | // to the dex cache of the current method's declaring class via the current method. |
| 2366 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2367 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2368 | // Does this instruction have any use in an environment before |
| 2369 | // control flow hits 'other'? |
| 2370 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2371 | |
| 2372 | // Remove all references to environment uses of this instruction. |
| 2373 | // The caller must ensure that this is safe to do. |
| 2374 | void RemoveEnvironmentUsers(); |
| 2375 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2376 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2377 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2378 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2379 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2380 | // If set, the machine code for this instruction is assumed to be generated by |
| 2381 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2382 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2383 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2384 | static constexpr size_t kFieldInstructionKind = kFlagReferenceTypeIsExact + 1; |
| 2385 | static constexpr size_t kFieldInstructionKindSize = |
| 2386 | MinimumBitsToStore(static_cast<size_t>(InstructionKind::kLastInstructionKind - 1)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2387 | static constexpr size_t kFieldType = |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2388 | kFieldInstructionKind + kFieldInstructionKindSize; |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2389 | static constexpr size_t kFieldTypeSize = |
| 2390 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
| 2391 | static constexpr size_t kNumberOfGenericPackedBits = kFieldType + kFieldTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2392 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2393 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2394 | static_assert(kNumberOfGenericPackedBits <= kMaxNumberOfPackedBits, |
| 2395 | "Too many generic packed fields"); |
| 2396 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2397 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
| 2398 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2399 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2400 | return GetInputRecords()[i]; |
| 2401 | } |
| 2402 | |
| 2403 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2404 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2405 | input_records[index] = input; |
| 2406 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2407 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2408 | uint32_t GetPackedFields() const { |
| 2409 | return packed_fields_; |
| 2410 | } |
| 2411 | |
| 2412 | template <size_t flag> |
| 2413 | bool GetPackedFlag() const { |
| 2414 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2415 | } |
| 2416 | |
| 2417 | template <size_t flag> |
| 2418 | void SetPackedFlag(bool value = true) { |
| 2419 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2420 | } |
| 2421 | |
| 2422 | template <typename BitFieldType> |
| 2423 | typename BitFieldType::value_type GetPackedField() const { |
| 2424 | return BitFieldType::Decode(packed_fields_); |
| 2425 | } |
| 2426 | |
| 2427 | template <typename BitFieldType> |
| 2428 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2429 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2430 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2431 | } |
| 2432 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2433 | // Copy construction for the instruction (used for Clone function). |
| 2434 | // |
| 2435 | // Fields (e.g. lifetime, intervals and codegen info) associated with phases starting from |
| 2436 | // prepare_for_register_allocator are not copied (set to default values). |
| 2437 | // |
| 2438 | // Copy constructors must be provided for every HInstruction type; default copy constructor is |
| 2439 | // fine for most of them. However for some of the instructions a custom copy constructor must be |
| 2440 | // specified (when instruction has non-trivially copyable fields and must have a special behaviour |
| 2441 | // for copying them). |
| 2442 | explicit HInstruction(const HInstruction& other) |
| 2443 | : previous_(nullptr), |
| 2444 | next_(nullptr), |
| 2445 | block_(nullptr), |
| 2446 | dex_pc_(other.dex_pc_), |
| 2447 | id_(-1), |
| 2448 | ssa_index_(-1), |
| 2449 | packed_fields_(other.packed_fields_), |
| 2450 | environment_(nullptr), |
| 2451 | locations_(nullptr), |
| 2452 | live_interval_(nullptr), |
| 2453 | lifetime_position_(kNoLifetime), |
| 2454 | side_effects_(other.side_effects_), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2455 | reference_type_handle_(other.reference_type_handle_) { |
| 2456 | } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2457 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2458 | private: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2459 | using InstructionKindField = |
| 2460 | BitField<InstructionKind, kFieldInstructionKind, kFieldInstructionKindSize>; |
| 2461 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2462 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2463 | auto before_use_node = uses_.before_begin(); |
| 2464 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2465 | HInstruction* user = use_node->GetUser(); |
| 2466 | size_t input_index = use_node->GetIndex(); |
| 2467 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2468 | before_use_node = use_node; |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2473 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2474 | if (next != uses_.end()) { |
| 2475 | HInstruction* next_user = next->GetUser(); |
| 2476 | size_t next_index = next->GetIndex(); |
| 2477 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2478 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2483 | auto before_env_use_node = env_uses_.before_begin(); |
| 2484 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2485 | HEnvironment* user = env_use_node->GetUser(); |
| 2486 | size_t input_index = env_use_node->GetIndex(); |
| 2487 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2488 | before_env_use_node = env_use_node; |
| 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2493 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2494 | if (next != env_uses_.end()) { |
| 2495 | HEnvironment* next_user = next->GetUser(); |
| 2496 | size_t next_index = next->GetIndex(); |
| 2497 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2498 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2499 | } |
| 2500 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2501 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2502 | HInstruction* previous_; |
| 2503 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2504 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2505 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2506 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2507 | // An instruction gets an id when it is added to the graph. |
| 2508 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2509 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2510 | int id_; |
| 2511 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2512 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2513 | int ssa_index_; |
| 2514 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2515 | // Packed fields. |
| 2516 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2517 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2518 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2519 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2520 | |
| 2521 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2522 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2523 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2524 | // The environment associated with this instruction. Not null if the instruction |
| 2525 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2526 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2527 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2528 | // Set by the code generator. |
| 2529 | LocationSummary* locations_; |
| 2530 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2531 | // Set by the liveness analysis. |
| 2532 | LiveInterval* live_interval_; |
| 2533 | |
| 2534 | // Set by the liveness analysis, this is the position in a linear |
| 2535 | // order of blocks where this instruction's live interval start. |
| 2536 | size_t lifetime_position_; |
| 2537 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2538 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2539 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2540 | // The reference handle part of the reference type info. |
| 2541 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2542 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2543 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2544 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2545 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2546 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2547 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2548 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2549 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2550 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2551 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2552 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2553 | // Iterates over the instructions, while preserving the next instruction |
| 2554 | // in case the current instruction gets removed from the list by the user |
| 2555 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2556 | class HInstructionIterator : public ValueObject { |
| 2557 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2558 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2559 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2560 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2561 | } |
| 2562 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2563 | bool Done() const { return instruction_ == nullptr; } |
| 2564 | HInstruction* Current() const { return instruction_; } |
| 2565 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2566 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2567 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | private: |
| 2571 | HInstruction* instruction_; |
| 2572 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2573 | |
| 2574 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2575 | }; |
| 2576 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2577 | // Iterates over the instructions without saving the next instruction, |
| 2578 | // therefore handling changes in the graph potentially made by the user |
| 2579 | // of this iterator. |
| 2580 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2581 | public: |
| 2582 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2583 | : instruction_(instructions.first_instruction_) { |
| 2584 | } |
| 2585 | |
| 2586 | bool Done() const { return instruction_ == nullptr; } |
| 2587 | HInstruction* Current() const { return instruction_; } |
| 2588 | void Advance() { |
| 2589 | instruction_ = instruction_->GetNext(); |
| 2590 | } |
| 2591 | |
| 2592 | private: |
| 2593 | HInstruction* instruction_; |
| 2594 | |
| 2595 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2596 | }; |
| 2597 | |
| 2598 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2599 | class HBackwardInstructionIterator : public ValueObject { |
| 2600 | public: |
| 2601 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2602 | : instruction_(instructions.last_instruction_) { |
| 2603 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2604 | } |
| 2605 | |
| 2606 | bool Done() const { return instruction_ == nullptr; } |
| 2607 | HInstruction* Current() const { return instruction_; } |
| 2608 | void Advance() { |
| 2609 | instruction_ = next_; |
| 2610 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2611 | } |
| 2612 | |
| 2613 | private: |
| 2614 | HInstruction* instruction_; |
| 2615 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2616 | |
| 2617 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2618 | }; |
| 2619 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2620 | class HVariableInputSizeInstruction : public HInstruction { |
| 2621 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2622 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2623 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2624 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2625 | } |
| 2626 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2627 | void AddInput(HInstruction* input); |
| 2628 | void InsertInputAt(size_t index, HInstruction* input); |
| 2629 | void RemoveInputAt(size_t index); |
| 2630 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2631 | // Removes all the inputs. |
| 2632 | // Also removes this instructions from each input's use list |
| 2633 | // (for non-environment uses only). |
| 2634 | void RemoveAllInputs(); |
| 2635 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2636 | protected: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2637 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2638 | SideEffects side_effects, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2639 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2640 | ArenaAllocator* allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2641 | size_t number_of_inputs, |
| 2642 | ArenaAllocKind kind) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2643 | : HInstruction(inst_kind, side_effects, dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2644 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2645 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2646 | DataType::Type type, |
| 2647 | SideEffects side_effects, |
| 2648 | uint32_t dex_pc, |
| 2649 | ArenaAllocator* allocator, |
| 2650 | size_t number_of_inputs, |
| 2651 | ArenaAllocKind kind) |
| 2652 | : HInstruction(inst_kind, type, side_effects, dex_pc), |
| 2653 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2654 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2655 | DEFAULT_COPY_CONSTRUCTOR(VariableInputSizeInstruction); |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2656 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2657 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2658 | }; |
| 2659 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2660 | template<size_t N> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2661 | class HExpression : public HInstruction { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2662 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2663 | HExpression<N>(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2664 | : HInstruction(kind, side_effects, dex_pc), inputs_() {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2665 | HExpression<N>(InstructionKind kind, |
| 2666 | DataType::Type type, |
| 2667 | SideEffects side_effects, |
| 2668 | uint32_t dex_pc) |
| 2669 | : HInstruction(kind, type, side_effects, dex_pc), inputs_() {} |
| 2670 | virtual ~HExpression() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2671 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2672 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 2673 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2674 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2677 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2678 | DEFAULT_COPY_CONSTRUCTOR(Expression<N>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2679 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2680 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2681 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2682 | |
| 2683 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2684 | }; |
| 2685 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2686 | // HExpression specialization for N=0. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2687 | template<> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2688 | class HExpression<0> : public HInstruction { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2689 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2690 | using HInstruction::HInstruction; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2691 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2692 | virtual ~HExpression() {} |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2693 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2694 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 2695 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2696 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2697 | } |
| 2698 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2699 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2700 | DEFAULT_COPY_CONSTRUCTOR(Expression<0>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2701 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2702 | private: |
| 2703 | friend class SsaBuilder; |
| 2704 | }; |
| 2705 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2706 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2707 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2708 | class HReturnVoid final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2709 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2710 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2711 | : HExpression(kReturnVoid, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2712 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2713 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2714 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2715 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2716 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2717 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2718 | protected: |
| 2719 | DEFAULT_COPY_CONSTRUCTOR(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2720 | }; |
| 2721 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2722 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2723 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2724 | class HReturn final : public HExpression<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2725 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2726 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2727 | : HExpression(kReturn, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2728 | SetRawInputAt(0, value); |
| 2729 | } |
| 2730 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2731 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2732 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2733 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2734 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2735 | protected: |
| 2736 | DEFAULT_COPY_CONSTRUCTOR(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2737 | }; |
| 2738 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2739 | class HPhi final : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2740 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2741 | HPhi(ArenaAllocator* allocator, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2742 | uint32_t reg_number, |
| 2743 | size_t number_of_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2744 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2745 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2746 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2747 | kPhi, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2748 | ToPhiType(type), |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2749 | SideEffects::None(), |
| 2750 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2751 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2752 | number_of_inputs, |
| 2753 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2754 | reg_number_(reg_number) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2755 | DCHECK_NE(GetType(), DataType::Type::kVoid); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2756 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2757 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2758 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2759 | SetPackedFlag<kFlagIsLive>(true); |
| 2760 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2761 | } |
| 2762 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2763 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2764 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2765 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2766 | static DataType::Type ToPhiType(DataType::Type type) { |
| 2767 | return DataType::Kind(type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2771 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2772 | void SetType(DataType::Type new_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2773 | // Make sure that only valid type changes occur. The following are allowed: |
| 2774 | // (1) int -> float/ref (primitive type propagation), |
| 2775 | // (2) long -> double (primitive type propagation). |
| 2776 | DCHECK(GetType() == new_type || |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2777 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kFloat32) || |
| 2778 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kReference) || |
| 2779 | (GetType() == DataType::Type::kInt64 && new_type == DataType::Type::kFloat64)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2780 | SetPackedField<TypeField>(new_type); |
| 2781 | } |
| 2782 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2783 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2784 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2785 | |
| 2786 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2787 | |
| 2788 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2789 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2790 | bool IsDead() const { return !IsLive(); } |
| 2791 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2792 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2793 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2794 | return other != nullptr |
| 2795 | && other->IsPhi() |
| 2796 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2797 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2798 | } |
| 2799 | |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 2800 | bool HasEquivalentPhi() const { |
| 2801 | if (GetPrevious() != nullptr && GetPrevious()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2802 | return true; |
| 2803 | } |
| 2804 | if (GetNext() != nullptr && GetNext()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2805 | return true; |
| 2806 | } |
| 2807 | return false; |
| 2808 | } |
| 2809 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2810 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2811 | // An equivalent phi is a phi having the same dex register and type. |
| 2812 | // It assumes that phis with the same dex register are adjacent. |
| 2813 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2814 | HInstruction* next = GetNext(); |
| 2815 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2816 | if (next->GetType() == GetType()) { |
| 2817 | return next->AsPhi(); |
| 2818 | } |
| 2819 | next = next->GetNext(); |
| 2820 | } |
| 2821 | return nullptr; |
| 2822 | } |
| 2823 | |
| 2824 | DECLARE_INSTRUCTION(Phi); |
| 2825 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2826 | protected: |
| 2827 | DEFAULT_COPY_CONSTRUCTOR(Phi); |
| 2828 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2829 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2830 | static constexpr size_t kFlagIsLive = HInstruction::kNumberOfGenericPackedBits; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2831 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2832 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2833 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2834 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2835 | const uint32_t reg_number_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2836 | }; |
| 2837 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2838 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2839 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2840 | // exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2841 | class HExit final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2842 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2843 | explicit HExit(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2844 | : HExpression(kExit, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2845 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2846 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2847 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2848 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2849 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2850 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2851 | protected: |
| 2852 | DEFAULT_COPY_CONSTRUCTOR(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2853 | }; |
| 2854 | |
| 2855 | // Jumps from one block to another. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2856 | class HGoto final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2857 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2858 | explicit HGoto(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2859 | : HExpression(kGoto, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2860 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2861 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2862 | bool IsClonable() const override { return true; } |
| 2863 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2864 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2865 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2866 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2867 | } |
| 2868 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2869 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2870 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2871 | protected: |
| 2872 | DEFAULT_COPY_CONSTRUCTOR(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2873 | }; |
| 2874 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2875 | class HConstant : public HExpression<0> { |
| 2876 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2877 | explicit HConstant(InstructionKind kind, DataType::Type type, uint32_t dex_pc = kNoDexPc) |
| 2878 | : HExpression(kind, type, SideEffects::None(), dex_pc) { |
| 2879 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2880 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2881 | bool CanBeMoved() const override { return true; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2882 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2883 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2884 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2885 | // Is this constant 0 in the arithmetic sense? |
| 2886 | virtual bool IsArithmeticZero() const { return false; } |
| 2887 | // Is this constant a 0-bit pattern? |
| 2888 | virtual bool IsZeroBitPattern() const { return false; } |
| 2889 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2890 | virtual bool IsOne() const { return false; } |
| 2891 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2892 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2893 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2894 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2895 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2896 | protected: |
| 2897 | DEFAULT_COPY_CONSTRUCTOR(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2898 | }; |
| 2899 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2900 | class HNullConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2901 | public: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2902 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2903 | return true; |
| 2904 | } |
| 2905 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2906 | uint64_t GetValueAsUint64() const override { return 0; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2907 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2908 | size_t ComputeHashCode() const override { return 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2909 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2910 | // The null constant representation is a 0-bit pattern. |
| 2911 | virtual bool IsZeroBitPattern() const { return true; } |
| 2912 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2913 | DECLARE_INSTRUCTION(NullConstant); |
| 2914 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2915 | protected: |
| 2916 | DEFAULT_COPY_CONSTRUCTOR(NullConstant); |
| 2917 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2918 | private: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2919 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2920 | : HConstant(kNullConstant, DataType::Type::kReference, dex_pc) { |
| 2921 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2922 | |
| 2923 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2924 | }; |
| 2925 | |
| 2926 | // Constants of the type int. Those can be from Dex instructions, or |
| 2927 | // synthesized (for example with the if-eqz instruction). |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2928 | class HIntConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2929 | public: |
| 2930 | int32_t GetValue() const { return value_; } |
| 2931 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2932 | uint64_t GetValueAsUint64() const override { |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2933 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2934 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2935 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2936 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2937 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2938 | return other->AsIntConstant()->value_ == value_; |
| 2939 | } |
| 2940 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2941 | size_t ComputeHashCode() const override { return GetValue(); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2942 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2943 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 2944 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 2945 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 2946 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2947 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2948 | // Integer constants are used to encode Boolean values as well, |
| 2949 | // where 1 means true and 0 means false. |
| 2950 | bool IsTrue() const { return GetValue() == 1; } |
| 2951 | bool IsFalse() const { return GetValue() == 0; } |
| 2952 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2953 | DECLARE_INSTRUCTION(IntConstant); |
| 2954 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2955 | protected: |
| 2956 | DEFAULT_COPY_CONSTRUCTOR(IntConstant); |
| 2957 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2958 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2959 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2960 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), value_(value) { |
| 2961 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2962 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2963 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), |
| 2964 | value_(value ? 1 : 0) { |
| 2965 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2966 | |
| 2967 | const int32_t value_; |
| 2968 | |
| 2969 | friend class HGraph; |
| 2970 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2971 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2972 | }; |
| 2973 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2974 | class HLongConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2975 | public: |
| 2976 | int64_t GetValue() const { return value_; } |
| 2977 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2978 | uint64_t GetValueAsUint64() const override { return value_; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2979 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2980 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2981 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2982 | return other->AsLongConstant()->value_ == value_; |
| 2983 | } |
| 2984 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2985 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2986 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2987 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 2988 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 2989 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 2990 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2991 | |
| 2992 | DECLARE_INSTRUCTION(LongConstant); |
| 2993 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2994 | protected: |
| 2995 | DEFAULT_COPY_CONSTRUCTOR(LongConstant); |
| 2996 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2997 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2998 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2999 | : HConstant(kLongConstant, DataType::Type::kInt64, dex_pc), |
| 3000 | value_(value) { |
| 3001 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3002 | |
| 3003 | const int64_t value_; |
| 3004 | |
| 3005 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3006 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3007 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3008 | class HFloatConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3009 | public: |
| 3010 | float GetValue() const { return value_; } |
| 3011 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3012 | uint64_t GetValueAsUint64() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3013 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3014 | } |
| 3015 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3016 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3017 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 3018 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3019 | } |
| 3020 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3021 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3022 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3023 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3024 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 3025 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3026 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3027 | return std::fpclassify(value_) == FP_ZERO; |
| 3028 | } |
| 3029 | bool IsArithmeticPositiveZero() const { |
| 3030 | return IsArithmeticZero() && !std::signbit(value_); |
| 3031 | } |
| 3032 | bool IsArithmeticNegativeZero() const { |
| 3033 | return IsArithmeticZero() && std::signbit(value_); |
| 3034 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3035 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3036 | 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] | 3037 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3038 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3039 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3040 | } |
| 3041 | bool IsNaN() const { |
| 3042 | return std::isnan(value_); |
| 3043 | } |
| 3044 | |
| 3045 | DECLARE_INSTRUCTION(FloatConstant); |
| 3046 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3047 | protected: |
| 3048 | DEFAULT_COPY_CONSTRUCTOR(FloatConstant); |
| 3049 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3050 | private: |
| 3051 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3052 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3053 | value_(value) { |
| 3054 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3055 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3056 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3057 | value_(bit_cast<float, int32_t>(value)) { |
| 3058 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3059 | |
| 3060 | const float value_; |
| 3061 | |
| 3062 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3063 | friend class SsaBuilder; |
| 3064 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3065 | }; |
| 3066 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3067 | class HDoubleConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3068 | public: |
| 3069 | double GetValue() const { return value_; } |
| 3070 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3071 | uint64_t GetValueAsUint64() const override { return bit_cast<uint64_t, double>(value_); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3072 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3073 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3074 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 3075 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3076 | } |
| 3077 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3078 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3079 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3080 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3081 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 3082 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3083 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3084 | return std::fpclassify(value_) == FP_ZERO; |
| 3085 | } |
| 3086 | bool IsArithmeticPositiveZero() const { |
| 3087 | return IsArithmeticZero() && !std::signbit(value_); |
| 3088 | } |
| 3089 | bool IsArithmeticNegativeZero() const { |
| 3090 | return IsArithmeticZero() && std::signbit(value_); |
| 3091 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3092 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3093 | 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] | 3094 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3095 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3096 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3097 | } |
| 3098 | bool IsNaN() const { |
| 3099 | return std::isnan(value_); |
| 3100 | } |
| 3101 | |
| 3102 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3103 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3104 | protected: |
| 3105 | DEFAULT_COPY_CONSTRUCTOR(DoubleConstant); |
| 3106 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3107 | private: |
| 3108 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3109 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3110 | value_(value) { |
| 3111 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3112 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3113 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3114 | value_(bit_cast<double, int64_t>(value)) { |
| 3115 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3116 | |
| 3117 | const double value_; |
| 3118 | |
| 3119 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3120 | friend class SsaBuilder; |
| 3121 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3122 | }; |
| 3123 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3124 | // Conditional branch. A block ending with an HIf instruction must have |
| 3125 | // two successors. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3126 | class HIf final : public HExpression<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3127 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3128 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3129 | : HExpression(kIf, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3130 | SetRawInputAt(0, input); |
| 3131 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3132 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3133 | bool IsClonable() const override { return true; } |
| 3134 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3135 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3136 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3137 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3141 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3142 | } |
| 3143 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3144 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3145 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3146 | protected: |
| 3147 | DEFAULT_COPY_CONSTRUCTOR(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3148 | }; |
| 3149 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3150 | |
| 3151 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 3152 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 3153 | // non-exceptional control flow. |
| 3154 | // Normal-flow successor is stored at index zero, exception handlers under |
| 3155 | // higher indices in no particular order. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3156 | class HTryBoundary final : public HExpression<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3157 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3158 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3159 | kEntry, |
| 3160 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3161 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3162 | }; |
| 3163 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3164 | // SideEffects::CanTriggerGC prevents instructions with SideEffects::DependOnGC to be alive |
| 3165 | // across the catch block entering edges as GC might happen during throwing an exception. |
| 3166 | // TryBoundary with BoundaryKind::kExit is conservatively used for that as there is no |
| 3167 | // HInstruction which a catch block must start from. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3168 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3169 | : HExpression(kTryBoundary, |
| 3170 | (kind == BoundaryKind::kExit) ? SideEffects::CanTriggerGC() |
| 3171 | : SideEffects::None(), |
| 3172 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3173 | SetPackedField<BoundaryKindField>(kind); |
| 3174 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3175 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3176 | bool IsControlFlow() const override { return true; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3177 | |
| 3178 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3179 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3180 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 3181 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 3182 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 3183 | } |
| 3184 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3185 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 3186 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3187 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 3188 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 3189 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | // If not present already, adds `handler` to its block's list of exception |
| 3193 | // handlers. |
| 3194 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3195 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3196 | GetBlock()->AddSuccessor(handler); |
| 3197 | } |
| 3198 | } |
| 3199 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3200 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 3201 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3202 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3203 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 3204 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3205 | DECLARE_INSTRUCTION(TryBoundary); |
| 3206 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3207 | protected: |
| 3208 | DEFAULT_COPY_CONSTRUCTOR(TryBoundary); |
| 3209 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3210 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3211 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 3212 | static constexpr size_t kFieldBoundaryKindSize = |
| 3213 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 3214 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 3215 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 3216 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 3217 | "Too many packed fields."); |
| 3218 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3219 | }; |
| 3220 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3221 | // Deoptimize to interpreter, upon checking a condition. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3222 | class HDeoptimize final : public HVariableInputSizeInstruction { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3223 | public: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3224 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 3225 | // across. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3226 | HDeoptimize(ArenaAllocator* allocator, |
| 3227 | HInstruction* cond, |
| 3228 | DeoptimizationKind kind, |
| 3229 | uint32_t dex_pc) |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3230 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3231 | kDeoptimize, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3232 | SideEffects::All(), |
| 3233 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3234 | allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3235 | /* number_of_inputs */ 1, |
| 3236 | kArenaAllocMisc) { |
| 3237 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 3238 | SetPackedField<DeoptimizeKindField>(kind); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3239 | SetRawInputAt(0, cond); |
| 3240 | } |
| 3241 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3242 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3243 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3244 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3245 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3246 | // instead of `guard`. |
| 3247 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3248 | // at the point of the `HDeoptimize`. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3249 | HDeoptimize(ArenaAllocator* allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3250 | HInstruction* cond, |
| 3251 | HInstruction* guard, |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3252 | DeoptimizationKind kind, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3253 | uint32_t dex_pc) |
| 3254 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3255 | kDeoptimize, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3256 | guard->GetType(), |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3257 | SideEffects::CanTriggerGC(), |
| 3258 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3259 | allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3260 | /* number_of_inputs */ 2, |
| 3261 | kArenaAllocMisc) { |
| 3262 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3263 | SetPackedField<DeoptimizeKindField>(kind); |
| 3264 | SetRawInputAt(0, cond); |
| 3265 | SetRawInputAt(1, guard); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3266 | } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3267 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3268 | bool CanBeMoved() const override { return GetPackedFlag<kFieldCanBeMoved>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3269 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3270 | bool InstructionDataEquals(const HInstruction* other) const override { |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3271 | return (other->CanBeMoved() == CanBeMoved()) && (other->AsDeoptimize()->GetKind() == GetKind()); |
| 3272 | } |
| 3273 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3274 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3275 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3276 | bool CanThrow() const override { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3277 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3278 | DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3279 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3280 | bool GuardsAnInput() const { |
| 3281 | return InputCount() == 2; |
| 3282 | } |
| 3283 | |
| 3284 | HInstruction* GuardedInput() const { |
| 3285 | DCHECK(GuardsAnInput()); |
| 3286 | return InputAt(1); |
| 3287 | } |
| 3288 | |
| 3289 | void RemoveGuard() { |
| 3290 | RemoveInputAt(1); |
| 3291 | } |
| 3292 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3293 | DECLARE_INSTRUCTION(Deoptimize); |
| 3294 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3295 | protected: |
| 3296 | DEFAULT_COPY_CONSTRUCTOR(Deoptimize); |
| 3297 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3298 | private: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3299 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3300 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3301 | static constexpr size_t kFieldDeoptimizeKindSize = |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3302 | MinimumBitsToStore(static_cast<size_t>(DeoptimizationKind::kLast)); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3303 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3304 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3305 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3306 | "Too many packed fields."); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3307 | using DeoptimizeKindField = |
| 3308 | BitField<DeoptimizationKind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3309 | }; |
| 3310 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3311 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3312 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3313 | // if it's true, starts to do deoptimization. |
| 3314 | // It has a 4-byte slot on stack. |
| 3315 | // TODO: allocate a register for this flag. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3316 | class HShouldDeoptimizeFlag final : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3317 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3318 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3319 | // with regard to other passes. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3320 | HShouldDeoptimizeFlag(ArenaAllocator* allocator, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3321 | : HVariableInputSizeInstruction(kShouldDeoptimizeFlag, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3322 | DataType::Type::kInt32, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3323 | SideEffects::None(), |
| 3324 | dex_pc, |
| 3325 | allocator, |
| 3326 | 0, |
| 3327 | kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3328 | } |
| 3329 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3330 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3331 | // further guard elimination/motion since a guard might have been used for justification |
| 3332 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3333 | // to avoid other optimizations trying to move it. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3334 | bool CanBeMoved() const override { return false; } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3335 | |
| 3336 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3337 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3338 | protected: |
| 3339 | DEFAULT_COPY_CONSTRUCTOR(ShouldDeoptimizeFlag); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3340 | }; |
| 3341 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3342 | // Represents the ArtMethod that was passed as a first argument to |
| 3343 | // the method. It is used by instructions that depend on it, like |
| 3344 | // instructions that work with the dex cache. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3345 | class HCurrentMethod final : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3346 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3347 | explicit HCurrentMethod(DataType::Type type, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3348 | : HExpression(kCurrentMethod, type, SideEffects::None(), dex_pc) { |
| 3349 | } |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3350 | |
| 3351 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3352 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3353 | protected: |
| 3354 | DEFAULT_COPY_CONSTRUCTOR(CurrentMethod); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3355 | }; |
| 3356 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3357 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3358 | // of a class. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3359 | class HClassTableGet final : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3360 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3361 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3362 | kVTable, |
| 3363 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3364 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3365 | }; |
| 3366 | HClassTableGet(HInstruction* cls, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3367 | DataType::Type type, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3368 | TableKind kind, |
| 3369 | size_t index, |
| 3370 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3371 | : HExpression(kClassTableGet, type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3372 | index_(index) { |
| 3373 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3374 | SetRawInputAt(0, cls); |
| 3375 | } |
| 3376 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3377 | bool IsClonable() const override { return true; } |
| 3378 | bool CanBeMoved() const override { return true; } |
| 3379 | bool InstructionDataEquals(const HInstruction* other) const override { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3380 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3381 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3382 | } |
| 3383 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3384 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3385 | size_t GetIndex() const { return index_; } |
| 3386 | |
| 3387 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3388 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3389 | protected: |
| 3390 | DEFAULT_COPY_CONSTRUCTOR(ClassTableGet); |
| 3391 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3392 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3393 | static constexpr size_t kFieldTableKind = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3394 | static constexpr size_t kFieldTableKindSize = |
| 3395 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3396 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3397 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3398 | "Too many packed fields."); |
| 3399 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3400 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3401 | // The index of the ArtMethod in the table. |
| 3402 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3403 | }; |
| 3404 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3405 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3406 | // have one successor for each entry in the switch table, and the final successor |
| 3407 | // will be the block containing the next Dex opcode. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3408 | class HPackedSwitch final : public HExpression<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3409 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3410 | HPackedSwitch(int32_t start_value, |
| 3411 | uint32_t num_entries, |
| 3412 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3413 | uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3414 | : HExpression(kPackedSwitch, SideEffects::None(), dex_pc), |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3415 | start_value_(start_value), |
| 3416 | num_entries_(num_entries) { |
| 3417 | SetRawInputAt(0, input); |
| 3418 | } |
| 3419 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3420 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3421 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3422 | bool IsControlFlow() const override { return true; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3423 | |
| 3424 | int32_t GetStartValue() const { return start_value_; } |
| 3425 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3426 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3427 | |
| 3428 | HBasicBlock* GetDefaultBlock() const { |
| 3429 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3430 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3431 | } |
| 3432 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3433 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3434 | protected: |
| 3435 | DEFAULT_COPY_CONSTRUCTOR(PackedSwitch); |
| 3436 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3437 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3438 | const int32_t start_value_; |
| 3439 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3440 | }; |
| 3441 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3442 | class HUnaryOperation : public HExpression<1> { |
| 3443 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3444 | HUnaryOperation(InstructionKind kind, |
| 3445 | DataType::Type result_type, |
| 3446 | HInstruction* input, |
| 3447 | uint32_t dex_pc = kNoDexPc) |
| 3448 | : HExpression(kind, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3449 | SetRawInputAt(0, input); |
| 3450 | } |
| 3451 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3452 | // All of the UnaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3453 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3454 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3455 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3456 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3457 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3458 | bool CanBeMoved() const override { return true; } |
| 3459 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3460 | return true; |
| 3461 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3462 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3463 | // Try to statically evaluate `this` and return a HConstant |
| 3464 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3465 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3466 | HConstant* TryStaticEvaluation() const; |
| 3467 | |
| 3468 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3469 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3470 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3471 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3472 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3473 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3474 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3475 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3476 | protected: |
| 3477 | DEFAULT_COPY_CONSTRUCTOR(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3478 | }; |
| 3479 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3480 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3481 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3482 | HBinaryOperation(InstructionKind kind, |
| 3483 | DataType::Type result_type, |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3484 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3485 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3486 | SideEffects side_effects = SideEffects::None(), |
| 3487 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3488 | : HExpression(kind, result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3489 | SetRawInputAt(0, left); |
| 3490 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3491 | } |
| 3492 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3493 | // All of the BinaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3494 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3495 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3496 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3497 | HInstruction* GetRight() const { return InputAt(1); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3498 | DataType::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3499 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3500 | virtual bool IsCommutative() const { return false; } |
| 3501 | |
| 3502 | // Put constant on the right. |
| 3503 | // Returns whether order is changed. |
| 3504 | bool OrderInputsWithConstantOnTheRight() { |
| 3505 | HInstruction* left = InputAt(0); |
| 3506 | HInstruction* right = InputAt(1); |
| 3507 | if (left->IsConstant() && !right->IsConstant()) { |
| 3508 | ReplaceInput(right, 0); |
| 3509 | ReplaceInput(left, 1); |
| 3510 | return true; |
| 3511 | } |
| 3512 | return false; |
| 3513 | } |
| 3514 | |
| 3515 | // Order inputs by instruction id, but favor constant on the right side. |
| 3516 | // This helps GVN for commutative ops. |
| 3517 | void OrderInputs() { |
| 3518 | DCHECK(IsCommutative()); |
| 3519 | HInstruction* left = InputAt(0); |
| 3520 | HInstruction* right = InputAt(1); |
| 3521 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3522 | return; |
| 3523 | } |
| 3524 | if (OrderInputsWithConstantOnTheRight()) { |
| 3525 | return; |
| 3526 | } |
| 3527 | // Order according to instruction id. |
| 3528 | if (left->GetId() > right->GetId()) { |
| 3529 | ReplaceInput(right, 0); |
| 3530 | ReplaceInput(left, 1); |
| 3531 | } |
| 3532 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3533 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3534 | bool CanBeMoved() const override { return true; } |
| 3535 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3536 | return true; |
| 3537 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3538 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3539 | // Try to statically evaluate `this` and return a HConstant |
| 3540 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3541 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3542 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3543 | |
| 3544 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3545 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3546 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3547 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3548 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3549 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3550 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3551 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3552 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3553 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3554 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3555 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3556 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3557 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3558 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3559 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3560 | // 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] | 3561 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3562 | HConstant* GetConstantRight() const; |
| 3563 | |
| 3564 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3565 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3566 | HInstruction* GetLeastConstantLeft() const; |
| 3567 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3568 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3569 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3570 | protected: |
| 3571 | DEFAULT_COPY_CONSTRUCTOR(BinaryOperation); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3572 | }; |
| 3573 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3574 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3575 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3576 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3577 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3578 | kGtBias, // return 1 for NaN comparisons |
| 3579 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3580 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3581 | }; |
| 3582 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3583 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3584 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3585 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3586 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3587 | HCondition(InstructionKind kind, |
| 3588 | HInstruction* first, |
| 3589 | HInstruction* second, |
| 3590 | uint32_t dex_pc = kNoDexPc) |
| 3591 | : HBinaryOperation(kind, |
| 3592 | DataType::Type::kBool, |
| 3593 | first, |
| 3594 | second, |
| 3595 | SideEffects::None(), |
| 3596 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3597 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3598 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3599 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3600 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3601 | // `instruction`, and disregard moves in between. |
| 3602 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3603 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3604 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3605 | |
| 3606 | virtual IfCondition GetCondition() const = 0; |
| 3607 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3608 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3609 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3610 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3611 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3612 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3613 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3614 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3615 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3616 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3617 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3618 | } |
| 3619 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3620 | bool IsFPConditionTrueIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3621 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3622 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3623 | if (if_cond == kCondNE) { |
| 3624 | return true; |
| 3625 | } else if (if_cond == kCondEQ) { |
| 3626 | return false; |
| 3627 | } |
| 3628 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | bool IsFPConditionFalseIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3632 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3633 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3634 | if (if_cond == kCondEQ) { |
| 3635 | return true; |
| 3636 | } else if (if_cond == kCondNE) { |
| 3637 | return false; |
| 3638 | } |
| 3639 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3640 | } |
| 3641 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3642 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3643 | // Needed if we merge a HCompare into a HCondition. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3644 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3645 | static constexpr size_t kFieldComparisonBiasSize = |
| 3646 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3647 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3648 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3649 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3650 | using ComparisonBiasField = |
| 3651 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3652 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3653 | template <typename T> |
| 3654 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3655 | |
| 3656 | template <typename T> |
| 3657 | int32_t CompareFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3658 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3659 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3660 | // Handle the bias. |
| 3661 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3662 | } |
| 3663 | |
| 3664 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3665 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3666 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3667 | } |
| 3668 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3669 | DEFAULT_COPY_CONSTRUCTOR(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3670 | }; |
| 3671 | |
| 3672 | // Instruction to check if two inputs are equal to each other. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3673 | class HEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3674 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3675 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3676 | : HCondition(kEqual, first, second, dex_pc) { |
| 3677 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3678 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3679 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3680 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3681 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3682 | HNullConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3683 | return MakeConstantCondition(true, GetDexPc()); |
| 3684 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3685 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3686 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3687 | } |
| 3688 | // In the following Evaluate methods, a HCompare instruction has |
| 3689 | // been merged into this HEqual instruction; evaluate it as |
| 3690 | // `Compare(x, y) == 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3691 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3692 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3693 | GetDexPc()); |
| 3694 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3695 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3696 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3697 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3698 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3699 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3700 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3701 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3702 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3703 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3704 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3705 | return kCondEQ; |
| 3706 | } |
| 3707 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3708 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3709 | return kCondNE; |
| 3710 | } |
| 3711 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3712 | protected: |
| 3713 | DEFAULT_COPY_CONSTRUCTOR(Equal); |
| 3714 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3715 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3716 | template <typename T> static bool Compute(T x, T y) { return x == y; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3717 | }; |
| 3718 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3719 | class HNotEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3720 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3721 | HNotEqual(HInstruction* first, HInstruction* second, |
| 3722 | uint32_t dex_pc = kNoDexPc) |
| 3723 | : HCondition(kNotEqual, first, second, dex_pc) { |
| 3724 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3725 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3726 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3727 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3728 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3729 | HNullConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3730 | return MakeConstantCondition(false, GetDexPc()); |
| 3731 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3732 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3733 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3734 | } |
| 3735 | // In the following Evaluate methods, a HCompare instruction has |
| 3736 | // been merged into this HNotEqual instruction; evaluate it as |
| 3737 | // `Compare(x, y) != 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3738 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3739 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3740 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3741 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3742 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3743 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3744 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3745 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3746 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3747 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3748 | DECLARE_INSTRUCTION(NotEqual); |
| 3749 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3750 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3751 | return kCondNE; |
| 3752 | } |
| 3753 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3754 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3755 | return kCondEQ; |
| 3756 | } |
| 3757 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3758 | protected: |
| 3759 | DEFAULT_COPY_CONSTRUCTOR(NotEqual); |
| 3760 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3761 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3762 | template <typename T> static bool Compute(T x, T y) { return x != y; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3763 | }; |
| 3764 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3765 | class HLessThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3766 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3767 | HLessThan(HInstruction* first, HInstruction* second, |
| 3768 | uint32_t dex_pc = kNoDexPc) |
| 3769 | : HCondition(kLessThan, first, second, dex_pc) { |
| 3770 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3771 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3772 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3773 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3774 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3775 | // In the following Evaluate methods, a HCompare instruction has |
| 3776 | // been merged into this HLessThan instruction; evaluate it as |
| 3777 | // `Compare(x, y) < 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3778 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3779 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3780 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3781 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3782 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3783 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3784 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3785 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3786 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3787 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3788 | DECLARE_INSTRUCTION(LessThan); |
| 3789 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3790 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3791 | return kCondLT; |
| 3792 | } |
| 3793 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3794 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3795 | return kCondGE; |
| 3796 | } |
| 3797 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3798 | protected: |
| 3799 | DEFAULT_COPY_CONSTRUCTOR(LessThan); |
| 3800 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3801 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3802 | template <typename T> static bool Compute(T x, T y) { return x < y; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3803 | }; |
| 3804 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3805 | class HLessThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3806 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3807 | HLessThanOrEqual(HInstruction* first, HInstruction* second, |
| 3808 | uint32_t dex_pc = kNoDexPc) |
| 3809 | : HCondition(kLessThanOrEqual, first, second, dex_pc) { |
| 3810 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3811 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3812 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3813 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3814 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3815 | // In the following Evaluate methods, a HCompare instruction has |
| 3816 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3817 | // `Compare(x, y) <= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3818 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3819 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3820 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3821 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3822 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3823 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3824 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3825 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3826 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3827 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3828 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3829 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3830 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3831 | return kCondLE; |
| 3832 | } |
| 3833 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3834 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3835 | return kCondGT; |
| 3836 | } |
| 3837 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3838 | protected: |
| 3839 | DEFAULT_COPY_CONSTRUCTOR(LessThanOrEqual); |
| 3840 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3841 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3842 | template <typename T> static bool Compute(T x, T y) { return x <= y; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3843 | }; |
| 3844 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3845 | class HGreaterThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3846 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3847 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3848 | : HCondition(kGreaterThan, first, second, dex_pc) { |
| 3849 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3850 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3851 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3852 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3853 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3854 | // In the following Evaluate methods, a HCompare instruction has |
| 3855 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3856 | // `Compare(x, y) > 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3857 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3858 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3859 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3860 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3861 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3862 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3863 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3864 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3865 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3866 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3867 | DECLARE_INSTRUCTION(GreaterThan); |
| 3868 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3869 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3870 | return kCondGT; |
| 3871 | } |
| 3872 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3873 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3874 | return kCondLE; |
| 3875 | } |
| 3876 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3877 | protected: |
| 3878 | DEFAULT_COPY_CONSTRUCTOR(GreaterThan); |
| 3879 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3880 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3881 | template <typename T> static bool Compute(T x, T y) { return x > y; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3882 | }; |
| 3883 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3884 | class HGreaterThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3885 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3886 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3887 | : HCondition(kGreaterThanOrEqual, first, second, dex_pc) { |
| 3888 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3889 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3890 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3891 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3892 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3893 | // In the following Evaluate methods, a HCompare instruction has |
| 3894 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3895 | // `Compare(x, y) >= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3896 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3897 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3898 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3899 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3900 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3901 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3902 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3903 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3904 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3905 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3906 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3907 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3908 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3909 | return kCondGE; |
| 3910 | } |
| 3911 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3912 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3913 | return kCondLT; |
| 3914 | } |
| 3915 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3916 | protected: |
| 3917 | DEFAULT_COPY_CONSTRUCTOR(GreaterThanOrEqual); |
| 3918 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3919 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3920 | template <typename T> static bool Compute(T x, T y) { return x >= y; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3921 | }; |
| 3922 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3923 | class HBelow final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3924 | public: |
| 3925 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3926 | : HCondition(kBelow, first, second, dex_pc) { |
| 3927 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3928 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3929 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3930 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3931 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3932 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3933 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3934 | } |
| 3935 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3936 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3937 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3938 | UNREACHABLE(); |
| 3939 | } |
| 3940 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3941 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3942 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3943 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | DECLARE_INSTRUCTION(Below); |
| 3947 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3948 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3949 | return kCondB; |
| 3950 | } |
| 3951 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3952 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3953 | return kCondAE; |
| 3954 | } |
| 3955 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3956 | protected: |
| 3957 | DEFAULT_COPY_CONSTRUCTOR(Below); |
| 3958 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3959 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3960 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3961 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3962 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3963 | }; |
| 3964 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3965 | class HBelowOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3966 | public: |
| 3967 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3968 | : HCondition(kBelowOrEqual, first, second, dex_pc) { |
| 3969 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3970 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3971 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3972 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3973 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3974 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3975 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3976 | } |
| 3977 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3978 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3979 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3980 | UNREACHABLE(); |
| 3981 | } |
| 3982 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3983 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3984 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3985 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3986 | } |
| 3987 | |
| 3988 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3989 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3990 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3991 | return kCondBE; |
| 3992 | } |
| 3993 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3994 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3995 | return kCondA; |
| 3996 | } |
| 3997 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3998 | protected: |
| 3999 | DEFAULT_COPY_CONSTRUCTOR(BelowOrEqual); |
| 4000 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4001 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4002 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4003 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 4004 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4005 | }; |
| 4006 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4007 | class HAbove final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4008 | public: |
| 4009 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4010 | : HCondition(kAbove, first, second, dex_pc) { |
| 4011 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4012 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4013 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4014 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4015 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4016 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4017 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4018 | } |
| 4019 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4020 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4021 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4022 | UNREACHABLE(); |
| 4023 | } |
| 4024 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4025 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4026 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4027 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | DECLARE_INSTRUCTION(Above); |
| 4031 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4032 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4033 | return kCondA; |
| 4034 | } |
| 4035 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4036 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4037 | return kCondBE; |
| 4038 | } |
| 4039 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4040 | protected: |
| 4041 | DEFAULT_COPY_CONSTRUCTOR(Above); |
| 4042 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4043 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4044 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4045 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 4046 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4047 | }; |
| 4048 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4049 | class HAboveOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4050 | public: |
| 4051 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4052 | : HCondition(kAboveOrEqual, first, second, dex_pc) { |
| 4053 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4054 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4055 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4056 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4057 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4058 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4059 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4060 | } |
| 4061 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4062 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4063 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4064 | UNREACHABLE(); |
| 4065 | } |
| 4066 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4067 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4068 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4069 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 4073 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4074 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4075 | return kCondAE; |
| 4076 | } |
| 4077 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4078 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4079 | return kCondB; |
| 4080 | } |
| 4081 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4082 | protected: |
| 4083 | DEFAULT_COPY_CONSTRUCTOR(AboveOrEqual); |
| 4084 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4085 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4086 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4087 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 4088 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4089 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4090 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4091 | // Instruction to check how two inputs compare to each other. |
| 4092 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4093 | class HCompare final : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4094 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4095 | // Note that `comparison_type` is the type of comparison performed |
| 4096 | // between the comparison's inputs, not the type of the instantiated |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4097 | // HCompare instruction (which is always DataType::Type::kInt). |
| 4098 | HCompare(DataType::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4099 | HInstruction* first, |
| 4100 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4101 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4102 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4103 | : HBinaryOperation(kCompare, |
| 4104 | DataType::Type::kInt32, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4105 | first, |
| 4106 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4107 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4108 | dex_pc) { |
| 4109 | SetPackedField<ComparisonBiasField>(bias); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4110 | DCHECK_EQ(comparison_type, DataType::Kind(first->GetType())); |
| 4111 | DCHECK_EQ(comparison_type, DataType::Kind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4112 | } |
| 4113 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4114 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4115 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 4116 | |
| 4117 | template <typename T> |
| 4118 | int32_t ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4119 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4120 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 4121 | // Handle the bias. |
| 4122 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 4123 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4124 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4125 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4126 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 4127 | // reach this code path when processing a freshly built HIR |
| 4128 | // graph. However HCompare integer instructions can be synthesized |
| 4129 | // by the instruction simplifier to implement IntegerCompare and |
| 4130 | // IntegerSignum intrinsics, so we have to handle this case. |
| 4131 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4132 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4133 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4134 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4135 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4136 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4137 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4138 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4139 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4140 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4141 | } |
| 4142 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4143 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4144 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4145 | } |
| 4146 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4147 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4148 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4149 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4150 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4151 | bool IsGtBias() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4152 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4153 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4154 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4155 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4156 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type type ATTRIBUTE_UNUSED) { |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 4157 | // Comparisons do not require a runtime call in any back end. |
| 4158 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4159 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4160 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4161 | DECLARE_INSTRUCTION(Compare); |
| 4162 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4163 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4164 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4165 | static constexpr size_t kFieldComparisonBiasSize = |
| 4166 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 4167 | static constexpr size_t kNumberOfComparePackedBits = |
| 4168 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 4169 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4170 | using ComparisonBiasField = |
| 4171 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 4172 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4173 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 4174 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 4175 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 4176 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 4177 | } |
| 4178 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4179 | DEFAULT_COPY_CONSTRUCTOR(Compare); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4180 | }; |
| 4181 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4182 | class HNewInstance final : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4183 | public: |
| 4184 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4185 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4186 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4187 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4188 | bool finalizable, |
| 4189 | QuickEntrypointEnum entrypoint) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4190 | : HExpression(kNewInstance, |
| 4191 | DataType::Type::kReference, |
| 4192 | SideEffects::CanTriggerGC(), |
| 4193 | dex_pc), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4194 | type_index_(type_index), |
| 4195 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4196 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4197 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4198 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4199 | } |
| 4200 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4201 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4202 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4203 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4204 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4205 | |
| 4206 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4207 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4208 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4209 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4210 | bool CanThrow() const override { return true; } |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4211 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4212 | bool NeedsChecks() const { |
| 4213 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 4214 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4215 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4216 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4217 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4218 | bool CanBeNull() const override { return false; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4219 | |
| 4220 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4221 | |
| 4222 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 4223 | entrypoint_ = entrypoint; |
| 4224 | } |
| 4225 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4226 | HLoadClass* GetLoadClass() const { |
| 4227 | HInstruction* input = InputAt(0); |
| 4228 | if (input->IsClinitCheck()) { |
| 4229 | input = input->InputAt(0); |
| 4230 | } |
| 4231 | DCHECK(input->IsLoadClass()); |
| 4232 | return input->AsLoadClass(); |
| 4233 | } |
| 4234 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4235 | bool IsStringAlloc() const; |
| 4236 | |
| 4237 | DECLARE_INSTRUCTION(NewInstance); |
| 4238 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4239 | protected: |
| 4240 | DEFAULT_COPY_CONSTRUCTOR(NewInstance); |
| 4241 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4242 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4243 | static constexpr size_t kFlagFinalizable = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4244 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 4245 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 4246 | "Too many packed fields."); |
| 4247 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4248 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4249 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4250 | QuickEntrypointEnum entrypoint_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4251 | }; |
| 4252 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 4253 | enum IntrinsicNeedsEnvironmentOrCache { |
| 4254 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 4255 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4256 | }; |
| 4257 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4258 | enum IntrinsicSideEffects { |
| 4259 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 4260 | kReadSideEffects, // Intrinsic may read heap memory. |
| 4261 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 4262 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 4263 | }; |
| 4264 | |
| 4265 | enum IntrinsicExceptions { |
| 4266 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 4267 | kCanThrow // Intrinsic may throw exceptions. |
| 4268 | }; |
| 4269 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4270 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4271 | public: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4272 | bool NeedsEnvironment() const override; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4273 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 4274 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4275 | SetRawInputAt(index, argument); |
| 4276 | } |
| 4277 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4278 | // Return the number of arguments. This number can be lower than |
| 4279 | // the number of inputs returned by InputCount(), as some invoke |
| 4280 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 4281 | // inputs at the end of their list of inputs. |
| 4282 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 4283 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4284 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4285 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4286 | InvokeType GetInvokeType() const { |
| 4287 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4288 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4289 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 4290 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4291 | return intrinsic_; |
| 4292 | } |
| 4293 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4294 | void SetIntrinsic(Intrinsics intrinsic, |
| 4295 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 4296 | IntrinsicSideEffects side_effects, |
| 4297 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4298 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4299 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4300 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4301 | } |
| 4302 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4303 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4304 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4305 | bool CanThrow() const override { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4306 | |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4307 | void SetAlwaysThrows(bool always_throws) { SetPackedFlag<kFlagAlwaysThrows>(always_throws); } |
| 4308 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4309 | bool AlwaysThrows() const override { return GetPackedFlag<kFlagAlwaysThrows>(); } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4310 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4311 | bool CanBeMoved() const override { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4312 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4313 | bool InstructionDataEquals(const HInstruction* other) const override { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4314 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 4315 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4316 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4317 | uint32_t* GetIntrinsicOptimizations() { |
| 4318 | return &intrinsic_optimizations_; |
| 4319 | } |
| 4320 | |
| 4321 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4322 | return &intrinsic_optimizations_; |
| 4323 | } |
| 4324 | |
| 4325 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4326 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4327 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 4328 | void SetResolvedMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4329 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4330 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4331 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4332 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4333 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4334 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4335 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4336 | static constexpr size_t kFlagCanThrow = kFieldInvokeType + kFieldInvokeTypeSize; |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4337 | static constexpr size_t kFlagAlwaysThrows = kFlagCanThrow + 1; |
| 4338 | static constexpr size_t kNumberOfInvokePackedBits = kFlagAlwaysThrows + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4339 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4340 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4341 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4342 | HInvoke(InstructionKind kind, |
| 4343 | ArenaAllocator* allocator, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4344 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4345 | uint32_t number_of_other_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4346 | DataType::Type return_type, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4347 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4348 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4349 | ArtMethod* resolved_method, |
| 4350 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4351 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4352 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4353 | return_type, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4354 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4355 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4356 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4357 | number_of_arguments + number_of_other_inputs, |
| 4358 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4359 | number_of_arguments_(number_of_arguments), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4360 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4361 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4362 | intrinsic_optimizations_(0) { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4363 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4364 | SetPackedFlag<kFlagCanThrow>(true); |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 4365 | // Check mutator lock, constructors lack annotalysis support. |
| 4366 | Locks::mutator_lock_->AssertNotExclusiveHeld(Thread::Current()); |
| 4367 | SetResolvedMethod(resolved_method); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4368 | } |
| 4369 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4370 | DEFAULT_COPY_CONSTRUCTOR(Invoke); |
| 4371 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4372 | uint32_t number_of_arguments_; |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4373 | ArtMethod* resolved_method_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4374 | const uint32_t dex_method_index_; |
| 4375 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4376 | |
| 4377 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4378 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4379 | }; |
| 4380 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4381 | class HInvokeUnresolved final : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4382 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4383 | HInvokeUnresolved(ArenaAllocator* allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4384 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4385 | DataType::Type return_type, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4386 | uint32_t dex_pc, |
| 4387 | uint32_t dex_method_index, |
| 4388 | InvokeType invoke_type) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4389 | : HInvoke(kInvokeUnresolved, |
| 4390 | allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4391 | number_of_arguments, |
| 4392 | 0u /* number_of_other_inputs */, |
| 4393 | return_type, |
| 4394 | dex_pc, |
| 4395 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4396 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4397 | invoke_type) { |
| 4398 | } |
| 4399 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4400 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4401 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4402 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4403 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4404 | protected: |
| 4405 | DEFAULT_COPY_CONSTRUCTOR(InvokeUnresolved); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4406 | }; |
| 4407 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4408 | class HInvokePolymorphic final : public HInvoke { |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4409 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4410 | HInvokePolymorphic(ArenaAllocator* allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4411 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4412 | DataType::Type return_type, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4413 | uint32_t dex_pc, |
| 4414 | uint32_t dex_method_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4415 | : HInvoke(kInvokePolymorphic, |
| 4416 | allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4417 | number_of_arguments, |
| 4418 | 0u /* number_of_other_inputs */, |
| 4419 | return_type, |
| 4420 | dex_pc, |
| 4421 | dex_method_index, |
| 4422 | nullptr, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4423 | kVirtual) { |
| 4424 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4425 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4426 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4427 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4428 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4429 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4430 | protected: |
| 4431 | DEFAULT_COPY_CONSTRUCTOR(InvokePolymorphic); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4432 | }; |
| 4433 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4434 | class HInvokeCustom final : public HInvoke { |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4435 | public: |
| 4436 | HInvokeCustom(ArenaAllocator* allocator, |
| 4437 | uint32_t number_of_arguments, |
| 4438 | uint32_t call_site_index, |
| 4439 | DataType::Type return_type, |
| 4440 | uint32_t dex_pc) |
| 4441 | : HInvoke(kInvokeCustom, |
| 4442 | allocator, |
| 4443 | number_of_arguments, |
| 4444 | /* number_of_other_inputs */ 0u, |
| 4445 | return_type, |
| 4446 | dex_pc, |
| 4447 | /* dex_method_index */ dex::kDexNoIndex, |
| 4448 | /* resolved_method */ nullptr, |
| 4449 | kStatic), |
| 4450 | call_site_index_(call_site_index) { |
| 4451 | } |
| 4452 | |
| 4453 | uint32_t GetCallSiteIndex() const { return call_site_index_; } |
| 4454 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4455 | bool IsClonable() const override { return true; } |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4456 | |
| 4457 | DECLARE_INSTRUCTION(InvokeCustom); |
| 4458 | |
| 4459 | protected: |
| 4460 | DEFAULT_COPY_CONSTRUCTOR(InvokeCustom); |
| 4461 | |
| 4462 | private: |
| 4463 | uint32_t call_site_index_; |
| 4464 | }; |
| 4465 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4466 | class HInvokeStaticOrDirect final : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4467 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4468 | // Requirements of this method call regarding the class |
| 4469 | // initialization (clinit) check of its declaring class. |
| 4470 | enum class ClinitCheckRequirement { |
| 4471 | kNone, // Class already initialized. |
| 4472 | kExplicit, // Static call having explicit clinit check as last input. |
| 4473 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4474 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4475 | }; |
| 4476 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4477 | // Determines how to load the target ArtMethod*. |
| 4478 | enum class MethodLoadKind { |
| 4479 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4480 | kStringInit, |
| 4481 | |
| 4482 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4483 | kRecursive, |
| 4484 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4485 | // Use PC-relative boot image ArtMethod* address that will be known at link time. |
| 4486 | // Used for boot image methods referenced by boot image code. |
| 4487 | kBootImageLinkTimePcRelative, |
| 4488 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4489 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| 4490 | // Used for app->boot calls with relocatable image. |
| 4491 | kBootImageRelRo, |
| 4492 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4493 | // Load from an entry in the .bss section using a PC-relative load. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4494 | // Used for methods outside boot image referenced by AOT-compiled app and boot image code. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4495 | kBssEntry, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4496 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4497 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4498 | // Used for for JIT-compiled calls. |
| 4499 | kJitDirectAddress, |
| 4500 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4501 | // Make a runtime call to resolve and call the method. This is the last-resort-kind |
| 4502 | // used when other kinds are unimplemented on a particular architecture. |
| 4503 | kRuntimeCall, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4504 | }; |
| 4505 | |
| 4506 | // Determines the location of the code pointer. |
| 4507 | enum class CodePtrLocation { |
| 4508 | // Recursive call, use local PC-relative call instruction. |
| 4509 | kCallSelf, |
| 4510 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4511 | // Use code pointer from the ArtMethod*. |
| 4512 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4513 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4514 | kCallArtMethod, |
| 4515 | }; |
| 4516 | |
| 4517 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4518 | MethodLoadKind method_load_kind; |
| 4519 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4520 | // The method load data holds |
| 4521 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4522 | // Note that there are multiple string init methods, each having its own offset. |
| 4523 | // - the method address for kDirectAddress |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4524 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4525 | }; |
| 4526 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4527 | HInvokeStaticOrDirect(ArenaAllocator* allocator, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4528 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4529 | DataType::Type return_type, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4530 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4531 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4532 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4533 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4534 | InvokeType invoke_type, |
| 4535 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4536 | ClinitCheckRequirement clinit_check_requirement) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4537 | : HInvoke(kInvokeStaticOrDirect, |
| 4538 | allocator, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4539 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4540 | // There is potentially one extra argument for the HCurrentMethod node, and |
Nicolas Geoffray | 0846a8f | 2018-09-12 15:21:07 +0100 | [diff] [blame] | 4541 | // potentially one other if the clinit check is explicit. |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4542 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4543 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4544 | return_type, |
| 4545 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4546 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4547 | resolved_method, |
| 4548 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4549 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4550 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4551 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4552 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4553 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4554 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4555 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4556 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4557 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4558 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4559 | |
| 4560 | // Using the current method is the default and once we find a better |
| 4561 | // method load kind, we should not go back to using the current method. |
| 4562 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4563 | |
| 4564 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4565 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4566 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4567 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4568 | dispatch_info_ = dispatch_info; |
| 4569 | } |
| 4570 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 4571 | DispatchInfo GetDispatchInfo() const { |
| 4572 | return dispatch_info_; |
| 4573 | } |
| 4574 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4575 | void AddSpecialInput(HInstruction* input) { |
| 4576 | // We allow only one special input. |
| 4577 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4578 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4579 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4580 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4581 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4582 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4583 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4584 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4585 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4586 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4587 | DCHECK(!input_records.empty()); |
| 4588 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4589 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4590 | // Note: `last_input` may be null during arguments setup. |
| 4591 | if (last_input != nullptr) { |
| 4592 | // `last_input` is the last input of a static invoke marked as having |
| 4593 | // an explicit clinit check. It must either be: |
| 4594 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4595 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4596 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4597 | } |
| 4598 | } |
| 4599 | return input_records; |
| 4600 | } |
| 4601 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4602 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4603 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4604 | // TODO: for intrinsics we can generate implicit null checks. |
| 4605 | return false; |
| 4606 | } |
| 4607 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4608 | bool CanBeNull() const override { |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4609 | return GetType() == DataType::Type::kReference && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4610 | } |
| 4611 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4612 | // Get the index of the special input, if any. |
| 4613 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4614 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4615 | // method pointer; otherwise there may be one platform-specific special input, |
| 4616 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4617 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4618 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4619 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4620 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4621 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4622 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4623 | bool NeedsDexCacheOfDeclaringClass() const override; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4624 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4625 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kJitDirectAddress; } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4626 | bool HasPcRelativeMethodLoadKind() const { |
| 4627 | return GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4628 | GetMethodLoadKind() == MethodLoadKind::kBootImageRelRo || |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4629 | GetMethodLoadKind() == MethodLoadKind::kBssEntry; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4630 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4631 | bool HasCurrentMethodInput() const { |
| 4632 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4633 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4634 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4635 | return true; |
| 4636 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4637 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4638 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4639 | return false; |
| 4640 | } |
| 4641 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4642 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4643 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4644 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4645 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | uint64_t GetMethodAddress() const { |
| 4649 | DCHECK(HasMethodAddress()); |
| 4650 | return dispatch_info_.method_load_data; |
| 4651 | } |
| 4652 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4653 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4654 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4655 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4656 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4657 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4658 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4659 | // Is this instruction a call to a static method? |
| 4660 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4661 | return GetInvokeType() == kStatic; |
| 4662 | } |
| 4663 | |
| 4664 | MethodReference GetTargetMethod() const { |
| 4665 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4666 | } |
| 4667 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4668 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4669 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4670 | // instruction; only relevant for static calls with explicit clinit check. |
| 4671 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4672 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4673 | size_t last_input_index = inputs_.size() - 1u; |
| 4674 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4675 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4676 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4677 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4678 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4679 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4680 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4681 | } |
| 4682 | |
| 4683 | // 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] | 4684 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4685 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4686 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | // Is this a call to a static method whose declaring class has an |
| 4690 | // implicit intialization check requirement? |
| 4691 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4692 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4693 | } |
| 4694 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4695 | // Does this method load kind need the current method as an input? |
| 4696 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4697 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kRuntimeCall; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4698 | } |
| 4699 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4700 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4701 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4702 | protected: |
| 4703 | DEFAULT_COPY_CONSTRUCTOR(InvokeStaticOrDirect); |
| 4704 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4705 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4706 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4707 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4708 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4709 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4710 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4711 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4712 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4713 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4714 | kFieldClinitCheckRequirement, |
| 4715 | kFieldClinitCheckRequirementSize>; |
| 4716 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4717 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | ea179f4 | 2018-02-08 22:30:18 +0000 | [diff] [blame] | 4718 | const MethodReference target_method_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4719 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4720 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4721 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4722 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4723 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4724 | class HInvokeVirtual final : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4725 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4726 | HInvokeVirtual(ArenaAllocator* allocator, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4727 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4728 | DataType::Type return_type, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4729 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4730 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4731 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4732 | uint32_t vtable_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4733 | : HInvoke(kInvokeVirtual, |
| 4734 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4735 | number_of_arguments, |
| 4736 | 0u, |
| 4737 | return_type, |
| 4738 | dex_pc, |
| 4739 | dex_method_index, |
| 4740 | resolved_method, |
| 4741 | kVirtual), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4742 | vtable_index_(vtable_index) { |
| 4743 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4744 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4745 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4746 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4747 | bool CanBeNull() const override { |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4748 | switch (GetIntrinsic()) { |
| 4749 | case Intrinsics::kThreadCurrentThread: |
| 4750 | case Intrinsics::kStringBufferAppend: |
| 4751 | case Intrinsics::kStringBufferToString: |
| 4752 | case Intrinsics::kStringBuilderAppend: |
| 4753 | case Intrinsics::kStringBuilderToString: |
| 4754 | return false; |
| 4755 | default: |
| 4756 | return HInvoke::CanBeNull(); |
| 4757 | } |
| 4758 | } |
| 4759 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4760 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4761 | // TODO: Add implicit null checks in intrinsics. |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 4762 | return (obj == InputAt(0)) && !IsIntrinsic(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4763 | } |
| 4764 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4765 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4766 | |
| 4767 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4768 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4769 | protected: |
| 4770 | DEFAULT_COPY_CONSTRUCTOR(InvokeVirtual); |
| 4771 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4772 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4773 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4774 | const uint32_t vtable_index_; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4775 | }; |
| 4776 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4777 | class HInvokeInterface final : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4778 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4779 | HInvokeInterface(ArenaAllocator* allocator, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4780 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4781 | DataType::Type return_type, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4782 | uint32_t dex_pc, |
| 4783 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4784 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4785 | uint32_t imt_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4786 | : HInvoke(kInvokeInterface, |
| 4787 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4788 | number_of_arguments, |
| 4789 | 0u, |
| 4790 | return_type, |
| 4791 | dex_pc, |
| 4792 | dex_method_index, |
| 4793 | resolved_method, |
| 4794 | kInterface), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4795 | imt_index_(imt_index) { |
| 4796 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4797 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4798 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4799 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4800 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4801 | // TODO: Add implicit null checks in intrinsics. |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 4802 | return (obj == InputAt(0)) && !IsIntrinsic(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4803 | } |
| 4804 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4805 | bool NeedsDexCacheOfDeclaringClass() const override { |
Nicolas Geoffray | fbdfa6d | 2017-02-03 10:43:13 +0000 | [diff] [blame] | 4806 | // The assembly stub currently needs it. |
| 4807 | return true; |
| 4808 | } |
| 4809 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4810 | uint32_t GetImtIndex() const { return imt_index_; } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4811 | |
| 4812 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4813 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4814 | protected: |
| 4815 | DEFAULT_COPY_CONSTRUCTOR(InvokeInterface); |
| 4816 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4817 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4818 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4819 | const uint32_t imt_index_; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4820 | }; |
| 4821 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4822 | class HNeg final : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4823 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4824 | HNeg(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4825 | : HUnaryOperation(kNeg, result_type, input, dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4826 | DCHECK_EQ(result_type, DataType::Kind(input->GetType())); |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4827 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4828 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4829 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4830 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4831 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4832 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4833 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4834 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4835 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4836 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4837 | HConstant* Evaluate(HFloatConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4838 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4839 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4840 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4841 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4842 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4843 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4844 | DECLARE_INSTRUCTION(Neg); |
| 4845 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4846 | protected: |
| 4847 | DEFAULT_COPY_CONSTRUCTOR(Neg); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4848 | }; |
| 4849 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4850 | class HNewArray final : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4851 | public: |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4852 | HNewArray(HInstruction* cls, HInstruction* length, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4853 | : HExpression(kNewArray, DataType::Type::kReference, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4854 | SetRawInputAt(0, cls); |
| 4855 | SetRawInputAt(1, length); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4856 | } |
| 4857 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4858 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4859 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4860 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4861 | bool NeedsEnvironment() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4862 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4863 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4864 | bool CanThrow() const override { return true; } |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4865 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4866 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4867 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4868 | HLoadClass* GetLoadClass() const { |
| 4869 | DCHECK(InputAt(0)->IsLoadClass()); |
| 4870 | return InputAt(0)->AsLoadClass(); |
| 4871 | } |
| 4872 | |
| 4873 | HInstruction* GetLength() const { |
| 4874 | return InputAt(1); |
| 4875 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4876 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4877 | DECLARE_INSTRUCTION(NewArray); |
| 4878 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4879 | protected: |
| 4880 | DEFAULT_COPY_CONSTRUCTOR(NewArray); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4881 | }; |
| 4882 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4883 | class HAdd final : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4884 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4885 | HAdd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4886 | HInstruction* left, |
| 4887 | HInstruction* right, |
| 4888 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4889 | : HBinaryOperation(kAdd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4890 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4891 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4892 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4893 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4894 | 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] | 4895 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4896 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4897 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4898 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4899 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4900 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4901 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4902 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4903 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4904 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4905 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4906 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4907 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4908 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4909 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4910 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4911 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4912 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4913 | DECLARE_INSTRUCTION(Add); |
| 4914 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4915 | protected: |
| 4916 | DEFAULT_COPY_CONSTRUCTOR(Add); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4917 | }; |
| 4918 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4919 | class HSub final : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4920 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4921 | HSub(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4922 | HInstruction* left, |
| 4923 | HInstruction* right, |
| 4924 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4925 | : HBinaryOperation(kSub, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4926 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4927 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4928 | 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] | 4929 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4930 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4931 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4932 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4933 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4934 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4935 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4936 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4937 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4938 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4939 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4940 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4941 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4942 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4943 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4944 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4945 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4946 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4947 | DECLARE_INSTRUCTION(Sub); |
| 4948 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4949 | protected: |
| 4950 | DEFAULT_COPY_CONSTRUCTOR(Sub); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4951 | }; |
| 4952 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4953 | class HMul final : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4954 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4955 | HMul(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4956 | HInstruction* left, |
| 4957 | HInstruction* right, |
| 4958 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4959 | : HBinaryOperation(kMul, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4960 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4961 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4962 | bool IsCommutative() const override { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4963 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4964 | 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] | 4965 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4966 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4967 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4968 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4969 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4970 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4971 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4972 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4973 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4974 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4975 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4976 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4977 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4978 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4979 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4980 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4981 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4982 | |
| 4983 | DECLARE_INSTRUCTION(Mul); |
| 4984 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4985 | protected: |
| 4986 | DEFAULT_COPY_CONSTRUCTOR(Mul); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4987 | }; |
| 4988 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4989 | class HDiv final : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4990 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4991 | HDiv(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4992 | HInstruction* left, |
| 4993 | HInstruction* right, |
| 4994 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4995 | : HBinaryOperation(kDiv, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4996 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4997 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4998 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4999 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5000 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5001 | // Our graph structure ensures we never have 0 for `y` during |
| 5002 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5003 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5004 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5005 | return (y == -1) ? -x : x / y; |
| 5006 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5007 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5008 | template <typename T> |
| 5009 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5010 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5011 | return x / y; |
| 5012 | } |
| 5013 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5014 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5015 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5016 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5017 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5018 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5019 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5020 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5021 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5022 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5023 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5024 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5025 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5026 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5027 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5028 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5029 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5030 | |
| 5031 | DECLARE_INSTRUCTION(Div); |
| 5032 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5033 | protected: |
| 5034 | DEFAULT_COPY_CONSTRUCTOR(Div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5035 | }; |
| 5036 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5037 | class HRem final : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5038 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5039 | HRem(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5040 | HInstruction* left, |
| 5041 | HInstruction* right, |
| 5042 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5043 | : HBinaryOperation(kRem, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5044 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5045 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5046 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5047 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5048 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5049 | // Our graph structure ensures we never have 0 for `y` during |
| 5050 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5051 | DCHECK_NE(y, 0); |
| 5052 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 5053 | return (y == -1) ? 0 : x % y; |
| 5054 | } |
| 5055 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5056 | template <typename T> |
| 5057 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5058 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5059 | return std::fmod(x, y); |
| 5060 | } |
| 5061 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5062 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5063 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5064 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5065 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5066 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5067 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5068 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5069 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5070 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5071 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5072 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5073 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5074 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5075 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5076 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5077 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5078 | |
| 5079 | DECLARE_INSTRUCTION(Rem); |
| 5080 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5081 | protected: |
| 5082 | DEFAULT_COPY_CONSTRUCTOR(Rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5083 | }; |
| 5084 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5085 | class HMin final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5086 | public: |
| 5087 | HMin(DataType::Type result_type, |
| 5088 | HInstruction* left, |
| 5089 | HInstruction* right, |
| 5090 | uint32_t dex_pc) |
| 5091 | : HBinaryOperation(kMin, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5092 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5093 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5094 | |
| 5095 | // Evaluation for integral values. |
| 5096 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5097 | return (x <= y) ? x : y; |
| 5098 | } |
| 5099 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5100 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5101 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5102 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5103 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5104 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5105 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5106 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5107 | } |
| 5108 | // TODO: Evaluation for floating-point values. |
| 5109 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5110 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5111 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5112 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5113 | |
| 5114 | DECLARE_INSTRUCTION(Min); |
| 5115 | |
| 5116 | protected: |
| 5117 | DEFAULT_COPY_CONSTRUCTOR(Min); |
| 5118 | }; |
| 5119 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5120 | class HMax final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5121 | public: |
| 5122 | HMax(DataType::Type result_type, |
| 5123 | HInstruction* left, |
| 5124 | HInstruction* right, |
| 5125 | uint32_t dex_pc) |
| 5126 | : HBinaryOperation(kMax, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5127 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5128 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5129 | |
| 5130 | // Evaluation for integral values. |
| 5131 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5132 | return (x >= y) ? x : y; |
| 5133 | } |
| 5134 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5135 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5136 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5137 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5138 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5139 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5140 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5141 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5142 | } |
| 5143 | // TODO: Evaluation for floating-point values. |
| 5144 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5145 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5146 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5147 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5148 | |
| 5149 | DECLARE_INSTRUCTION(Max); |
| 5150 | |
| 5151 | protected: |
| 5152 | DEFAULT_COPY_CONSTRUCTOR(Max); |
| 5153 | }; |
| 5154 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5155 | class HAbs final : public HUnaryOperation { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5156 | public: |
| 5157 | HAbs(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5158 | : HUnaryOperation(kAbs, result_type, input, dex_pc) {} |
| 5159 | |
| 5160 | // Evaluation for integral values. |
| 5161 | template <typename T> static T ComputeIntegral(T x) { |
| 5162 | return x < 0 ? -x : x; |
| 5163 | } |
| 5164 | |
| 5165 | // Evaluation for floating-point values. |
| 5166 | // Note, as a "quality of implementation", rather than pure "spec compliance", |
| 5167 | // we require that Math.abs() clears the sign bit (but changes nothing else) |
| 5168 | // for all floating-point numbers, including NaN (signaling NaN may become quiet though). |
| 5169 | // http://b/30758343 |
| 5170 | template <typename T, typename S> static T ComputeFP(T x) { |
| 5171 | S bits = bit_cast<S, T>(x); |
| 5172 | return bit_cast<T, S>(bits & std::numeric_limits<S>::max()); |
| 5173 | } |
| 5174 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5175 | HConstant* Evaluate(HIntConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5176 | return GetBlock()->GetGraph()->GetIntConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5177 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5178 | HConstant* Evaluate(HLongConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5179 | return GetBlock()->GetGraph()->GetLongConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5180 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5181 | HConstant* Evaluate(HFloatConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5182 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5183 | ComputeFP<float, int32_t>(x->GetValue()), GetDexPc()); |
| 5184 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5185 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5186 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5187 | ComputeFP<double, int64_t>(x->GetValue()), GetDexPc()); |
| 5188 | } |
| 5189 | |
| 5190 | DECLARE_INSTRUCTION(Abs); |
| 5191 | |
| 5192 | protected: |
| 5193 | DEFAULT_COPY_CONSTRUCTOR(Abs); |
| 5194 | }; |
| 5195 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5196 | class HDivZeroCheck final : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5197 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 5198 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5199 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5200 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5201 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5202 | : HExpression(kDivZeroCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5203 | SetRawInputAt(0, value); |
| 5204 | } |
| 5205 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5206 | bool IsClonable() const override { return true; } |
| 5207 | bool CanBeMoved() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5208 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5209 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5210 | return true; |
| 5211 | } |
| 5212 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5213 | bool NeedsEnvironment() const override { return true; } |
| 5214 | bool CanThrow() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5215 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5216 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 5217 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5218 | protected: |
| 5219 | DEFAULT_COPY_CONSTRUCTOR(DivZeroCheck); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5220 | }; |
| 5221 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5222 | class HShl final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5223 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5224 | HShl(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5225 | HInstruction* value, |
| 5226 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5227 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5228 | : HBinaryOperation(kShl, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5229 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5230 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5231 | } |
| 5232 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5233 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5234 | 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] | 5235 | return value << (distance & max_shift_distance); |
| 5236 | } |
| 5237 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5238 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5239 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5240 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5241 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5242 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5243 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5244 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5245 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5246 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5247 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5248 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5249 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5250 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5251 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5252 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5253 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5254 | UNREACHABLE(); |
| 5255 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5256 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5257 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5258 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5259 | UNREACHABLE(); |
| 5260 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5261 | |
| 5262 | DECLARE_INSTRUCTION(Shl); |
| 5263 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5264 | protected: |
| 5265 | DEFAULT_COPY_CONSTRUCTOR(Shl); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5266 | }; |
| 5267 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5268 | class HShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5269 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5270 | HShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5271 | HInstruction* value, |
| 5272 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5273 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5274 | : HBinaryOperation(kShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5275 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5276 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5277 | } |
| 5278 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5279 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5280 | 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] | 5281 | return value >> (distance & max_shift_distance); |
| 5282 | } |
| 5283 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5284 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5285 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5286 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5287 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5288 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5289 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5290 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5291 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5292 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5293 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5294 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5295 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5296 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5297 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5298 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5299 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5300 | UNREACHABLE(); |
| 5301 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5302 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5303 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5304 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5305 | UNREACHABLE(); |
| 5306 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5307 | |
| 5308 | DECLARE_INSTRUCTION(Shr); |
| 5309 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5310 | protected: |
| 5311 | DEFAULT_COPY_CONSTRUCTOR(Shr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5312 | }; |
| 5313 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5314 | class HUShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5315 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5316 | HUShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5317 | HInstruction* value, |
| 5318 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5319 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5320 | : HBinaryOperation(kUShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5321 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5322 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5323 | } |
| 5324 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5325 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5326 | 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] | 5327 | typedef typename std::make_unsigned<T>::type V; |
| 5328 | V ux = static_cast<V>(value); |
| 5329 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 5330 | } |
| 5331 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5332 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5333 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5334 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5335 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5336 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5337 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5338 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5339 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5340 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5341 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5342 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5343 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5344 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5345 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5346 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5347 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5348 | UNREACHABLE(); |
| 5349 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5350 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5351 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5352 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5353 | UNREACHABLE(); |
| 5354 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5355 | |
| 5356 | DECLARE_INSTRUCTION(UShr); |
| 5357 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5358 | protected: |
| 5359 | DEFAULT_COPY_CONSTRUCTOR(UShr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5360 | }; |
| 5361 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5362 | class HAnd final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5363 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5364 | HAnd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5365 | HInstruction* left, |
| 5366 | HInstruction* right, |
| 5367 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5368 | : HBinaryOperation(kAnd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5369 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5370 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5371 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5372 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5373 | 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] | 5374 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5375 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5376 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5377 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5378 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5379 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5380 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5381 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5382 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5383 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5384 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5385 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5386 | UNREACHABLE(); |
| 5387 | } |
| 5388 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5389 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5390 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5391 | UNREACHABLE(); |
| 5392 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5393 | |
| 5394 | DECLARE_INSTRUCTION(And); |
| 5395 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5396 | protected: |
| 5397 | DEFAULT_COPY_CONSTRUCTOR(And); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5398 | }; |
| 5399 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5400 | class HOr final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5401 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5402 | HOr(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5403 | HInstruction* left, |
| 5404 | HInstruction* right, |
| 5405 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5406 | : HBinaryOperation(kOr, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5407 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5408 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5409 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5410 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5411 | 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] | 5412 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5413 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5414 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5415 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5416 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5417 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5418 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5419 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5420 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5421 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5422 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5423 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5424 | UNREACHABLE(); |
| 5425 | } |
| 5426 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5427 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5428 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5429 | UNREACHABLE(); |
| 5430 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5431 | |
| 5432 | DECLARE_INSTRUCTION(Or); |
| 5433 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5434 | protected: |
| 5435 | DEFAULT_COPY_CONSTRUCTOR(Or); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5436 | }; |
| 5437 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5438 | class HXor final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5439 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5440 | HXor(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5441 | HInstruction* left, |
| 5442 | HInstruction* right, |
| 5443 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5444 | : HBinaryOperation(kXor, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5445 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5446 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5447 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5448 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5449 | 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] | 5450 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5451 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5452 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5453 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5454 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5455 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5456 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5457 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5458 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5459 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5460 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5461 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5462 | UNREACHABLE(); |
| 5463 | } |
| 5464 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5465 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5466 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5467 | UNREACHABLE(); |
| 5468 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5469 | |
| 5470 | DECLARE_INSTRUCTION(Xor); |
| 5471 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5472 | protected: |
| 5473 | DEFAULT_COPY_CONSTRUCTOR(Xor); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5474 | }; |
| 5475 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5476 | class HRor final : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5477 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5478 | HRor(DataType::Type result_type, HInstruction* value, HInstruction* distance) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5479 | : HBinaryOperation(kRor, result_type, value, distance) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5480 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5481 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5482 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5483 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5484 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5485 | 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] | 5486 | typedef typename std::make_unsigned<T>::type V; |
| 5487 | V ux = static_cast<V>(value); |
| 5488 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5489 | return static_cast<T>(ux); |
| 5490 | } else { |
| 5491 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5492 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 5493 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5494 | } |
| 5495 | } |
| 5496 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5497 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5498 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5499 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5500 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5501 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5502 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5503 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5504 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5505 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5506 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5507 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5508 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5509 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5510 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5511 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5512 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5513 | UNREACHABLE(); |
| 5514 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5515 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5516 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5517 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5518 | UNREACHABLE(); |
| 5519 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5520 | |
| 5521 | DECLARE_INSTRUCTION(Ror); |
| 5522 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5523 | protected: |
| 5524 | DEFAULT_COPY_CONSTRUCTOR(Ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5525 | }; |
| 5526 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5527 | // The value of a parameter in this method. Its location depends on |
| 5528 | // the calling convention. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5529 | class HParameterValue final : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5530 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5531 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5532 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5533 | uint8_t index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5534 | DataType::Type parameter_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5535 | bool is_this = false) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5536 | : HExpression(kParameterValue, parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5537 | dex_file_(dex_file), |
| 5538 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5539 | index_(index) { |
| 5540 | SetPackedFlag<kFlagIsThis>(is_this); |
| 5541 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 5542 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5543 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5544 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5545 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5546 | uint8_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5547 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5548 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5549 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5550 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5551 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5552 | DECLARE_INSTRUCTION(ParameterValue); |
| 5553 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5554 | protected: |
| 5555 | DEFAULT_COPY_CONSTRUCTOR(ParameterValue); |
| 5556 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5557 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5558 | // Whether or not the parameter value corresponds to 'this' argument. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5559 | static constexpr size_t kFlagIsThis = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5560 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 5561 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 5562 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 5563 | "Too many packed fields."); |
| 5564 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5565 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5566 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5567 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5568 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5569 | const uint8_t index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5570 | }; |
| 5571 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5572 | class HNot final : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5573 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5574 | HNot(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5575 | : HUnaryOperation(kNot, result_type, input, dex_pc) { |
| 5576 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5577 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5578 | bool CanBeMoved() const override { return true; } |
| 5579 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5580 | return true; |
| 5581 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5582 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5583 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5584 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5585 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5586 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5587 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5588 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5589 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5590 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5591 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5592 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5593 | UNREACHABLE(); |
| 5594 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5595 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5596 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5597 | UNREACHABLE(); |
| 5598 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5599 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5600 | DECLARE_INSTRUCTION(Not); |
| 5601 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5602 | protected: |
| 5603 | DEFAULT_COPY_CONSTRUCTOR(Not); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5604 | }; |
| 5605 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5606 | class HBooleanNot final : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5607 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5608 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5609 | : HUnaryOperation(kBooleanNot, DataType::Type::kBool, input, dex_pc) { |
| 5610 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5611 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5612 | bool CanBeMoved() const override { return true; } |
| 5613 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5614 | return true; |
| 5615 | } |
| 5616 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5617 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5618 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5619 | return !x; |
| 5620 | } |
| 5621 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5622 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5623 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5624 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5625 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5626 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5627 | UNREACHABLE(); |
| 5628 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5629 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5630 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5631 | UNREACHABLE(); |
| 5632 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5633 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5634 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5635 | UNREACHABLE(); |
| 5636 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5637 | |
| 5638 | DECLARE_INSTRUCTION(BooleanNot); |
| 5639 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5640 | protected: |
| 5641 | DEFAULT_COPY_CONSTRUCTOR(BooleanNot); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5642 | }; |
| 5643 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5644 | class HTypeConversion final : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5645 | public: |
| 5646 | // Instantiate a type conversion of `input` to `result_type`. |
Vladimir Marko | c8fb211 | 2017-10-03 11:37:52 +0100 | [diff] [blame] | 5647 | HTypeConversion(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5648 | : HExpression(kTypeConversion, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5649 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5650 | // Invariant: We should never generate a conversion to a Boolean value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5651 | DCHECK_NE(DataType::Type::kBool, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5655 | DataType::Type GetInputType() const { return GetInput()->GetType(); } |
| 5656 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5657 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5658 | bool IsClonable() const override { return true; } |
| 5659 | bool CanBeMoved() const override { return true; } |
| 5660 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5661 | return true; |
| 5662 | } |
Nicolas Geoffray | acc56ac | 2018-10-09 08:45:24 +0100 | [diff] [blame] | 5663 | // Return whether the conversion is implicit. This includes conversion to the same type. |
| 5664 | bool IsImplicitConversion() const { |
| 5665 | return DataType::IsTypeConversionImplicit(GetInputType(), GetResultType()); |
| 5666 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5667 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5668 | // Try to statically evaluate the conversion and return a HConstant |
| 5669 | // containing the result. If the input cannot be converted, return nullptr. |
| 5670 | HConstant* TryStaticEvaluation() const; |
| 5671 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5672 | DECLARE_INSTRUCTION(TypeConversion); |
| 5673 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5674 | protected: |
| 5675 | DEFAULT_COPY_CONSTRUCTOR(TypeConversion); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5676 | }; |
| 5677 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5678 | static constexpr uint32_t kNoRegNumber = -1; |
| 5679 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5680 | class HNullCheck final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5681 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5682 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5683 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5684 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5685 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5686 | : HExpression(kNullCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5687 | SetRawInputAt(0, value); |
| 5688 | } |
| 5689 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5690 | bool IsClonable() const override { return true; } |
| 5691 | bool CanBeMoved() const override { return true; } |
| 5692 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5693 | return true; |
| 5694 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5695 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5696 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5697 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5698 | bool CanThrow() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5699 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5700 | bool CanBeNull() const override { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5701 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5702 | DECLARE_INSTRUCTION(NullCheck); |
| 5703 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5704 | protected: |
| 5705 | DEFAULT_COPY_CONSTRUCTOR(NullCheck); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5706 | }; |
| 5707 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5708 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5709 | // that information to avoid requiring the mutator lock every time we need it. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5710 | class FieldInfo : public ValueObject { |
| 5711 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5712 | FieldInfo(ArtField* field, |
| 5713 | MemberOffset field_offset, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5714 | DataType::Type field_type, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5715 | bool is_volatile, |
| 5716 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5717 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5718 | const DexFile& dex_file) |
| 5719 | : field_(field), |
| 5720 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5721 | field_type_(field_type), |
| 5722 | is_volatile_(is_volatile), |
| 5723 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5724 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5725 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5726 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5727 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5728 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5729 | DataType::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5730 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5731 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5732 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5733 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5734 | |
| 5735 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5736 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5737 | const MemberOffset field_offset_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5738 | const DataType::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5739 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5740 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5741 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5742 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5743 | }; |
| 5744 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5745 | class HInstanceFieldGet final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5746 | public: |
| 5747 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5748 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5749 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5750 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5751 | bool is_volatile, |
| 5752 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5753 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5754 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5755 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5756 | : HExpression(kInstanceFieldGet, |
| 5757 | field_type, |
| 5758 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5759 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5760 | field_info_(field, |
| 5761 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5762 | field_type, |
| 5763 | is_volatile, |
| 5764 | field_idx, |
| 5765 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5766 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5767 | SetRawInputAt(0, value); |
| 5768 | } |
| 5769 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5770 | bool IsClonable() const override { return true; } |
| 5771 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5772 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5773 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5774 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5775 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5776 | } |
| 5777 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5778 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5779 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5780 | } |
| 5781 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5782 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5783 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5784 | } |
| 5785 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5786 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5787 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5788 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5789 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5790 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5791 | void SetType(DataType::Type new_type) { |
| 5792 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5793 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5794 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5795 | SetPackedField<TypeField>(new_type); |
| 5796 | } |
| 5797 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5798 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5799 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5800 | protected: |
| 5801 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldGet); |
| 5802 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5803 | private: |
| 5804 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5805 | }; |
| 5806 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5807 | class HInstanceFieldSet final : public HExpression<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5808 | public: |
| 5809 | HInstanceFieldSet(HInstruction* object, |
| 5810 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5811 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5812 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5813 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5814 | bool is_volatile, |
| 5815 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5816 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5817 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5818 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5819 | : HExpression(kInstanceFieldSet, |
| 5820 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5821 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5822 | field_info_(field, |
| 5823 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5824 | field_type, |
| 5825 | is_volatile, |
| 5826 | field_idx, |
| 5827 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5828 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5829 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5830 | SetRawInputAt(0, object); |
| 5831 | SetRawInputAt(1, value); |
| 5832 | } |
| 5833 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5834 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5835 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5836 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5837 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5838 | } |
| 5839 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5840 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5841 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5842 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5843 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5844 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5845 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5846 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5847 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5848 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5849 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5850 | protected: |
| 5851 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldSet); |
| 5852 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5853 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5854 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5855 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5856 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5857 | "Too many packed fields."); |
| 5858 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5859 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5860 | }; |
| 5861 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5862 | class HArrayGet final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5863 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5864 | HArrayGet(HInstruction* array, |
| 5865 | HInstruction* index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5866 | DataType::Type type, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5867 | uint32_t dex_pc) |
| 5868 | : HArrayGet(array, |
| 5869 | index, |
| 5870 | type, |
| 5871 | SideEffects::ArrayReadOfType(type), |
| 5872 | dex_pc, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5873 | /* is_string_char_at */ false) { |
| 5874 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5875 | |
| 5876 | HArrayGet(HInstruction* array, |
| 5877 | HInstruction* index, |
| 5878 | DataType::Type type, |
| 5879 | SideEffects side_effects, |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5880 | uint32_t dex_pc, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5881 | bool is_string_char_at) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5882 | : HExpression(kArrayGet, type, side_effects, dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5883 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5884 | SetRawInputAt(0, array); |
| 5885 | SetRawInputAt(1, index); |
| 5886 | } |
| 5887 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5888 | bool IsClonable() const override { return true; } |
| 5889 | bool CanBeMoved() const override { return true; } |
| 5890 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5891 | return true; |
| 5892 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5893 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5894 | // TODO: We can be smarter here. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5895 | // Currently, unless the array is the result of NewArray, the array access is always |
| 5896 | // preceded by some form of null NullCheck necessary for the bounds check, usually |
| 5897 | // implicit null check on the ArrayLength input to BoundsCheck or Deoptimize for |
| 5898 | // dynamic BCE. There are cases when these could be removed to produce better code. |
| 5899 | // If we ever add optimizations to do so we should allow an implicit check here |
| 5900 | // (as long as the address falls in the first page). |
| 5901 | // |
| 5902 | // As an example of such fancy optimization, we could eliminate BoundsCheck for |
| 5903 | // a = cond ? new int[1] : null; |
| 5904 | // a[0]; // The Phi does not need bounds check for either input. |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5905 | return false; |
| 5906 | } |
| 5907 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5908 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5909 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5910 | if (kIsDebugBuild && result) { |
| 5911 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5912 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5913 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5914 | if (DataType::IsIntOrLongType(GetType())) { |
| 5915 | DCHECK(DataType::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5916 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5917 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| 5918 | DCHECK(DataType::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5919 | } |
| 5920 | } |
| 5921 | return result; |
| 5922 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5923 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5924 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5925 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5926 | HInstruction* GetArray() const { return InputAt(0); } |
| 5927 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5928 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5929 | void SetType(DataType::Type new_type) { |
| 5930 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5931 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5932 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5933 | SetPackedField<TypeField>(new_type); |
| 5934 | } |
| 5935 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5936 | DECLARE_INSTRUCTION(ArrayGet); |
| 5937 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5938 | protected: |
| 5939 | DEFAULT_COPY_CONSTRUCTOR(ArrayGet); |
| 5940 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5941 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5942 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5943 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5944 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5945 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5946 | // a flag, so that code generators don't need to do the locking. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5947 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5948 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5949 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5950 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5951 | }; |
| 5952 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5953 | class HArraySet final : public HExpression<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5954 | public: |
| 5955 | HArraySet(HInstruction* array, |
| 5956 | HInstruction* index, |
| 5957 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5958 | DataType::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5959 | uint32_t dex_pc) |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5960 | : HArraySet(array, |
| 5961 | index, |
| 5962 | value, |
| 5963 | expected_component_type, |
| 5964 | // Make a best guess for side effects now, may be refined during SSA building. |
| 5965 | ComputeSideEffects(GetComponentType(value->GetType(), expected_component_type)), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5966 | dex_pc) { |
| 5967 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5968 | |
| 5969 | HArraySet(HInstruction* array, |
| 5970 | HInstruction* index, |
| 5971 | HInstruction* value, |
| 5972 | DataType::Type expected_component_type, |
| 5973 | SideEffects side_effects, |
| 5974 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5975 | : HExpression(kArraySet, side_effects, dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5976 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5977 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5978 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5979 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5980 | SetRawInputAt(0, array); |
| 5981 | SetRawInputAt(1, index); |
| 5982 | SetRawInputAt(2, value); |
| 5983 | } |
| 5984 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5985 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5986 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5987 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5988 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5989 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5990 | } |
| 5991 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5992 | // Can throw ArrayStoreException. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5993 | bool CanThrow() const override { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5994 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5995 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5996 | // TODO: Same as for ArrayGet. |
| 5997 | return false; |
| 5998 | } |
| 5999 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6000 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6001 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6002 | } |
| 6003 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6004 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6005 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6006 | } |
| 6007 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6008 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6009 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6010 | } |
| 6011 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6012 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6013 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 6014 | bool StaticTypeOfArrayIsObjectArray() const { |
| 6015 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 6016 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6017 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6018 | HInstruction* GetArray() const { return InputAt(0); } |
| 6019 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6020 | HInstruction* GetValue() const { return InputAt(2); } |
| 6021 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6022 | DataType::Type GetComponentType() const { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6023 | return GetComponentType(GetValue()->GetType(), GetRawExpectedComponentType()); |
| 6024 | } |
| 6025 | |
| 6026 | static DataType::Type GetComponentType(DataType::Type value_type, |
| 6027 | DataType::Type expected_component_type) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6028 | // The Dex format does not type floating point index operations. Since the |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6029 | // `expected_component_type` comes from SSA building and can therefore not |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6030 | // be correct, we also check what is the value type. If it is a floating |
| 6031 | // point type, we must use that type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6032 | return ((value_type == DataType::Type::kFloat32) || (value_type == DataType::Type::kFloat64)) |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6033 | ? value_type |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6034 | : expected_component_type; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6035 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6036 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6037 | DataType::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6038 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6039 | } |
| 6040 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6041 | static SideEffects ComputeSideEffects(DataType::Type type) { |
| 6042 | return SideEffects::ArrayWriteOfType(type).Union(SideEffectsForArchRuntimeCalls(type)); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 6043 | } |
| 6044 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6045 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type value_type) { |
| 6046 | return (value_type == DataType::Type::kReference) ? SideEffects::CanTriggerGC() |
| 6047 | : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6048 | } |
| 6049 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6050 | DECLARE_INSTRUCTION(ArraySet); |
| 6051 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6052 | protected: |
| 6053 | DEFAULT_COPY_CONSTRUCTOR(ArraySet); |
| 6054 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6055 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6056 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 6057 | static constexpr size_t kFieldExpectedComponentTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6058 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6059 | static constexpr size_t kFlagNeedsTypeCheck = |
| 6060 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 6061 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6062 | // Cached information for the reference_type_info_ so that codegen |
| 6063 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6064 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 6065 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 6066 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 6067 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6068 | using ExpectedComponentTypeField = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6069 | BitField<DataType::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6070 | }; |
| 6071 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6072 | class HArrayLength final : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6073 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6074 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6075 | : HExpression(kArrayLength, DataType::Type::kInt32, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6076 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6077 | // Note that arrays do not change length, so the instruction does not |
| 6078 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6079 | SetRawInputAt(0, array); |
| 6080 | } |
| 6081 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6082 | bool IsClonable() const override { return true; } |
| 6083 | bool CanBeMoved() const override { return true; } |
| 6084 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6085 | return true; |
| 6086 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6087 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 6088 | return obj == InputAt(0); |
| 6089 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6090 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6091 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 6092 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6093 | DECLARE_INSTRUCTION(ArrayLength); |
| 6094 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6095 | protected: |
| 6096 | DEFAULT_COPY_CONSTRUCTOR(ArrayLength); |
| 6097 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6098 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6099 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 6100 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 6101 | // determine whether a particular HArrayLength is actually a String.length() by |
| 6102 | // looking at the type of the input but that requires holding the mutator lock, so |
| 6103 | // we prefer to use a flag, so that code generators don't need to do the locking. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6104 | static constexpr size_t kFlagIsStringLength = kNumberOfGenericPackedBits; |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6105 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 6106 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6107 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6108 | }; |
| 6109 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6110 | class HBoundsCheck final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6111 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 6112 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6113 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 6114 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6115 | HBoundsCheck(HInstruction* index, |
| 6116 | HInstruction* length, |
| 6117 | uint32_t dex_pc, |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6118 | bool is_string_char_at = false) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6119 | : HExpression(kBoundsCheck, index->GetType(), SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6120 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(index->GetType())); |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6121 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6122 | SetRawInputAt(0, index); |
| 6123 | SetRawInputAt(1, length); |
| 6124 | } |
| 6125 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6126 | bool IsClonable() const override { return true; } |
| 6127 | bool CanBeMoved() const override { return true; } |
| 6128 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6129 | return true; |
| 6130 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6131 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6132 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6133 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6134 | bool CanThrow() const override { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 6135 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 6136 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6137 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6138 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6139 | |
| 6140 | DECLARE_INSTRUCTION(BoundsCheck); |
| 6141 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6142 | protected: |
| 6143 | DEFAULT_COPY_CONSTRUCTOR(BoundsCheck); |
| 6144 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6145 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6146 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | f02046e | 2018-10-02 15:31:32 +0100 | [diff] [blame] | 6147 | static constexpr size_t kNumberOfBoundsCheckPackedBits = kFlagIsStringCharAt + 1; |
| 6148 | static_assert(kNumberOfBoundsCheckPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6149 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6150 | }; |
| 6151 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6152 | class HSuspendCheck final : public HExpression<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6153 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 6154 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6155 | : HExpression(kSuspendCheck, SideEffects::CanTriggerGC(), dex_pc), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6156 | slow_path_(nullptr) { |
| 6157 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6158 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6159 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6160 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6161 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6162 | return true; |
| 6163 | } |
| 6164 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6165 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 6166 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6167 | |
| 6168 | DECLARE_INSTRUCTION(SuspendCheck); |
| 6169 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6170 | protected: |
| 6171 | DEFAULT_COPY_CONSTRUCTOR(SuspendCheck); |
| 6172 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6173 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6174 | // Only used for code generation, in order to share the same slow path between back edges |
| 6175 | // of a same loop. |
| 6176 | SlowPathCode* slow_path_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6177 | }; |
| 6178 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6179 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 6180 | // It ensures that we can generate line number and local variables at this point. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6181 | class HNativeDebugInfo : public HExpression<0> { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6182 | public: |
| 6183 | explicit HNativeDebugInfo(uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6184 | : HExpression<0>(kNativeDebugInfo, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6185 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6186 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6187 | bool NeedsEnvironment() const override { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6188 | return true; |
| 6189 | } |
| 6190 | |
| 6191 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 6192 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6193 | protected: |
| 6194 | DEFAULT_COPY_CONSTRUCTOR(NativeDebugInfo); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6195 | }; |
| 6196 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6197 | /** |
| 6198 | * Instruction to load a Class object. |
| 6199 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6200 | class HLoadClass final : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6201 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6202 | // Determines how to load the Class. |
| 6203 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6204 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 6205 | kInvalid = -1, |
| 6206 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6207 | // Use the Class* from the method's own ArtMethod*. |
| 6208 | kReferrersClass, |
| 6209 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6210 | // Use PC-relative boot image Class* address that will be known at link time. |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6211 | // Used for boot image classes referenced by boot image code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6212 | kBootImageLinkTimePcRelative, |
| 6213 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6214 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6215 | // Used for boot image classes referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6216 | kBootImageRelRo, |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6217 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6218 | // Load from an entry in the .bss section using a PC-relative load. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6219 | // Used for classes outside boot image referenced by AOT-compiled app and boot image code. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6220 | kBssEntry, |
| 6221 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6222 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 6223 | // Used for boot image classes referenced by apps in JIT-compiled code. |
| 6224 | kJitBootImageAddress, |
| 6225 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6226 | // Load from the root table associated with the JIT compiled method. |
| 6227 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6228 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6229 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6230 | // the codegen is unable to use another appropriate kind. |
| 6231 | kRuntimeCall, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6232 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6233 | kLast = kRuntimeCall |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6234 | }; |
| 6235 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6236 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6237 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6238 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6239 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6240 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6241 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6242 | bool needs_access_check) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6243 | : HInstruction(kLoadClass, |
| 6244 | DataType::Type::kReference, |
| 6245 | SideEffectsForArchRuntimeCalls(), |
| 6246 | dex_pc), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6247 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6248 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6249 | dex_file_(dex_file), |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6250 | klass_(klass) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 6251 | // Referrers class should not need access check. We never inline unverified |
| 6252 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6253 | DCHECK(!is_referrers_class || !needs_access_check); |
| 6254 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6255 | SetPackedField<LoadKindField>( |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6256 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kRuntimeCall); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6257 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6258 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6259 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6260 | SetPackedFlag<kFlagValidLoadedClassRTI>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6261 | } |
| 6262 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6263 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6264 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6265 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6266 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6267 | LoadKind GetLoadKind() const { |
| 6268 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6269 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6270 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6271 | bool HasPcRelativeLoadKind() const { |
| 6272 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6273 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 6274 | GetLoadKind() == LoadKind::kBssEntry; |
| 6275 | } |
| 6276 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6277 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6278 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6279 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6280 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6281 | size_t ComputeHashCode() const override { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6282 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6283 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6284 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6285 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6286 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6287 | } |
| 6288 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 6289 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 6290 | // The entrypoint the code generator is going to call does not do |
| 6291 | // clinit of the class. |
| 6292 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6293 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6294 | } |
| 6295 | |
| 6296 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6297 | return NeedsAccessCheck() || |
| 6298 | MustGenerateClinitCheck() || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6299 | GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6300 | GetLoadKind() == LoadKind::kBssEntry; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6301 | } |
| 6302 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6303 | bool CanThrow() const override { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6304 | return NeedsAccessCheck() || |
| 6305 | MustGenerateClinitCheck() || |
| 6306 | // If the class is in the boot image, the lookup in the runtime call cannot throw. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6307 | ((GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6308 | GetLoadKind() == LoadKind::kBssEntry) && |
| 6309 | !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6310 | } |
| 6311 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6312 | ReferenceTypeInfo GetLoadedClassRTI() { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6313 | if (GetPackedFlag<kFlagValidLoadedClassRTI>()) { |
| 6314 | // Note: The is_exact flag from the return value should not be used. |
| 6315 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact */ true); |
| 6316 | } else { |
| 6317 | return ReferenceTypeInfo::CreateInvalid(); |
| 6318 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6319 | } |
| 6320 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6321 | // Loaded class RTI is marked as valid by RTP if the klass_ is admissible. |
| 6322 | void SetValidLoadedClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 6323 | DCHECK(klass_ != nullptr); |
| 6324 | SetPackedFlag<kFlagValidLoadedClassRTI>(true); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6325 | } |
| 6326 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6327 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6328 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6329 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6330 | bool NeedsDexCacheOfDeclaringClass() const override { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6331 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6332 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 6333 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6334 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6335 | return SideEffects::CanTriggerGC(); |
| 6336 | } |
| 6337 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6338 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6339 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6340 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6341 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6342 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6343 | bool MustResolveTypeOnSlowPath() const { |
| 6344 | // Check that this instruction has a slow path. |
| 6345 | DCHECK(GetLoadKind() != LoadKind::kRuntimeCall); // kRuntimeCall calls on main path. |
| 6346 | DCHECK(GetLoadKind() == LoadKind::kBssEntry || MustGenerateClinitCheck()); |
| 6347 | return GetLoadKind() == LoadKind::kBssEntry; |
| 6348 | } |
| 6349 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6350 | void MarkInBootImage() { |
| 6351 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 6352 | } |
| 6353 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6354 | void AddSpecialInput(HInstruction* special_input); |
| 6355 | |
| 6356 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6357 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6358 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6359 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6360 | } |
| 6361 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6362 | Handle<mirror::Class> GetClass() const { |
| 6363 | return klass_; |
| 6364 | } |
| 6365 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6366 | DECLARE_INSTRUCTION(LoadClass); |
| 6367 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6368 | protected: |
| 6369 | DEFAULT_COPY_CONSTRUCTOR(LoadClass); |
| 6370 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6371 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6372 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6373 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6374 | // Whether this instruction must generate the initialization check. |
| 6375 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6376 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6377 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 6378 | static constexpr size_t kFieldLoadKindSize = |
| 6379 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6380 | static constexpr size_t kFlagValidLoadedClassRTI = kFieldLoadKind + kFieldLoadKindSize; |
| 6381 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagValidLoadedClassRTI + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6382 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6383 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 6384 | |
| 6385 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6386 | return load_kind == LoadKind::kReferrersClass || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6387 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6388 | load_kind == LoadKind::kBssEntry || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6389 | load_kind == LoadKind::kRuntimeCall; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6390 | } |
| 6391 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6392 | void SetLoadKindInternal(LoadKind load_kind); |
| 6393 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6394 | // The special input is the HCurrentMethod for kRuntimeCall or kReferrersClass. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6395 | // For other load kinds it's empty or possibly some architecture-specific instruction |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6396 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6397 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6398 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6399 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 6400 | // - The compiling method's dex file if the class is defined there too. |
| 6401 | // - The compiling method's dex file if the class is referenced there. |
| 6402 | // - The dex file where the class is defined. When the load kind can only be |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6403 | // kBssEntry or kRuntimeCall, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6404 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6405 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6406 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6407 | Handle<mirror::Class> klass_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6408 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6409 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 6410 | |
| 6411 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6412 | inline void HLoadClass::SetLoadKind(LoadKind load_kind) { |
| 6413 | // The load kind should be determined before inserting the instruction to the graph. |
| 6414 | DCHECK(GetBlock() == nullptr); |
| 6415 | DCHECK(GetEnvironment() == nullptr); |
| 6416 | SetPackedField<LoadKindField>(load_kind); |
| 6417 | if (load_kind != LoadKind::kRuntimeCall && load_kind != LoadKind::kReferrersClass) { |
| 6418 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6419 | } |
| 6420 | if (!NeedsEnvironment()) { |
| 6421 | SetSideEffects(SideEffects::None()); |
| 6422 | } |
| 6423 | } |
| 6424 | |
| 6425 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6426 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6427 | // The special input is used for PC-relative loads on some architectures, |
| 6428 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6429 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6430 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6431 | GetLoadKind() == LoadKind::kBssEntry || |
| 6432 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6433 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6434 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 6435 | special_input->AddUseAt(this, 0); |
| 6436 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6437 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6438 | class HLoadString final : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6439 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6440 | // Determines how to load the String. |
| 6441 | enum class LoadKind { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6442 | // Use PC-relative boot image String* address that will be known at link time. |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6443 | // Used for boot image strings referenced by boot image code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6444 | kBootImageLinkTimePcRelative, |
| 6445 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6446 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6447 | // Used for boot image strings referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6448 | kBootImageRelRo, |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6449 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6450 | // Load from an entry in the .bss section using a PC-relative load. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6451 | // Used for strings outside boot image referenced by AOT-compiled app and boot image code. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6452 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6453 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6454 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 6455 | // Used for boot image strings referenced by apps in JIT-compiled code. |
| 6456 | kJitBootImageAddress, |
| 6457 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6458 | // Load from the root table associated with the JIT compiled method. |
| 6459 | kJitTableAddress, |
| 6460 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6461 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6462 | // the codegen is unable to use another appropriate kind. |
| 6463 | kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6464 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6465 | kLast = kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6466 | }; |
| 6467 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6468 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6469 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6470 | const DexFile& dex_file, |
| 6471 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6472 | : HInstruction(kLoadString, |
| 6473 | DataType::Type::kReference, |
| 6474 | SideEffectsForArchRuntimeCalls(), |
| 6475 | dex_pc), |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6476 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6477 | string_index_(string_index), |
| 6478 | dex_file_(dex_file) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6479 | SetPackedField<LoadKindField>(LoadKind::kRuntimeCall); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6480 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6481 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6482 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6483 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6484 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6485 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6486 | LoadKind GetLoadKind() const { |
| 6487 | return GetPackedField<LoadKindField>(); |
| 6488 | } |
| 6489 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6490 | bool HasPcRelativeLoadKind() const { |
| 6491 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6492 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 6493 | GetLoadKind() == LoadKind::kBssEntry; |
| 6494 | } |
| 6495 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6496 | const DexFile& GetDexFile() const { |
| 6497 | return dex_file_; |
| 6498 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6499 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6500 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6501 | return string_index_; |
| 6502 | } |
| 6503 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6504 | Handle<mirror::String> GetString() const { |
| 6505 | return string_; |
| 6506 | } |
| 6507 | |
| 6508 | void SetString(Handle<mirror::String> str) { |
| 6509 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6510 | } |
| 6511 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6512 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6513 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6514 | bool InstructionDataEquals(const HInstruction* other) const override; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6515 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6516 | size_t ComputeHashCode() const override { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6517 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6518 | // Will call the runtime if we need to load the string through |
| 6519 | // the dex cache and the string is not guaranteed to be there yet. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6520 | bool NeedsEnvironment() const override { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6521 | LoadKind load_kind = GetLoadKind(); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6522 | if (load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6523 | load_kind == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6524 | load_kind == LoadKind::kJitBootImageAddress || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6525 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6526 | return false; |
| 6527 | } |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6528 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6529 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6530 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6531 | bool NeedsDexCacheOfDeclaringClass() const override { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6532 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6533 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6534 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6535 | bool CanBeNull() const override { return false; } |
| 6536 | bool CanThrow() const override { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6537 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6538 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6539 | return SideEffects::CanTriggerGC(); |
| 6540 | } |
| 6541 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6542 | void AddSpecialInput(HInstruction* special_input); |
| 6543 | |
| 6544 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6545 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6546 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6547 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6548 | } |
| 6549 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6550 | DECLARE_INSTRUCTION(LoadString); |
| 6551 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6552 | protected: |
| 6553 | DEFAULT_COPY_CONSTRUCTOR(LoadString); |
| 6554 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6555 | private: |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6556 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6557 | static constexpr size_t kFieldLoadKindSize = |
| 6558 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 6559 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6560 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6561 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6562 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6563 | void SetLoadKindInternal(LoadKind load_kind); |
| 6564 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6565 | // The special input is the HCurrentMethod for kRuntimeCall. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6566 | // For other load kinds it's empty or possibly some architecture-specific instruction |
Vladimir Marko | 48886c2 | 2017-01-06 11:45:47 +0000 | [diff] [blame] | 6567 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6568 | HUserRecord<HInstruction*> special_input_; |
| 6569 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6570 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6571 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6572 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6573 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6574 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6575 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 6576 | |
| 6577 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6578 | inline void HLoadString::SetLoadKind(LoadKind load_kind) { |
| 6579 | // The load kind should be determined before inserting the instruction to the graph. |
| 6580 | DCHECK(GetBlock() == nullptr); |
| 6581 | DCHECK(GetEnvironment() == nullptr); |
| 6582 | DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); |
| 6583 | SetPackedField<LoadKindField>(load_kind); |
| 6584 | if (load_kind != LoadKind::kRuntimeCall) { |
| 6585 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6586 | } |
| 6587 | if (!NeedsEnvironment()) { |
| 6588 | SetSideEffects(SideEffects::None()); |
| 6589 | } |
| 6590 | } |
| 6591 | |
| 6592 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6593 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6594 | // The special input is used for PC-relative loads on some architectures, |
| 6595 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6596 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6597 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6598 | GetLoadKind() == LoadKind::kBssEntry || |
| 6599 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6600 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 6601 | // so use the GetInputRecords() from the base class to set the input record. |
| 6602 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6603 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6604 | special_input->AddUseAt(this, 0); |
| 6605 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6606 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6607 | class HLoadMethodHandle final : public HInstruction { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6608 | public: |
| 6609 | HLoadMethodHandle(HCurrentMethod* current_method, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 6610 | uint16_t method_handle_idx, |
| 6611 | const DexFile& dex_file, |
| 6612 | uint32_t dex_pc) |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6613 | : HInstruction(kLoadMethodHandle, |
| 6614 | DataType::Type::kReference, |
| 6615 | SideEffectsForArchRuntimeCalls(), |
| 6616 | dex_pc), |
| 6617 | special_input_(HUserRecord<HInstruction*>(current_method)), |
| 6618 | method_handle_idx_(method_handle_idx), |
| 6619 | dex_file_(dex_file) { |
| 6620 | } |
| 6621 | |
| 6622 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6623 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6624 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6625 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6626 | } |
| 6627 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6628 | bool IsClonable() const override { return true; } |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6629 | |
| 6630 | uint16_t GetMethodHandleIndex() const { return method_handle_idx_; } |
| 6631 | |
| 6632 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6633 | |
| 6634 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6635 | return SideEffects::CanTriggerGC(); |
| 6636 | } |
| 6637 | |
| 6638 | DECLARE_INSTRUCTION(LoadMethodHandle); |
| 6639 | |
| 6640 | protected: |
| 6641 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodHandle); |
| 6642 | |
| 6643 | private: |
| 6644 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6645 | HUserRecord<HInstruction*> special_input_; |
| 6646 | |
| 6647 | const uint16_t method_handle_idx_; |
| 6648 | const DexFile& dex_file_; |
| 6649 | }; |
| 6650 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6651 | class HLoadMethodType final : public HInstruction { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6652 | public: |
| 6653 | HLoadMethodType(HCurrentMethod* current_method, |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6654 | dex::ProtoIndex proto_index, |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6655 | const DexFile& dex_file, |
| 6656 | uint32_t dex_pc) |
| 6657 | : HInstruction(kLoadMethodType, |
| 6658 | DataType::Type::kReference, |
| 6659 | SideEffectsForArchRuntimeCalls(), |
| 6660 | dex_pc), |
| 6661 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6662 | proto_index_(proto_index), |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6663 | dex_file_(dex_file) { |
| 6664 | } |
| 6665 | |
| 6666 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6667 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6668 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6669 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6670 | } |
| 6671 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6672 | bool IsClonable() const override { return true; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6673 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6674 | dex::ProtoIndex GetProtoIndex() const { return proto_index_; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6675 | |
| 6676 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6677 | |
| 6678 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6679 | return SideEffects::CanTriggerGC(); |
| 6680 | } |
| 6681 | |
| 6682 | DECLARE_INSTRUCTION(LoadMethodType); |
| 6683 | |
| 6684 | protected: |
| 6685 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodType); |
| 6686 | |
| 6687 | private: |
| 6688 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6689 | HUserRecord<HInstruction*> special_input_; |
| 6690 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6691 | const dex::ProtoIndex proto_index_; |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6692 | const DexFile& dex_file_; |
| 6693 | }; |
| 6694 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6695 | /** |
| 6696 | * Performs an initialization check on its Class object input. |
| 6697 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6698 | class HClinitCheck final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6699 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 6700 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 6701 | : HExpression( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6702 | kClinitCheck, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6703 | DataType::Type::kReference, |
Mingyao Yang | 217eb06 | 2017-12-11 15:20:07 -0800 | [diff] [blame] | 6704 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6705 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6706 | SetRawInputAt(0, constant); |
| 6707 | } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 6708 | // TODO: Make ClinitCheck clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6709 | bool CanBeMoved() const override { return true; } |
| 6710 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6711 | return true; |
| 6712 | } |
| 6713 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6714 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6715 | // May call runtime to initialize the class. |
| 6716 | return true; |
| 6717 | } |
| 6718 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6719 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6720 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6721 | HLoadClass* GetLoadClass() const { |
| 6722 | DCHECK(InputAt(0)->IsLoadClass()); |
| 6723 | return InputAt(0)->AsLoadClass(); |
| 6724 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6725 | |
| 6726 | DECLARE_INSTRUCTION(ClinitCheck); |
| 6727 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6728 | |
| 6729 | protected: |
| 6730 | DEFAULT_COPY_CONSTRUCTOR(ClinitCheck); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6731 | }; |
| 6732 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6733 | class HStaticFieldGet final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6734 | public: |
| 6735 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6736 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6737 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6738 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6739 | bool is_volatile, |
| 6740 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6741 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6742 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6743 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6744 | : HExpression(kStaticFieldGet, |
| 6745 | field_type, |
| 6746 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 6747 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6748 | field_info_(field, |
| 6749 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6750 | field_type, |
| 6751 | is_volatile, |
| 6752 | field_idx, |
| 6753 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6754 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6755 | SetRawInputAt(0, cls); |
| 6756 | } |
| 6757 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6758 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6759 | bool IsClonable() const override { return true; } |
| 6760 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6761 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6762 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6763 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6764 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6765 | } |
| 6766 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6767 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6768 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6769 | } |
| 6770 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6771 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6772 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6773 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6774 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6775 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6776 | void SetType(DataType::Type new_type) { |
| 6777 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6778 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6779 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6780 | SetPackedField<TypeField>(new_type); |
| 6781 | } |
| 6782 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6783 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 6784 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6785 | protected: |
| 6786 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldGet); |
| 6787 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6788 | private: |
| 6789 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6790 | }; |
| 6791 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6792 | class HStaticFieldSet final : public HExpression<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6793 | public: |
| 6794 | HStaticFieldSet(HInstruction* cls, |
| 6795 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6796 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6797 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6798 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6799 | bool is_volatile, |
| 6800 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6801 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6802 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6803 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6804 | : HExpression(kStaticFieldSet, |
| 6805 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 6806 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6807 | field_info_(field, |
| 6808 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6809 | field_type, |
| 6810 | is_volatile, |
| 6811 | field_idx, |
| 6812 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6813 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6814 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6815 | SetRawInputAt(0, cls); |
| 6816 | SetRawInputAt(1, value); |
| 6817 | } |
| 6818 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6819 | bool IsClonable() const override { return true; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6820 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6821 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6822 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6823 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6824 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6825 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6826 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6827 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6828 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6829 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6830 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6831 | protected: |
| 6832 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldSet); |
| 6833 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6834 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6835 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6836 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6837 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6838 | "Too many packed fields."); |
| 6839 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6840 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6841 | }; |
| 6842 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6843 | class HUnresolvedInstanceFieldGet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6844 | public: |
| 6845 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6846 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6847 | uint32_t field_index, |
| 6848 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6849 | : HExpression(kUnresolvedInstanceFieldGet, |
| 6850 | field_type, |
| 6851 | SideEffects::AllExceptGCDependency(), |
| 6852 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6853 | field_index_(field_index) { |
| 6854 | SetRawInputAt(0, obj); |
| 6855 | } |
| 6856 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6857 | bool IsClonable() const override { return true; } |
| 6858 | bool NeedsEnvironment() const override { return true; } |
| 6859 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6860 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6861 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6862 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6863 | |
| 6864 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6865 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6866 | protected: |
| 6867 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldGet); |
| 6868 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6869 | private: |
| 6870 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6871 | }; |
| 6872 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6873 | class HUnresolvedInstanceFieldSet final : public HExpression<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6874 | public: |
| 6875 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6876 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6877 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6878 | uint32_t field_index, |
| 6879 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6880 | : HExpression(kUnresolvedInstanceFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6881 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6882 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6883 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6884 | SetRawInputAt(0, obj); |
| 6885 | SetRawInputAt(1, value); |
| 6886 | } |
| 6887 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6888 | bool IsClonable() const override { return true; } |
| 6889 | bool NeedsEnvironment() const override { return true; } |
| 6890 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6891 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6892 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6893 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6894 | |
| 6895 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6896 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6897 | protected: |
| 6898 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldSet); |
| 6899 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6900 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6901 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6902 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6903 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6904 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6905 | kFieldFieldType + kFieldFieldTypeSize; |
| 6906 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6907 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6908 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6909 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6910 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6911 | }; |
| 6912 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6913 | class HUnresolvedStaticFieldGet final : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6914 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6915 | HUnresolvedStaticFieldGet(DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6916 | uint32_t field_index, |
| 6917 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6918 | : HExpression(kUnresolvedStaticFieldGet, |
| 6919 | field_type, |
| 6920 | SideEffects::AllExceptGCDependency(), |
| 6921 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6922 | field_index_(field_index) { |
| 6923 | } |
| 6924 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6925 | bool IsClonable() const override { return true; } |
| 6926 | bool NeedsEnvironment() const override { return true; } |
| 6927 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6928 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6929 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6930 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6931 | |
| 6932 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6933 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6934 | protected: |
| 6935 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldGet); |
| 6936 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6937 | private: |
| 6938 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6939 | }; |
| 6940 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6941 | class HUnresolvedStaticFieldSet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6942 | public: |
| 6943 | HUnresolvedStaticFieldSet(HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6944 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6945 | uint32_t field_index, |
| 6946 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6947 | : HExpression(kUnresolvedStaticFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6948 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6949 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6950 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6951 | SetRawInputAt(0, value); |
| 6952 | } |
| 6953 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6954 | bool IsClonable() const override { return true; } |
| 6955 | bool NeedsEnvironment() const override { return true; } |
| 6956 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6957 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6958 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6959 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6960 | |
| 6961 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6962 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6963 | protected: |
| 6964 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldSet); |
| 6965 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6966 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6967 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6968 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6969 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6970 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6971 | kFieldFieldType + kFieldFieldTypeSize; |
| 6972 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6973 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6974 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6975 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6976 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6977 | }; |
| 6978 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6979 | // Implement the move-exception DEX instruction. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6980 | class HLoadException final : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6981 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6982 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6983 | : HExpression(kLoadException, DataType::Type::kReference, SideEffects::None(), dex_pc) { |
| 6984 | } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6985 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6986 | bool CanBeNull() const override { return false; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6987 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6988 | DECLARE_INSTRUCTION(LoadException); |
| 6989 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6990 | protected: |
| 6991 | DEFAULT_COPY_CONSTRUCTOR(LoadException); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6992 | }; |
| 6993 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6994 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6995 | // Must not be removed because the runtime expects the TLS to get cleared. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6996 | class HClearException final : public HExpression<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6997 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6998 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6999 | : HExpression(kClearException, SideEffects::AllWrites(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7000 | } |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7001 | |
| 7002 | DECLARE_INSTRUCTION(ClearException); |
| 7003 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7004 | protected: |
| 7005 | DEFAULT_COPY_CONSTRUCTOR(ClearException); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7006 | }; |
| 7007 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7008 | class HThrow final : public HExpression<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7009 | public: |
| 7010 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7011 | : HExpression(kThrow, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7012 | SetRawInputAt(0, exception); |
| 7013 | } |
| 7014 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7015 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7016 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7017 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7018 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7019 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7020 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7021 | bool AlwaysThrows() const override { return true; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 7022 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7023 | DECLARE_INSTRUCTION(Throw); |
| 7024 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7025 | protected: |
| 7026 | DEFAULT_COPY_CONSTRUCTOR(Throw); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7027 | }; |
| 7028 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7029 | /** |
| 7030 | * Implementation strategies for the code generator of a HInstanceOf |
| 7031 | * or `HCheckCast`. |
| 7032 | */ |
| 7033 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7034 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7035 | kExactCheck, // Can do a single class compare. |
| 7036 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 7037 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 7038 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 7039 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7040 | kArrayCheck, // No optimization yet when checking against a generic array. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7041 | kBitstringCheck, // Compare the type check bitstring. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7042 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7043 | }; |
| 7044 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 7045 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 7046 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7047 | // Note: HTypeCheckInstruction is just a helper class, not an abstract instruction with an |
| 7048 | // `IsTypeCheckInstruction()`. (New virtual methods in the HInstruction class have a high cost.) |
| 7049 | class HTypeCheckInstruction : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7050 | public: |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7051 | HTypeCheckInstruction(InstructionKind kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7052 | DataType::Type type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7053 | HInstruction* object, |
| 7054 | HInstruction* target_class_or_null, |
| 7055 | TypeCheckKind check_kind, |
| 7056 | Handle<mirror::Class> klass, |
| 7057 | uint32_t dex_pc, |
| 7058 | ArenaAllocator* allocator, |
| 7059 | HIntConstant* bitstring_path_to_root, |
| 7060 | HIntConstant* bitstring_mask, |
| 7061 | SideEffects side_effects) |
| 7062 | : HVariableInputSizeInstruction( |
| 7063 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7064 | type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7065 | side_effects, |
| 7066 | dex_pc, |
| 7067 | allocator, |
| 7068 | /* number_of_inputs */ check_kind == TypeCheckKind::kBitstringCheck ? 4u : 2u, |
| 7069 | kArenaAllocTypeCheckInputs), |
| 7070 | klass_(klass) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7071 | SetPackedField<TypeCheckKindField>(check_kind); |
| 7072 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7073 | SetPackedFlag<kFlagValidTargetClassRTI>(false); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7074 | SetRawInputAt(0, object); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7075 | SetRawInputAt(1, target_class_or_null); |
| 7076 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_path_to_root != nullptr); |
| 7077 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_mask != nullptr); |
| 7078 | if (check_kind == TypeCheckKind::kBitstringCheck) { |
| 7079 | DCHECK(target_class_or_null->IsNullConstant()); |
| 7080 | SetRawInputAt(2, bitstring_path_to_root); |
| 7081 | SetRawInputAt(3, bitstring_mask); |
| 7082 | } else { |
| 7083 | DCHECK(target_class_or_null->IsLoadClass()); |
| 7084 | } |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7085 | } |
| 7086 | |
| 7087 | HLoadClass* GetTargetClass() const { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7088 | DCHECK_NE(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7089 | HInstruction* load_class = InputAt(1); |
| 7090 | DCHECK(load_class->IsLoadClass()); |
| 7091 | return load_class->AsLoadClass(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7092 | } |
| 7093 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7094 | uint32_t GetBitstringPathToRoot() const { |
| 7095 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7096 | HInstruction* path_to_root = InputAt(2); |
| 7097 | DCHECK(path_to_root->IsIntConstant()); |
| 7098 | return static_cast<uint32_t>(path_to_root->AsIntConstant()->GetValue()); |
| 7099 | } |
| 7100 | |
| 7101 | uint32_t GetBitstringMask() const { |
| 7102 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7103 | HInstruction* mask = InputAt(3); |
| 7104 | DCHECK(mask->IsIntConstant()); |
| 7105 | return static_cast<uint32_t>(mask->AsIntConstant()->GetValue()); |
| 7106 | } |
| 7107 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7108 | bool IsClonable() const override { return true; } |
| 7109 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7110 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7111 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7112 | DCHECK(other->IsInstanceOf() || other->IsCheckCast()) << other->DebugName(); |
| 7113 | return GetPackedFields() == down_cast<const HTypeCheckInstruction*>(other)->GetPackedFields(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7114 | } |
| 7115 | |
Andreas Gampe | 3fbd3ad | 2018-03-26 21:14:46 +0000 | [diff] [blame] | 7116 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 7117 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 7118 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 7119 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
| 7120 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7121 | ReferenceTypeInfo GetTargetClassRTI() { |
| 7122 | if (GetPackedFlag<kFlagValidTargetClassRTI>()) { |
| 7123 | // Note: The is_exact flag from the return value should not be used. |
| 7124 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact */ true); |
| 7125 | } else { |
| 7126 | return ReferenceTypeInfo::CreateInvalid(); |
| 7127 | } |
| 7128 | } |
| 7129 | |
| 7130 | // Target class RTI is marked as valid by RTP if the klass_ is admissible. |
| 7131 | void SetValidTargetClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 7132 | DCHECK(klass_ != nullptr); |
| 7133 | SetPackedFlag<kFlagValidTargetClassRTI>(true); |
| 7134 | } |
| 7135 | |
| 7136 | Handle<mirror::Class> GetClass() const { |
| 7137 | return klass_; |
| 7138 | } |
| 7139 | |
| 7140 | protected: |
| 7141 | DEFAULT_COPY_CONSTRUCTOR(TypeCheckInstruction); |
| 7142 | |
| 7143 | private: |
| 7144 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 7145 | static constexpr size_t kFieldTypeCheckKindSize = |
| 7146 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 7147 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 7148 | static constexpr size_t kFlagValidTargetClassRTI = kFlagMustDoNullCheck + 1; |
| 7149 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagValidTargetClassRTI + 1; |
| 7150 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7151 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
| 7152 | |
| 7153 | Handle<mirror::Class> klass_; |
| 7154 | }; |
| 7155 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7156 | class HInstanceOf final : public HTypeCheckInstruction { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7157 | public: |
| 7158 | HInstanceOf(HInstruction* object, |
| 7159 | HInstruction* target_class_or_null, |
| 7160 | TypeCheckKind check_kind, |
| 7161 | Handle<mirror::Class> klass, |
| 7162 | uint32_t dex_pc, |
| 7163 | ArenaAllocator* allocator, |
| 7164 | HIntConstant* bitstring_path_to_root, |
| 7165 | HIntConstant* bitstring_mask) |
| 7166 | : HTypeCheckInstruction(kInstanceOf, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7167 | DataType::Type::kBool, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7168 | object, |
| 7169 | target_class_or_null, |
| 7170 | check_kind, |
| 7171 | klass, |
| 7172 | dex_pc, |
| 7173 | allocator, |
| 7174 | bitstring_path_to_root, |
| 7175 | bitstring_mask, |
| 7176 | SideEffectsForArchRuntimeCalls(check_kind)) {} |
| 7177 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7178 | bool IsClonable() const override { return true; } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 7179 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7180 | bool NeedsEnvironment() const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7181 | return CanCallRuntime(GetTypeCheckKind()); |
| 7182 | } |
| 7183 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7184 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 7185 | // Mips currently does runtime calls for any other checks. |
| 7186 | return check_kind != TypeCheckKind::kExactCheck; |
| 7187 | } |
| 7188 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7189 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7190 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7191 | } |
| 7192 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7193 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7194 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7195 | protected: |
| 7196 | DEFAULT_COPY_CONSTRUCTOR(InstanceOf); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7197 | }; |
| 7198 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7199 | class HBoundType final : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7200 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 7201 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7202 | : HExpression(kBoundType, DataType::Type::kReference, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7203 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 7204 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 7205 | SetPackedFlag<kFlagCanBeNull>(true); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7206 | DCHECK_EQ(input->GetType(), DataType::Type::kReference); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7207 | SetRawInputAt(0, input); |
| 7208 | } |
| 7209 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7210 | bool InstructionDataEquals(const HInstruction* other) const override; |
| 7211 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7212 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7213 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7214 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7215 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7216 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7217 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7218 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7219 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 7220 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7221 | } |
| 7222 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7223 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7224 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7225 | DECLARE_INSTRUCTION(BoundType); |
| 7226 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7227 | protected: |
| 7228 | DEFAULT_COPY_CONSTRUCTOR(BoundType); |
| 7229 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7230 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7231 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 7232 | // is false then CanBeNull() cannot be true). |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7233 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7234 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 7235 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 7236 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7237 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7238 | // 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] | 7239 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 7240 | // It is used to bound the type in cases like: |
| 7241 | // if (x instanceof ClassX) { |
| 7242 | // // uper_bound_ will be ClassX |
| 7243 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7244 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7245 | }; |
| 7246 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7247 | class HCheckCast final : public HTypeCheckInstruction { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7248 | public: |
| 7249 | HCheckCast(HInstruction* object, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7250 | HInstruction* target_class_or_null, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7251 | TypeCheckKind check_kind, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7252 | Handle<mirror::Class> klass, |
| 7253 | uint32_t dex_pc, |
| 7254 | ArenaAllocator* allocator, |
| 7255 | HIntConstant* bitstring_path_to_root, |
| 7256 | HIntConstant* bitstring_mask) |
| 7257 | : HTypeCheckInstruction(kCheckCast, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7258 | DataType::Type::kVoid, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7259 | object, |
| 7260 | target_class_or_null, |
| 7261 | check_kind, |
| 7262 | klass, |
| 7263 | dex_pc, |
| 7264 | allocator, |
| 7265 | bitstring_path_to_root, |
| 7266 | bitstring_mask, |
| 7267 | SideEffects::CanTriggerGC()) {} |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7268 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7269 | bool IsClonable() const override { return true; } |
| 7270 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7271 | // Instruction may throw a CheckCastError. |
| 7272 | return true; |
| 7273 | } |
| 7274 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7275 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7276 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7277 | DECLARE_INSTRUCTION(CheckCast); |
| 7278 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7279 | protected: |
| 7280 | DEFAULT_COPY_CONSTRUCTOR(CheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7281 | }; |
| 7282 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 7283 | /** |
| 7284 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 7285 | * @details We define the combined barrier types that are actually required |
| 7286 | * by the Java Memory Model, rather than using exactly the terminology from |
| 7287 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 7288 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 7289 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 7290 | * The current recipe is as follows: |
| 7291 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 7292 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 7293 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 7294 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 7295 | * class has final fields. |
| 7296 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 7297 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 7298 | */ |
| 7299 | enum MemBarrierKind { |
| 7300 | kAnyStore, |
| 7301 | kLoadAny, |
| 7302 | kStoreStore, |
| 7303 | kAnyAny, |
| 7304 | kNTStoreStore, |
| 7305 | kLastBarrierKind = kNTStoreStore |
| 7306 | }; |
| 7307 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 7308 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7309 | class HMemoryBarrier final : public HExpression<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7310 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7311 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7312 | : HExpression(kMemoryBarrier, |
| 7313 | SideEffects::AllWritesAndReads(), // Assume write/read on all fields/arrays. |
| 7314 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7315 | SetPackedField<BarrierKindField>(barrier_kind); |
| 7316 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7317 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7318 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7319 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7320 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7321 | |
| 7322 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 7323 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7324 | protected: |
| 7325 | DEFAULT_COPY_CONSTRUCTOR(MemoryBarrier); |
| 7326 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7327 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7328 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 7329 | static constexpr size_t kFieldBarrierKindSize = |
| 7330 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 7331 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 7332 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 7333 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 7334 | "Too many packed fields."); |
| 7335 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7336 | }; |
| 7337 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7338 | // A constructor fence orders all prior stores to fields that could be accessed via a final field of |
| 7339 | // the specified object(s), with respect to any subsequent store that might "publish" |
| 7340 | // (i.e. make visible) the specified object to another thread. |
| 7341 | // |
| 7342 | // JLS 17.5.1 "Semantics of final fields" states that a freeze action happens |
| 7343 | // for all final fields (that were set) at the end of the invoked constructor. |
| 7344 | // |
| 7345 | // The constructor fence models the freeze actions for the final fields of an object |
| 7346 | // being constructed (semantically at the end of the constructor). Constructor fences |
| 7347 | // have a per-object affinity; two separate objects being constructed get two separate |
| 7348 | // constructor fences. |
| 7349 | // |
| 7350 | // (Note: that if calling a super-constructor or forwarding to another constructor, |
| 7351 | // the freezes would happen at the end of *that* constructor being invoked). |
| 7352 | // |
| 7353 | // The memory model guarantees that when the object being constructed is "published" after |
| 7354 | // constructor completion (i.e. escapes the current thread via a store), then any final field |
| 7355 | // writes must be observable on other threads (once they observe that publication). |
| 7356 | // |
| 7357 | // Further, anything written before the freeze, and read by dereferencing through the final field, |
| 7358 | // must also be visible (so final object field could itself have an object with non-final fields; |
| 7359 | // yet the freeze must also extend to them). |
| 7360 | // |
| 7361 | // Constructor example: |
| 7362 | // |
| 7363 | // class HasFinal { |
| 7364 | // final int field; Optimizing IR for <init>()V: |
| 7365 | // HasFinal() { |
| 7366 | // field = 123; HInstanceFieldSet(this, HasFinal.field, 123) |
| 7367 | // // freeze(this.field); HConstructorFence(this) |
| 7368 | // } HReturn |
| 7369 | // } |
| 7370 | // |
| 7371 | // HConstructorFence can serve double duty as a fence for new-instance/new-array allocations of |
| 7372 | // already-initialized classes; in that case the allocation must act as a "default-initializer" |
| 7373 | // of the object which effectively writes the class pointer "final field". |
| 7374 | // |
| 7375 | // For example, we can model default-initialiation as roughly the equivalent of the following: |
| 7376 | // |
| 7377 | // class Object { |
| 7378 | // private final Class header; |
| 7379 | // } |
| 7380 | // |
| 7381 | // Java code: Optimizing IR: |
| 7382 | // |
| 7383 | // T new_instance<T>() { |
| 7384 | // Object obj = allocate_memory(T.class.size); obj = HInvoke(art_quick_alloc_object, T) |
| 7385 | // obj.header = T.class; // header write is done by above call. |
| 7386 | // // freeze(obj.header) HConstructorFence(obj) |
| 7387 | // return (T)obj; |
| 7388 | // } |
| 7389 | // |
| 7390 | // See also: |
| 7391 | // * CompilerDriver::RequiresConstructorBarrier |
| 7392 | // * QuasiAtomic::ThreadFenceForConstructor |
| 7393 | // |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7394 | class HConstructorFence final : public HVariableInputSizeInstruction { |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7395 | // A fence has variable inputs because the inputs can be removed |
| 7396 | // after prepare_for_register_allocation phase. |
| 7397 | // (TODO: In the future a fence could freeze multiple objects |
| 7398 | // after merging two fences together.) |
| 7399 | public: |
| 7400 | // `fence_object` is the reference that needs to be protected for correct publication. |
| 7401 | // |
| 7402 | // It makes sense in the following situations: |
| 7403 | // * <init> constructors, it's the "this" parameter (i.e. HParameterValue, s.t. IsThis() == true). |
| 7404 | // * new-instance-like instructions, it's the return value (i.e. HNewInstance). |
| 7405 | // |
| 7406 | // After construction the `fence_object` becomes the 0th input. |
| 7407 | // This is not an input in a real sense, but just a convenient place to stash the information |
| 7408 | // about the associated object. |
| 7409 | HConstructorFence(HInstruction* fence_object, |
| 7410 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7411 | ArenaAllocator* allocator) |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7412 | // We strongly suspect there is not a more accurate way to describe the fine-grained reordering |
| 7413 | // constraints described in the class header. We claim that these SideEffects constraints |
| 7414 | // enforce a superset of the real constraints. |
| 7415 | // |
| 7416 | // The ordering described above is conservatively modeled with SideEffects as follows: |
| 7417 | // |
| 7418 | // * To prevent reordering of the publication stores: |
| 7419 | // ----> "Reads of objects" is the initial SideEffect. |
| 7420 | // * For every primitive final field store in the constructor: |
| 7421 | // ----> Union that field's type as a read (e.g. "Read of T") into the SideEffect. |
| 7422 | // * If there are any stores to reference final fields in the constructor: |
| 7423 | // ----> Use a more conservative "AllReads" SideEffect because any stores to any references |
| 7424 | // that are reachable from `fence_object` also need to be prevented for reordering |
| 7425 | // (and we do not want to do alias analysis to figure out what those stores are). |
| 7426 | // |
| 7427 | // In the implementation, this initially starts out as an "all reads" side effect; this is an |
| 7428 | // even more conservative approach than the one described above, and prevents all of the |
| 7429 | // above reordering without analyzing any of the instructions in the constructor. |
| 7430 | // |
| 7431 | // If in a later phase we discover that there are no writes to reference final fields, |
| 7432 | // we can refine the side effect to a smaller set of type reads (see above constraints). |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7433 | : HVariableInputSizeInstruction(kConstructorFence, |
| 7434 | SideEffects::AllReads(), |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7435 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7436 | allocator, |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7437 | /* number_of_inputs */ 1, |
| 7438 | kArenaAllocConstructorFenceInputs) { |
| 7439 | DCHECK(fence_object != nullptr); |
| 7440 | SetRawInputAt(0, fence_object); |
| 7441 | } |
| 7442 | |
| 7443 | // The object associated with this constructor fence. |
| 7444 | // |
| 7445 | // (Note: This will be null after the prepare_for_register_allocation phase, |
| 7446 | // as all constructor fence inputs are removed there). |
| 7447 | HInstruction* GetFenceObject() const { |
| 7448 | return InputAt(0); |
| 7449 | } |
| 7450 | |
| 7451 | // Find all the HConstructorFence uses (`fence_use`) for `this` and: |
| 7452 | // - Delete `fence_use` from `this`'s use list. |
| 7453 | // - Delete `this` from `fence_use`'s inputs list. |
| 7454 | // - If the `fence_use` is dead, remove it from the graph. |
| 7455 | // |
| 7456 | // A fence is considered dead once it no longer has any uses |
| 7457 | // and all of the inputs are dead. |
| 7458 | // |
| 7459 | // This must *not* be called during/after prepare_for_register_allocation, |
| 7460 | // because that removes all the inputs to the fences but the fence is actually |
| 7461 | // still considered live. |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7462 | // |
| 7463 | // Returns how many HConstructorFence instructions were removed from graph. |
| 7464 | static size_t RemoveConstructorFences(HInstruction* instruction); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7465 | |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7466 | // Combine all inputs of `this` and `other` instruction and remove |
| 7467 | // `other` from the graph. |
| 7468 | // |
| 7469 | // Inputs are unique after the merge. |
| 7470 | // |
| 7471 | // Requirement: `this` must not be the same as `other. |
| 7472 | void Merge(HConstructorFence* other); |
| 7473 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7474 | // Check if this constructor fence is protecting |
| 7475 | // an HNewInstance or HNewArray that is also the immediate |
| 7476 | // predecessor of `this`. |
| 7477 | // |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7478 | // If `ignore_inputs` is true, then the immediate predecessor doesn't need |
| 7479 | // to be one of the inputs of `this`. |
| 7480 | // |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7481 | // Returns the associated HNewArray or HNewInstance, |
| 7482 | // or null otherwise. |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7483 | HInstruction* GetAssociatedAllocation(bool ignore_inputs = false); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7484 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7485 | DECLARE_INSTRUCTION(ConstructorFence); |
| 7486 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7487 | protected: |
| 7488 | DEFAULT_COPY_CONSTRUCTOR(ConstructorFence); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7489 | }; |
| 7490 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7491 | class HMonitorOperation final : public HExpression<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7492 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7493 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7494 | kEnter, |
| 7495 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7496 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7497 | }; |
| 7498 | |
| 7499 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7500 | : HExpression(kMonitorOperation, |
| 7501 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 7502 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7503 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7504 | SetRawInputAt(0, object); |
| 7505 | } |
| 7506 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7507 | // Instruction may go into runtime, so we need an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7508 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 7509 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7510 | bool CanThrow() const override { |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 7511 | // Verifier guarantees that monitor-exit cannot throw. |
| 7512 | // This is important because it allows the HGraphBuilder to remove |
| 7513 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 7514 | return IsEnter(); |
| 7515 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7516 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7517 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 7518 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7519 | |
| 7520 | DECLARE_INSTRUCTION(MonitorOperation); |
| 7521 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7522 | protected: |
| 7523 | DEFAULT_COPY_CONSTRUCTOR(MonitorOperation); |
| 7524 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7525 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7526 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 7527 | static constexpr size_t kFieldOperationKindSize = |
| 7528 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 7529 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 7530 | kFieldOperationKind + kFieldOperationKindSize; |
| 7531 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7532 | "Too many packed fields."); |
| 7533 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7534 | }; |
| 7535 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7536 | class HSelect final : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7537 | public: |
| 7538 | HSelect(HInstruction* condition, |
| 7539 | HInstruction* true_value, |
| 7540 | HInstruction* false_value, |
| 7541 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7542 | : HExpression(kSelect, HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7543 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 7544 | |
| 7545 | // First input must be `true_value` or `false_value` to allow codegens to |
| 7546 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 7547 | // that architectures which implement HSelect as a conditional move also |
| 7548 | // will not need to invert the condition. |
| 7549 | SetRawInputAt(0, false_value); |
| 7550 | SetRawInputAt(1, true_value); |
| 7551 | SetRawInputAt(2, condition); |
| 7552 | } |
| 7553 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7554 | bool IsClonable() const override { return true; } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7555 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 7556 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 7557 | HInstruction* GetCondition() const { return InputAt(2); } |
| 7558 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7559 | bool CanBeMoved() const override { return true; } |
| 7560 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7561 | return true; |
| 7562 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7563 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7564 | bool CanBeNull() const override { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7565 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 7566 | } |
| 7567 | |
| 7568 | DECLARE_INSTRUCTION(Select); |
| 7569 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7570 | protected: |
| 7571 | DEFAULT_COPY_CONSTRUCTOR(Select); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7572 | }; |
| 7573 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 7574 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7575 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7576 | MoveOperands(Location source, |
| 7577 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7578 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7579 | HInstruction* instruction) |
| 7580 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7581 | |
| 7582 | Location GetSource() const { return source_; } |
| 7583 | Location GetDestination() const { return destination_; } |
| 7584 | |
| 7585 | void SetSource(Location value) { source_ = value; } |
| 7586 | void SetDestination(Location value) { destination_ = value; } |
| 7587 | |
| 7588 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 7589 | // destination (but not the source). |
| 7590 | Location MarkPending() { |
| 7591 | DCHECK(!IsPending()); |
| 7592 | Location dest = destination_; |
| 7593 | destination_ = Location::NoLocation(); |
| 7594 | return dest; |
| 7595 | } |
| 7596 | |
| 7597 | void ClearPending(Location dest) { |
| 7598 | DCHECK(IsPending()); |
| 7599 | destination_ = dest; |
| 7600 | } |
| 7601 | |
| 7602 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7603 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 7604 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7605 | } |
| 7606 | |
| 7607 | // True if this blocks a move from the given location. |
| 7608 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 7609 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7610 | } |
| 7611 | |
| 7612 | // A move is redundant if it's been eliminated, if its source and |
| 7613 | // destination are the same, or if its destination is unneeded. |
| 7614 | bool IsRedundant() const { |
| 7615 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 7616 | } |
| 7617 | |
| 7618 | // We clear both operands to indicate move that's been eliminated. |
| 7619 | void Eliminate() { |
| 7620 | source_ = destination_ = Location::NoLocation(); |
| 7621 | } |
| 7622 | |
| 7623 | bool IsEliminated() const { |
| 7624 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 7625 | return source_.IsInvalid(); |
| 7626 | } |
| 7627 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7628 | DataType::Type GetType() const { return type_; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7629 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7630 | bool Is64BitMove() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7631 | return DataType::Is64BitType(type_); |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7632 | } |
| 7633 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7634 | HInstruction* GetInstruction() const { return instruction_; } |
| 7635 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7636 | private: |
| 7637 | Location source_; |
| 7638 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7639 | // The type this move is for. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7640 | DataType::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7641 | // The instruction this move is assocatied with. Null when this move is |
| 7642 | // for moving an input in the expected locations of user (including a phi user). |
| 7643 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 7644 | // in the same parallel move. |
| 7645 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7646 | }; |
| 7647 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7648 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 7649 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7650 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 7651 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7652 | class HParallelMove final : public HExpression<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7653 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7654 | explicit HParallelMove(ArenaAllocator* allocator, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7655 | : HExpression(kParallelMove, SideEffects::None(), dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7656 | moves_(allocator->Adapter(kArenaAllocMoveOperands)) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7657 | moves_.reserve(kDefaultNumberOfMoves); |
| 7658 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7659 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7660 | void AddMove(Location source, |
| 7661 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7662 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7663 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 7664 | DCHECK(source.IsValid()); |
| 7665 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7666 | if (kIsDebugBuild) { |
| 7667 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7668 | for (const MoveOperands& move : moves_) { |
| 7669 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7670 | // Special case the situation where the move is for the spill slot |
| 7671 | // of the instruction. |
| 7672 | if ((GetPrevious() == instruction) |
| 7673 | || ((GetPrevious() == nullptr) |
| 7674 | && instruction->IsPhi() |
| 7675 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7676 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7677 | << "Doing parallel moves for the same instruction."; |
| 7678 | } else { |
| 7679 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 7680 | } |
| 7681 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 7682 | } |
| 7683 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7684 | for (const MoveOperands& move : moves_) { |
| 7685 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7686 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7687 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7688 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7689 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7690 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7691 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7692 | } |
| 7693 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7694 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7695 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7696 | } |
| 7697 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7698 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7699 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 7700 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7701 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7702 | protected: |
| 7703 | DEFAULT_COPY_CONSTRUCTOR(ParallelMove); |
| 7704 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7705 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7706 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7707 | }; |
| 7708 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7709 | // This instruction computes an intermediate address pointing in the 'middle' of an object. The |
| 7710 | // result pointer cannot be handled by GC, so extra care is taken to make sure that this value is |
| 7711 | // never used across anything that can trigger GC. |
| 7712 | // The result of this instruction is not a pointer in the sense of `DataType::Type::kreference`. |
| 7713 | // So we represent it by the type `DataType::Type::kInt`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7714 | class HIntermediateAddress final : public HExpression<2> { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7715 | public: |
| 7716 | HIntermediateAddress(HInstruction* base_address, HInstruction* offset, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7717 | : HExpression(kIntermediateAddress, |
| 7718 | DataType::Type::kInt32, |
| 7719 | SideEffects::DependsOnGC(), |
| 7720 | dex_pc) { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7721 | DCHECK_EQ(DataType::Size(DataType::Type::kInt32), |
| 7722 | DataType::Size(DataType::Type::kReference)) |
| 7723 | << "kPrimInt and kPrimNot have different sizes."; |
| 7724 | SetRawInputAt(0, base_address); |
| 7725 | SetRawInputAt(1, offset); |
| 7726 | } |
| 7727 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7728 | bool IsClonable() const override { return true; } |
| 7729 | bool CanBeMoved() const override { return true; } |
| 7730 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7731 | return true; |
| 7732 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7733 | bool IsActualObject() const override { return false; } |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7734 | |
| 7735 | HInstruction* GetBaseAddress() const { return InputAt(0); } |
| 7736 | HInstruction* GetOffset() const { return InputAt(1); } |
| 7737 | |
| 7738 | DECLARE_INSTRUCTION(IntermediateAddress); |
| 7739 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7740 | protected: |
| 7741 | DEFAULT_COPY_CONSTRUCTOR(IntermediateAddress); |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7742 | }; |
| 7743 | |
| 7744 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7745 | } // namespace art |
| 7746 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 7747 | #include "nodes_vector.h" |
| 7748 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7749 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 7750 | #include "nodes_shared.h" |
| 7751 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7752 | #ifdef ART_ENABLE_CODEGEN_mips |
| 7753 | #include "nodes_mips.h" |
| 7754 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7755 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 7756 | #include "nodes_x86.h" |
| 7757 | #endif |
| 7758 | |
| 7759 | namespace art { |
| 7760 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7761 | class OptimizingCompilerStats; |
| 7762 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7763 | class HGraphVisitor : public ValueObject { |
| 7764 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7765 | explicit HGraphVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7766 | : stats_(stats), |
| 7767 | graph_(graph) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 7768 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7769 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7770 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7771 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 7772 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7773 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7774 | void VisitInsertionOrder(); |
| 7775 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7776 | // Visit the graph following dominator tree reverse post-order. |
| 7777 | void VisitReversePostOrder(); |
| 7778 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 7779 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7780 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7781 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7782 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7783 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 7784 | |
| 7785 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7786 | |
| 7787 | #undef DECLARE_VISIT_INSTRUCTION |
| 7788 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7789 | protected: |
| 7790 | OptimizingCompilerStats* stats_; |
| 7791 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7792 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 7793 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7794 | |
| 7795 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 7796 | }; |
| 7797 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7798 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 7799 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7800 | explicit HGraphDelegateVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7801 | : HGraphVisitor(graph, stats) {} |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7802 | virtual ~HGraphDelegateVisitor() {} |
| 7803 | |
| 7804 | // Visit functions that delegate to to super class. |
| 7805 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7806 | void Visit##name(H##name* instr) override { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7807 | |
| 7808 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7809 | |
| 7810 | #undef DECLARE_VISIT_INSTRUCTION |
| 7811 | |
| 7812 | private: |
| 7813 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 7814 | }; |
| 7815 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7816 | // Create a clone of the instruction, insert it into the graph; replace the old one with a new |
| 7817 | // and remove the old instruction. |
| 7818 | HInstruction* ReplaceInstrOrPhiByClone(HInstruction* instr); |
| 7819 | |
| 7820 | // Create a clone for each clonable instructions/phis and replace the original with the clone. |
| 7821 | // |
| 7822 | // Used for testing individual instruction cloner. |
| 7823 | class CloneAndReplaceInstructionVisitor : public HGraphDelegateVisitor { |
| 7824 | public: |
| 7825 | explicit CloneAndReplaceInstructionVisitor(HGraph* graph) |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7826 | : HGraphDelegateVisitor(graph), instr_replaced_by_clones_count_(0) {} |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7827 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7828 | void VisitInstruction(HInstruction* instruction) override { |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7829 | if (instruction->IsClonable()) { |
| 7830 | ReplaceInstrOrPhiByClone(instruction); |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7831 | instr_replaced_by_clones_count_++; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7832 | } |
| 7833 | } |
| 7834 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7835 | size_t GetInstrReplacedByClonesCount() const { return instr_replaced_by_clones_count_; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7836 | |
| 7837 | private: |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7838 | size_t instr_replaced_by_clones_count_; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7839 | |
| 7840 | DISALLOW_COPY_AND_ASSIGN(CloneAndReplaceInstructionVisitor); |
| 7841 | }; |
| 7842 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7843 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7844 | // of an inner loop. The order in which the blocks are iterated is on their |
| 7845 | // block id. |
| 7846 | class HBlocksInLoopIterator : public ValueObject { |
| 7847 | public: |
| 7848 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 7849 | : blocks_in_loop_(info.GetBlocks()), |
| 7850 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 7851 | index_(0) { |
| 7852 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 7853 | Advance(); |
| 7854 | } |
| 7855 | } |
| 7856 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7857 | bool Done() const { return index_ == blocks_.size(); } |
| 7858 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7859 | void Advance() { |
| 7860 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7861 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7862 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 7863 | break; |
| 7864 | } |
| 7865 | } |
| 7866 | } |
| 7867 | |
| 7868 | private: |
| 7869 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7870 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7871 | size_t index_; |
| 7872 | |
| 7873 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 7874 | }; |
| 7875 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7876 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7877 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 7878 | // post order. |
| 7879 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 7880 | public: |
| 7881 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 7882 | : blocks_in_loop_(info.GetBlocks()), |
| 7883 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 7884 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7885 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7886 | Advance(); |
| 7887 | } |
| 7888 | } |
| 7889 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7890 | bool Done() const { return index_ == blocks_.size(); } |
| 7891 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7892 | void Advance() { |
| 7893 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7894 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 7895 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7896 | break; |
| 7897 | } |
| 7898 | } |
| 7899 | } |
| 7900 | |
| 7901 | private: |
| 7902 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7903 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7904 | size_t index_; |
| 7905 | |
| 7906 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 7907 | }; |
| 7908 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7909 | // Returns int64_t value of a properly typed constant. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7910 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7911 | if (constant->IsIntConstant()) { |
| 7912 | return constant->AsIntConstant()->GetValue(); |
| 7913 | } else if (constant->IsLongConstant()) { |
| 7914 | return constant->AsLongConstant()->GetValue(); |
| 7915 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 7916 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7917 | return 0; |
| 7918 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7919 | } |
| 7920 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7921 | // Returns true iff instruction is an integral constant (and sets value on success). |
| 7922 | inline bool IsInt64AndGet(HInstruction* instruction, /*out*/ int64_t* value) { |
| 7923 | if (instruction->IsIntConstant()) { |
| 7924 | *value = instruction->AsIntConstant()->GetValue(); |
| 7925 | return true; |
| 7926 | } else if (instruction->IsLongConstant()) { |
| 7927 | *value = instruction->AsLongConstant()->GetValue(); |
| 7928 | return true; |
| 7929 | } else if (instruction->IsNullConstant()) { |
| 7930 | *value = 0; |
| 7931 | return true; |
| 7932 | } |
| 7933 | return false; |
| 7934 | } |
| 7935 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 7936 | // Returns true iff instruction is the given integral constant. |
| 7937 | inline bool IsInt64Value(HInstruction* instruction, int64_t value) { |
| 7938 | int64_t val = 0; |
| 7939 | return IsInt64AndGet(instruction, &val) && val == value; |
| 7940 | } |
| 7941 | |
| 7942 | // Returns true iff instruction is a zero bit pattern. |
| 7943 | inline bool IsZeroBitPattern(HInstruction* instruction) { |
| 7944 | return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern(); |
| 7945 | } |
| 7946 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7947 | // Implement HInstruction::Is##type() for concrete instructions. |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7948 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7949 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } |
| 7950 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7951 | #undef INSTRUCTION_TYPE_CHECK |
| 7952 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7953 | // Implement HInstruction::Is##type() for abstract instructions. |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7954 | #define INSTRUCTION_TYPE_CHECK_RESULT(type, super) \ |
| 7955 | std::is_base_of<BaseType, H##type>::value, |
| 7956 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 7957 | inline bool HInstruction::Is##type() const { \ |
| 7958 | DCHECK_LT(GetKind(), kLastInstructionKind); \ |
| 7959 | using BaseType = H##type; \ |
| 7960 | static constexpr bool results[] = { \ |
| 7961 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK_RESULT) \ |
| 7962 | }; \ |
| 7963 | return results[static_cast<size_t>(GetKind())]; \ |
| 7964 | } |
| 7965 | |
| 7966 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7967 | #undef INSTRUCTION_TYPE_CHECK |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7968 | #undef INSTRUCTION_TYPE_CHECK_RESULT |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7969 | |
| 7970 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7971 | inline const H##type* HInstruction::As##type() const { \ |
| 7972 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 7973 | } \ |
| 7974 | inline H##type* HInstruction::As##type() { \ |
| 7975 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 7976 | } |
| 7977 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7978 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 7979 | #undef INSTRUCTION_TYPE_CAST |
| 7980 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7981 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 7982 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 7983 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 7984 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 7985 | size_t number_of_new_blocks, |
| 7986 | size_t after) { |
| 7987 | DCHECK_LT(after, blocks->size()); |
| 7988 | size_t old_size = blocks->size(); |
| 7989 | size_t new_size = old_size + number_of_new_blocks; |
| 7990 | blocks->resize(new_size); |
| 7991 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 7992 | } |
| 7993 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7994 | /* |
| 7995 | * Hunt "under the hood" of array lengths (leading to array references), |
| 7996 | * null checks (also leading to array references), and new arrays |
| 7997 | * (leading to the actual length). This makes it more likely related |
| 7998 | * instructions become actually comparable. |
| 7999 | */ |
| 8000 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 8001 | while (instruction->IsArrayLength() || |
| 8002 | instruction->IsNullCheck() || |
| 8003 | instruction->IsNewArray()) { |
| 8004 | instruction = instruction->IsNewArray() |
| 8005 | ? instruction->AsNewArray()->GetLength() |
| 8006 | : instruction->InputAt(0); |
| 8007 | } |
| 8008 | return instruction; |
| 8009 | } |
| 8010 | |
Artem Serov | 21c7e6f | 2017-07-27 16:04:42 +0100 | [diff] [blame] | 8011 | void RemoveEnvironmentUses(HInstruction* instruction); |
| 8012 | bool HasEnvironmentUsedByOthers(HInstruction* instruction); |
| 8013 | void ResetEnvironmentInputRecords(HInstruction* instruction); |
| 8014 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8015 | } // namespace art |
| 8016 | |
| 8017 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |