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 | 3fae129 | 2019-06-07 11:26:25 +0100 | [diff] [blame] | 28 | #include "base/intrusive_forward_list.h" |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 29 | #include "base/iteration_range.h" |
Andreas Gampe | 7fbc4a5 | 2018-11-28 08:26:47 -0800 | [diff] [blame] | 30 | #include "base/mutex.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 31 | #include "base/quasi_atomic.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 32 | #include "base/stl_util.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 33 | #include "base/transform_array_ref.h" |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 34 | #include "art_method.h" |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 35 | #include "class_root.h" |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 36 | #include "compilation_kind.h" |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 37 | #include "data_type.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 38 | #include "deoptimization_kind.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 39 | #include "dex/dex_file.h" |
| 40 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 41 | #include "dex/invoke_type.h" |
David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 42 | #include "dex/method_reference.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 43 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 44 | #include "handle.h" |
| 45 | #include "handle_scope.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 46 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 47 | #include "locations.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 48 | #include "mirror/class.h" |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 49 | #include "mirror/method_type.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 50 | #include "offsets.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 51 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 52 | namespace art { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 53 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 54 | class ArenaStack; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 55 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 56 | class HBasicBlock; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 57 | class HConstructorFence; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 58 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 59 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 60 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 61 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 62 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 63 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 64 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 65 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 66 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 67 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 68 | class HNullConstant; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 69 | class HParameterValue; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 70 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 71 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 72 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 73 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 74 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 75 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 76 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 77 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 78 | namespace mirror { |
| 79 | class DexCache; |
| 80 | } // namespace mirror |
| 81 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 82 | static const int kDefaultNumberOfBlocks = 8; |
| 83 | static const int kDefaultNumberOfSuccessors = 2; |
| 84 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 85 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 86 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 87 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 88 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 89 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 90 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 91 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 92 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 93 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 94 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 95 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 96 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 97 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 98 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 99 | static constexpr uint32_t kNoDexPc = -1; |
| 100 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 101 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 102 | // For the purposes of the compiler, the dex files must actually be the same object |
| 103 | // if we want to safely treat them as the same. This is especially important for JIT |
| 104 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 105 | // times and provide different class resolution but no two class loaders should ever |
| 106 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 107 | // all sorts of weird failures. |
| 108 | return &lhs == &rhs; |
| 109 | } |
| 110 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 111 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 112 | // All types. |
| 113 | kCondEQ, // == |
| 114 | kCondNE, // != |
| 115 | // Signed integers and floating-point numbers. |
| 116 | kCondLT, // < |
| 117 | kCondLE, // <= |
| 118 | kCondGT, // > |
| 119 | kCondGE, // >= |
| 120 | // Unsigned integers. |
| 121 | kCondB, // < |
| 122 | kCondBE, // <= |
| 123 | kCondA, // > |
| 124 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 125 | // First and last aliases. |
| 126 | kCondFirst = kCondEQ, |
| 127 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 128 | }; |
| 129 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 130 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 131 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 132 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 133 | kAnalysisFailThrowCatchLoop, |
| 134 | kAnalysisFailAmbiguousArrayOp, |
Nicolas Geoffray | 0846a8f | 2018-09-12 15:21:07 +0100 | [diff] [blame] | 135 | kAnalysisFailIrreducibleLoopAndStringInit, |
Nicolas Geoffray | 7cfc8f5 | 2019-08-07 10:41:09 +0100 | [diff] [blame] | 136 | kAnalysisFailPhiEquivalentInOsr, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 137 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 140 | template <typename T> |
| 141 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 142 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 143 | } |
| 144 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 145 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 146 | public: |
| 147 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 148 | |
| 149 | void AddInstruction(HInstruction* instruction); |
| 150 | void RemoveInstruction(HInstruction* instruction); |
| 151 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 152 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 153 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 154 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 155 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 156 | // Return true if this list contains `instruction`. |
| 157 | bool Contains(HInstruction* instruction) const; |
| 158 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 159 | // Return true if `instruction1` is found before `instruction2` in |
| 160 | // this instruction list and false otherwise. Abort if none |
| 161 | // of these instructions is found. |
| 162 | bool FoundBefore(const HInstruction* instruction1, |
| 163 | const HInstruction* instruction2) const; |
| 164 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 165 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 166 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 167 | |
| 168 | // Update the block of all instructions to be `block`. |
| 169 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 170 | |
| 171 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 172 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 173 | void Add(const HInstructionList& instruction_list); |
| 174 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 175 | // Return the number of instructions in the list. This is an expensive operation. |
| 176 | size_t CountSize() const; |
| 177 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 178 | private: |
| 179 | HInstruction* first_instruction_; |
| 180 | HInstruction* last_instruction_; |
| 181 | |
| 182 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 183 | friend class HGraph; |
| 184 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 185 | friend class HInstructionIterator; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 186 | friend class HInstructionIteratorHandleChanges; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 187 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 188 | |
| 189 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 190 | }; |
| 191 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 192 | class ReferenceTypeInfo : ValueObject { |
| 193 | public: |
| 194 | typedef Handle<mirror::Class> TypeHandle; |
| 195 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 196 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 197 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 198 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 199 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 200 | } |
| 201 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 202 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 203 | return ReferenceTypeInfo(type_handle, is_exact); |
| 204 | } |
| 205 | |
| 206 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 207 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 208 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 209 | return handle.GetReference() != nullptr; |
| 210 | } |
| 211 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 212 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 213 | return IsValidHandle(type_handle_); |
| 214 | } |
| 215 | |
| 216 | bool IsExact() const { return is_exact_; } |
| 217 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 218 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 219 | DCHECK(IsValid()); |
| 220 | return GetTypeHandle()->IsObjectClass(); |
| 221 | } |
| 222 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 223 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 224 | DCHECK(IsValid()); |
| 225 | return GetTypeHandle()->IsStringClass(); |
| 226 | } |
| 227 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 228 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 229 | DCHECK(IsValid()); |
| 230 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 231 | } |
| 232 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 233 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 234 | DCHECK(IsValid()); |
| 235 | return GetTypeHandle()->IsInterface(); |
| 236 | } |
| 237 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 238 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 239 | DCHECK(IsValid()); |
| 240 | return GetTypeHandle()->IsArrayClass(); |
| 241 | } |
| 242 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 243 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 244 | DCHECK(IsValid()); |
| 245 | return GetTypeHandle()->IsPrimitiveArray(); |
| 246 | } |
| 247 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 248 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 249 | DCHECK(IsValid()); |
| 250 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 251 | } |
| 252 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 253 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 254 | DCHECK(IsValid()); |
| 255 | if (!IsExact()) return false; |
| 256 | if (!IsArrayClass()) return false; |
| 257 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 258 | } |
| 259 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 260 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 261 | DCHECK(IsValid()); |
| 262 | if (!IsExact()) return false; |
| 263 | if (!IsArrayClass()) return false; |
| 264 | if (!rti.IsArrayClass()) return false; |
| 265 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 266 | rti.GetTypeHandle()->GetComponentType()); |
| 267 | } |
| 268 | |
| 269 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 270 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 271 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 272 | DCHECK(IsValid()); |
| 273 | DCHECK(rti.IsValid()); |
| 274 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 275 | } |
| 276 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 277 | // Returns true if the type information provide the same amount of details. |
| 278 | // Note that it does not mean that the instructions have the same actual type |
| 279 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 280 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 281 | if (!IsValid() && !rti.IsValid()) { |
| 282 | // Invalid types are equal. |
| 283 | return true; |
| 284 | } |
| 285 | if (!IsValid() || !rti.IsValid()) { |
| 286 | // One is valid, the other not. |
| 287 | return false; |
| 288 | } |
| 289 | return IsExact() == rti.IsExact() |
| 290 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 291 | } |
| 292 | |
| 293 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 294 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 295 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 296 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 297 | |
| 298 | // The class of the object. |
| 299 | TypeHandle type_handle_; |
| 300 | // Whether or not the type is exact or a superclass of the actual type. |
| 301 | // Whether or not we have any information about this type. |
| 302 | bool is_exact_; |
| 303 | }; |
| 304 | |
| 305 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 306 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 307 | class HandleCache { |
| 308 | public: |
| 309 | explicit HandleCache(VariableSizedHandleScope* handles) : handles_(handles) { } |
| 310 | |
| 311 | VariableSizedHandleScope* GetHandles() { return handles_; } |
| 312 | |
| 313 | template <typename T> |
| 314 | MutableHandle<T> NewHandle(T* object) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 315 | return handles_->NewHandle(object); |
| 316 | } |
| 317 | |
| 318 | template <typename T> |
| 319 | MutableHandle<T> NewHandle(ObjPtr<T> object) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 320 | return handles_->NewHandle(object); |
| 321 | } |
| 322 | |
| 323 | ReferenceTypeInfo::TypeHandle GetObjectClassHandle() { |
| 324 | return GetRootHandle(ClassRoot::kJavaLangObject, &object_class_handle_); |
| 325 | } |
| 326 | |
| 327 | ReferenceTypeInfo::TypeHandle GetClassClassHandle() { |
| 328 | return GetRootHandle(ClassRoot::kJavaLangClass, &class_class_handle_); |
| 329 | } |
| 330 | |
| 331 | ReferenceTypeInfo::TypeHandle GetMethodHandleClassHandle() { |
| 332 | return GetRootHandle(ClassRoot::kJavaLangInvokeMethodHandleImpl, &method_handle_class_handle_); |
| 333 | } |
| 334 | |
| 335 | ReferenceTypeInfo::TypeHandle GetMethodTypeClassHandle() { |
| 336 | return GetRootHandle(ClassRoot::kJavaLangInvokeMethodType, &method_type_class_handle_); |
| 337 | } |
| 338 | |
| 339 | ReferenceTypeInfo::TypeHandle GetStringClassHandle() { |
| 340 | return GetRootHandle(ClassRoot::kJavaLangString, &string_class_handle_); |
| 341 | } |
| 342 | |
| 343 | ReferenceTypeInfo::TypeHandle GetThrowableClassHandle() { |
| 344 | return GetRootHandle(ClassRoot::kJavaLangThrowable, &throwable_class_handle_); |
| 345 | } |
| 346 | |
| 347 | |
| 348 | private: |
| 349 | inline ReferenceTypeInfo::TypeHandle GetRootHandle(ClassRoot class_root, |
| 350 | ReferenceTypeInfo::TypeHandle* cache) { |
| 351 | if (UNLIKELY(!ReferenceTypeInfo::IsValidHandle(*cache))) { |
| 352 | *cache = CreateRootHandle(handles_, class_root); |
| 353 | } |
| 354 | return *cache; |
| 355 | } |
| 356 | |
| 357 | static ReferenceTypeInfo::TypeHandle CreateRootHandle(VariableSizedHandleScope* handles, |
| 358 | ClassRoot class_root); |
| 359 | |
| 360 | VariableSizedHandleScope* handles_; |
| 361 | |
| 362 | ReferenceTypeInfo::TypeHandle object_class_handle_; |
| 363 | ReferenceTypeInfo::TypeHandle class_class_handle_; |
| 364 | ReferenceTypeInfo::TypeHandle method_handle_class_handle_; |
| 365 | ReferenceTypeInfo::TypeHandle method_type_class_handle_; |
| 366 | ReferenceTypeInfo::TypeHandle string_class_handle_; |
| 367 | ReferenceTypeInfo::TypeHandle throwable_class_handle_; |
| 368 | }; |
| 369 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 370 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 371 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 372 | public: |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 373 | HGraph(ArenaAllocator* allocator, |
| 374 | ArenaStack* arena_stack, |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 375 | VariableSizedHandleScope* handles, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 376 | const DexFile& dex_file, |
| 377 | uint32_t method_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 378 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 379 | InvokeType invoke_type = kInvalidInvokeType, |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 380 | bool dead_reference_safe = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 381 | bool debuggable = false, |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 382 | CompilationKind compilation_kind = CompilationKind::kOptimized, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 383 | int start_instruction_id = 0) |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 384 | : allocator_(allocator), |
| 385 | arena_stack_(arena_stack), |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 386 | handle_cache_(handles), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 387 | blocks_(allocator->Adapter(kArenaAllocBlockList)), |
| 388 | reverse_post_order_(allocator->Adapter(kArenaAllocReversePostOrder)), |
| 389 | linear_order_(allocator->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 390 | entry_block_(nullptr), |
| 391 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 392 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 393 | number_of_vregs_(0), |
| 394 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 395 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 396 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 397 | has_try_catch_(false), |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 398 | has_monitor_operations_(false), |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 399 | has_simd_(false), |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 400 | has_loops_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 401 | has_irreducible_loops_(false), |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 402 | has_direct_critical_native_call_(false), |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 403 | dead_reference_safe_(dead_reference_safe), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 404 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 405 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 406 | dex_file_(dex_file), |
| 407 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 408 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 409 | in_ssa_form_(false), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 410 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 411 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 412 | cached_null_constant_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 413 | cached_int_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 414 | cached_float_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 415 | cached_long_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 416 | cached_double_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 417 | cached_current_method_(nullptr), |
Nicolas Geoffray | 53fec08 | 2017-03-27 12:56:16 +0100 | [diff] [blame] | 418 | art_method_(nullptr), |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 419 | compilation_kind_(compilation_kind), |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 420 | cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 421 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 422 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 423 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 424 | ArenaAllocator* GetAllocator() const { return allocator_; } |
| 425 | ArenaStack* GetArenaStack() const { return arena_stack_; } |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 426 | |
| 427 | HandleCache* GetHandleCache() { return &handle_cache_; } |
| 428 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 429 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 430 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 431 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 432 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 433 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 434 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 435 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 436 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 437 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 438 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 439 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 440 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 441 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 442 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 443 | void ComputeDominanceInformation(); |
| 444 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 445 | void ClearLoopInformation(); |
| 446 | void FindBackEdges(ArenaBitVector* visited); |
| 447 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 448 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 449 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 450 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 451 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 452 | // 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] | 453 | // 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] | 454 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 455 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 456 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 457 | // order and loop information. |
| 458 | void ComputeTryBlockInformation(); |
| 459 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 460 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 461 | // Returns the instruction to replace the invoke expression or null if the |
| 462 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 463 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 464 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 465 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 466 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 467 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 468 | // should be the new back edge. |
| 469 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 470 | HBasicBlock* reference, |
| 471 | bool replace_if_back_edge); |
| 472 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 473 | // Need to add a couple of blocks to test if the loop body is entered and |
| 474 | // put deoptimization instructions, etc. |
| 475 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 476 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 477 | // Adds a new loop directly after the loop with the given header and exit. |
| 478 | // Returns the new preheader. |
| 479 | HBasicBlock* TransformLoopForVectorization(HBasicBlock* header, |
| 480 | HBasicBlock* body, |
| 481 | HBasicBlock* exit); |
| 482 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 483 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 484 | // other blocks and has no instructions or phis. |
| 485 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 486 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 487 | // Splits the edge between `block` and `successor` while preserving the |
| 488 | // indices in the predecessor/successor lists. If there are multiple edges |
| 489 | // between the blocks, the lowest indices are used. |
| 490 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 491 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 492 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 493 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
Artem Serov | c73ee37 | 2017-07-31 15:08:40 +0100 | [diff] [blame] | 494 | void OrderLoopHeaderPredecessors(HBasicBlock* header); |
Artem Serov | 09faaea | 2017-12-07 14:36:01 +0000 | [diff] [blame] | 495 | |
| 496 | // Transform a loop into a format with a single preheader. |
| 497 | // |
| 498 | // Each phi in the header should be split: original one in the header should only hold |
| 499 | // inputs reachable from the back edges and a single input from the preheader. The newly created |
| 500 | // phi in the preheader should collate the inputs from the original multiple incoming blocks. |
| 501 | // |
| 502 | // Loops in the graph typically have a single preheader, so this method is used to "repair" loops |
| 503 | // that no longer have this property. |
| 504 | void TransformLoopToSinglePreheaderFormat(HBasicBlock* header); |
| 505 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 506 | void SimplifyLoop(HBasicBlock* header); |
| 507 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 508 | int32_t GetNextInstructionId() { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 509 | CHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 510 | return current_instruction_id_++; |
| 511 | } |
| 512 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 513 | int32_t GetCurrentInstructionId() const { |
| 514 | return current_instruction_id_; |
| 515 | } |
| 516 | |
| 517 | void SetCurrentInstructionId(int32_t id) { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 518 | CHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 519 | current_instruction_id_ = id; |
| 520 | } |
| 521 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 522 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 523 | return maximum_number_of_out_vregs_; |
| 524 | } |
| 525 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 526 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 527 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 528 | } |
| 529 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 530 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 531 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 532 | } |
| 533 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 534 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 535 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 536 | } |
| 537 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 538 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 539 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 540 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 541 | } |
| 542 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 543 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 544 | number_of_vregs_ = number_of_vregs; |
| 545 | } |
| 546 | |
| 547 | uint16_t GetNumberOfVRegs() const { |
| 548 | return number_of_vregs_; |
| 549 | } |
| 550 | |
| 551 | void SetNumberOfInVRegs(uint16_t value) { |
| 552 | number_of_in_vregs_ = value; |
| 553 | } |
| 554 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 555 | uint16_t GetNumberOfInVRegs() const { |
| 556 | return number_of_in_vregs_; |
| 557 | } |
| 558 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 559 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 560 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 561 | return number_of_vregs_ - number_of_in_vregs_; |
| 562 | } |
| 563 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 564 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 565 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 566 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 567 | |
Eric Holk | 1868de9 | 2020-02-12 09:10:21 -0800 | [diff] [blame] | 568 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() const { |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 569 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 570 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 571 | } |
| 572 | |
| 573 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 574 | return ReverseRange(GetReversePostOrder()); |
| 575 | } |
| 576 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 577 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 578 | return linear_order_; |
| 579 | } |
| 580 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 581 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 582 | return ReverseRange(GetLinearOrder()); |
| 583 | } |
| 584 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 585 | bool HasBoundsChecks() const { |
| 586 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 587 | } |
| 588 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 589 | void SetHasBoundsChecks(bool value) { |
| 590 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 591 | } |
| 592 | |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 593 | // Is the code known to be robust against eliminating dead references |
| 594 | // and the effects of early finalization? |
| 595 | bool IsDeadReferenceSafe() const { return dead_reference_safe_; } |
| 596 | |
| 597 | void MarkDeadReferenceUnsafe() { dead_reference_safe_ = false; } |
| 598 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 599 | bool IsDebuggable() const { return debuggable_; } |
| 600 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 601 | // 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] | 602 | // already, it is created and inserted into the graph. This method is only for |
| 603 | // integral types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 604 | 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] | 605 | |
| 606 | // TODO: This is problematic for the consistency of reference type propagation |
| 607 | // because it can be created anytime after the pass and thus it will be left |
| 608 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 609 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 610 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 611 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 612 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 613 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 614 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 615 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 616 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 617 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 618 | 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] | 619 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 620 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 621 | 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] | 622 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 623 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 624 | HCurrentMethod* GetCurrentMethod(); |
| 625 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 626 | const DexFile& GetDexFile() const { |
| 627 | return dex_file_; |
| 628 | } |
| 629 | |
| 630 | uint32_t GetMethodIdx() const { |
| 631 | return method_idx_; |
| 632 | } |
| 633 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 634 | // Get the method name (without the signature), e.g. "<init>" |
| 635 | const char* GetMethodName() const; |
| 636 | |
| 637 | // Get the pretty method name (class + name + optionally signature). |
| 638 | std::string PrettyMethod(bool with_signature = true) const; |
| 639 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 640 | InvokeType GetInvokeType() const { |
| 641 | return invoke_type_; |
| 642 | } |
| 643 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 644 | InstructionSet GetInstructionSet() const { |
| 645 | return instruction_set_; |
| 646 | } |
| 647 | |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 648 | bool IsCompilingOsr() const { return compilation_kind_ == CompilationKind::kOsr; } |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 649 | |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 650 | bool IsCompilingBaseline() const { return compilation_kind_ == CompilationKind::kBaseline; } |
| 651 | |
| 652 | CompilationKind GetCompilationKind() const { return compilation_kind_; } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 653 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 654 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 655 | return cha_single_implementation_list_; |
| 656 | } |
| 657 | |
| 658 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 659 | cha_single_implementation_list_.insert(method); |
| 660 | } |
| 661 | |
| 662 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 663 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 664 | } |
| 665 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 666 | bool HasTryCatch() const { return has_try_catch_; } |
| 667 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 668 | |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 669 | bool HasMonitorOperations() const { return has_monitor_operations_; } |
| 670 | void SetHasMonitorOperations(bool value) { has_monitor_operations_ = value; } |
| 671 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 672 | bool HasSIMD() const { return has_simd_; } |
| 673 | void SetHasSIMD(bool value) { has_simd_ = value; } |
| 674 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 675 | bool HasLoops() const { return has_loops_; } |
| 676 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 677 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 678 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 679 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 680 | |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 681 | bool HasDirectCriticalNativeCall() const { return has_direct_critical_native_call_; } |
| 682 | void SetHasDirectCriticalNativeCall(bool value) { has_direct_critical_native_call_ = value; } |
| 683 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 684 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 685 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 686 | |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 687 | // Returns an instruction with the opposite Boolean value from 'cond'. |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 688 | // The instruction has been inserted into the graph, either as a constant, or |
| 689 | // before cursor. |
| 690 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 691 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 692 | ReferenceTypeInfo GetInexactObjectRti() { |
| 693 | return ReferenceTypeInfo::Create(handle_cache_.GetObjectClassHandle(), /* is_exact= */ false); |
| 694 | } |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 695 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 696 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 697 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 698 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 699 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 700 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 701 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 702 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 703 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 704 | template <class InstructionType, typename ValueType> |
| 705 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 706 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 707 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 708 | // Try to find an existing constant of the given value. |
| 709 | InstructionType* constant = nullptr; |
| 710 | auto cached_constant = cache->find(value); |
| 711 | if (cached_constant != cache->end()) { |
| 712 | constant = cached_constant->second; |
| 713 | } |
| 714 | |
| 715 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 716 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 717 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 718 | constant = new (allocator_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 719 | cache->Overwrite(value, constant); |
| 720 | InsertConstant(constant); |
| 721 | } |
| 722 | return constant; |
| 723 | } |
| 724 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 725 | void InsertConstant(HConstant* instruction); |
| 726 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 727 | // Cache a float constant into the graph. This method should only be |
| 728 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 729 | void CacheFloatConstant(HFloatConstant* constant); |
| 730 | |
| 731 | // See CacheFloatConstant comment. |
| 732 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 733 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 734 | ArenaAllocator* const allocator_; |
| 735 | ArenaStack* const arena_stack_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 736 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 737 | HandleCache handle_cache_; |
| 738 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 739 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 740 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 741 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 742 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 743 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 744 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 745 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 746 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 747 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 748 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 749 | HBasicBlock* entry_block_; |
| 750 | HBasicBlock* exit_block_; |
| 751 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 752 | // 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] | 753 | uint16_t maximum_number_of_out_vregs_; |
| 754 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 755 | // The number of virtual registers in this method. Contains the parameters. |
| 756 | uint16_t number_of_vregs_; |
| 757 | |
| 758 | // The number of virtual registers used by parameters of this method. |
| 759 | uint16_t number_of_in_vregs_; |
| 760 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 761 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 762 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 763 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 764 | // Flag whether there are bounds checks in the graph. We can skip |
| 765 | // BCE if it's false. It's only best effort to keep it up to date in |
| 766 | // the presence of code elimination so there might be false positives. |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 767 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 768 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 769 | // Flag whether there are try/catch blocks in the graph. We will skip |
| 770 | // try/catch-related passes if it's false. It's only best effort to keep |
| 771 | // it up to date in the presence of code elimination so there might be |
| 772 | // false positives. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 773 | bool has_try_catch_; |
| 774 | |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 775 | // Flag whether there are any HMonitorOperation in the graph. If yes this will mandate |
| 776 | // DexRegisterMap to be present to allow deadlock analysis for non-debuggable code. |
| 777 | bool has_monitor_operations_; |
| 778 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 779 | // Flag whether SIMD instructions appear in the graph. If true, the |
| 780 | // code generators may have to be more careful spilling the wider |
| 781 | // contents of SIMD registers. |
| 782 | bool has_simd_; |
| 783 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 784 | // Flag whether there are any loops in the graph. We can skip loop |
| 785 | // optimization if it's false. It's only best effort to keep it up |
| 786 | // to date in the presence of code elimination so there might be false |
| 787 | // positives. |
| 788 | bool has_loops_; |
| 789 | |
| 790 | // Flag whether there are any irreducible loops in the graph. It's only |
| 791 | // best effort to keep it up to date in the presence of code elimination |
| 792 | // so there might be false positives. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 793 | bool has_irreducible_loops_; |
| 794 | |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 795 | // Flag whether there are any direct calls to native code registered |
| 796 | // for @CriticalNative methods. |
| 797 | bool has_direct_critical_native_call_; |
| 798 | |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 799 | // Is the code known to be robust against eliminating dead references |
| 800 | // and the effects of early finalization? If false, dead reference variables |
| 801 | // are kept if they might be visible to the garbage collector. |
| 802 | // Currently this means that the class was declared to be dead-reference-safe, |
| 803 | // the method accesses no reachability-sensitive fields or data, and the same |
| 804 | // is true for any methods that were inlined into the current one. |
| 805 | bool dead_reference_safe_; |
| 806 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 807 | // Indicates whether the graph should be compiled in a way that |
| 808 | // ensures full debuggability. If false, we can apply more |
| 809 | // aggressive optimizations that may limit the level of debugging. |
| 810 | const bool debuggable_; |
| 811 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 812 | // 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] | 813 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 814 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 815 | // The dex file from which the method is from. |
| 816 | const DexFile& dex_file_; |
| 817 | |
| 818 | // The method index in the dex file. |
| 819 | const uint32_t method_idx_; |
| 820 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 821 | // If inlined, this encodes how the callee is being invoked. |
| 822 | const InvokeType invoke_type_; |
| 823 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 824 | // Whether the graph has been transformed to SSA form. Only used |
| 825 | // in debug mode to ensure we are not using properties only valid |
| 826 | // for non-SSA form (like the number of temporaries). |
| 827 | bool in_ssa_form_; |
| 828 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 829 | // Number of CHA guards in the graph. Used to short-circuit the |
| 830 | // CHA guard optimization pass when there is no CHA guard left. |
| 831 | uint32_t number_of_cha_guards_; |
| 832 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 833 | const InstructionSet instruction_set_; |
| 834 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 835 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 836 | HNullConstant* cached_null_constant_; |
| 837 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 838 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 839 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 840 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 841 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 842 | HCurrentMethod* cached_current_method_; |
| 843 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 844 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 845 | // for example for methods whose declaring class could not be resolved |
| 846 | // (such as when the superclass could not be found). |
| 847 | ArtMethod* art_method_; |
| 848 | |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 849 | // How we are compiling the graph: either optimized, osr, or baseline. |
| 850 | // For osr, we will make all loops seen as irreducible and emit special |
| 851 | // stack maps to mark compiled code entries which the interpreter can |
| 852 | // directly jump to. |
| 853 | const CompilationKind compilation_kind_; |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 854 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 855 | // List of methods that are assumed to have single implementation. |
| 856 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 857 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 858 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 859 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 860 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 861 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 862 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 863 | }; |
| 864 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 865 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 866 | public: |
| 867 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 868 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 869 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 870 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 871 | contains_irreducible_loop_(false), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 872 | back_edges_(graph->GetAllocator()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 873 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 874 | blocks_(graph->GetAllocator(), |
| 875 | graph->GetBlocks().size(), |
| 876 | true, |
| 877 | kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 878 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 879 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 880 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 881 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 882 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 883 | |
| 884 | void Dump(std::ostream& os); |
| 885 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 886 | HBasicBlock* GetHeader() const { |
| 887 | return header_; |
| 888 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 889 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 890 | void SetHeader(HBasicBlock* block) { |
| 891 | header_ = block; |
| 892 | } |
| 893 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 894 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 895 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 896 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 897 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 898 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 899 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 902 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 903 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 904 | } |
| 905 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 906 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 907 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 908 | } |
| 909 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 910 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 911 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 914 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 915 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 916 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 917 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 918 | } |
| 919 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 920 | // Returns the lifetime position of the back edge that has the |
| 921 | // greatest lifetime position. |
| 922 | size_t GetLifetimeEnd() const; |
| 923 | |
| 924 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 925 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 926 | } |
| 927 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 928 | // Finds blocks that are part of this loop. |
| 929 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 930 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 931 | // Updates blocks population of the loop and all of its outer' ones recursively after the |
| 932 | // population of the inner loop is updated. |
| 933 | void PopulateInnerLoopUpwards(HLoopInformation* inner_loop); |
| 934 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 935 | // Returns whether this loop information contains `block`. |
| 936 | // Note that this loop information *must* be populated before entering this function. |
| 937 | bool Contains(const HBasicBlock& block) const; |
| 938 | |
| 939 | // Returns whether this loop information is an inner loop of `other`. |
| 940 | // Note that `other` *must* be populated before entering this function. |
| 941 | bool IsIn(const HLoopInformation& other) const; |
| 942 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 943 | // Returns true if instruction is not defined within this loop. |
| 944 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 945 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 946 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 947 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 948 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 949 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 950 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 951 | void ClearAllBlocks() { |
| 952 | blocks_.ClearAllBits(); |
| 953 | } |
| 954 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 955 | bool HasBackEdgeNotDominatedByHeader() const; |
| 956 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 957 | bool IsPopulated() const { |
| 958 | return blocks_.GetHighestBitSet() != -1; |
| 959 | } |
| 960 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 961 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 962 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 963 | bool HasExitEdge() const; |
| 964 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 965 | // Resets back edge and blocks-in-loop data. |
| 966 | void ResetBasicBlockData() { |
| 967 | back_edges_.clear(); |
| 968 | ClearAllBlocks(); |
| 969 | } |
| 970 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 971 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 972 | // Internal recursive implementation of `Populate`. |
| 973 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 974 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 975 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 976 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 977 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 978 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 979 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 980 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 981 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 982 | |
| 983 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 984 | }; |
| 985 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 986 | // Stores try/catch information for basic blocks. |
| 987 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 988 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 989 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 990 | public: |
| 991 | // Try block information constructor. |
| 992 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 993 | : try_entry_(&try_entry), |
| 994 | catch_dex_file_(nullptr), |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 995 | catch_type_index_(dex::TypeIndex::Invalid()) { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 996 | DCHECK(try_entry_ != nullptr); |
| 997 | } |
| 998 | |
| 999 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1000 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1001 | : try_entry_(nullptr), |
| 1002 | catch_dex_file_(&dex_file), |
| 1003 | catch_type_index_(catch_type_index) {} |
| 1004 | |
| 1005 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 1006 | |
| 1007 | const HTryBoundary& GetTryEntry() const { |
| 1008 | DCHECK(IsTryBlock()); |
| 1009 | return *try_entry_; |
| 1010 | } |
| 1011 | |
| 1012 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 1013 | |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1014 | bool IsValidTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1015 | DCHECK(IsCatchBlock()); |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1016 | return catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1017 | } |
| 1018 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1019 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1020 | DCHECK(IsCatchBlock()); |
| 1021 | return catch_type_index_; |
| 1022 | } |
| 1023 | |
| 1024 | const DexFile& GetCatchDexFile() const { |
| 1025 | DCHECK(IsCatchBlock()); |
| 1026 | return *catch_dex_file_; |
| 1027 | } |
| 1028 | |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1029 | void SetInvalidTypeIndex() { |
| 1030 | catch_type_index_ = dex::TypeIndex::Invalid(); |
| 1031 | } |
| 1032 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1033 | private: |
| 1034 | // One of possibly several TryBoundary instructions entering the block's try. |
| 1035 | // Only set for try blocks. |
| 1036 | const HTryBoundary* try_entry_; |
| 1037 | |
| 1038 | // Exception type information. Only set for catch blocks. |
| 1039 | const DexFile* catch_dex_file_; |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1040 | dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1041 | }; |
| 1042 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1043 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1044 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1045 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1046 | // A block in a method. Contains the list of instructions represented |
| 1047 | // as a double linked list. Each block knows its predecessors and |
| 1048 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1049 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1050 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1051 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 1052 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1053 | : graph_(graph), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1054 | predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), |
| 1055 | successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1056 | loop_information_(nullptr), |
| 1057 | dominator_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1058 | dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1059 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1060 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1061 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1062 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1063 | try_catch_information_(nullptr) { |
| 1064 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 1065 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 1066 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 1067 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1068 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1069 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1070 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1073 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1074 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 1077 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 1078 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 1079 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1080 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 1081 | return ContainsElement(successors_, block, start_from); |
| 1082 | } |
| 1083 | |
| 1084 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1085 | return dominated_blocks_; |
| 1086 | } |
| 1087 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1088 | bool IsEntryBlock() const { |
| 1089 | return graph_->GetEntryBlock() == this; |
| 1090 | } |
| 1091 | |
| 1092 | bool IsExitBlock() const { |
| 1093 | return graph_->GetExitBlock() == this; |
| 1094 | } |
| 1095 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1096 | bool IsSingleGoto() const; |
Mads Ager | 16e5289 | 2017-07-14 13:11:37 +0200 | [diff] [blame] | 1097 | bool IsSingleReturn() const; |
Mingyao Yang | 46721ef | 2017-10-05 14:45:17 -0700 | [diff] [blame] | 1098 | bool IsSingleReturnOrReturnVoidAllowingPhis() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1099 | bool IsSingleTryBoundary() const; |
| 1100 | |
| 1101 | // Returns true if this block emits nothing but a jump. |
| 1102 | bool IsSingleJump() const { |
| 1103 | HLoopInformation* loop_info = GetLoopInformation(); |
| 1104 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 1105 | // Back edges generate a suspend check. |
| 1106 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 1107 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1108 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1109 | void AddBackEdge(HBasicBlock* back_edge) { |
| 1110 | if (loop_information_ == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1111 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1112 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1113 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1114 | loop_information_->AddBackEdge(back_edge); |
| 1115 | } |
| 1116 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 1117 | // Registers a back edge; if the block was not a loop header before the call associates a newly |
| 1118 | // created loop info with it. |
| 1119 | // |
| 1120 | // Used in SuperblockCloner to preserve LoopInformation object instead of reseting loop |
| 1121 | // info for all blocks during back edges recalculation. |
| 1122 | void AddBackEdgeWhileUpdating(HBasicBlock* back_edge) { |
| 1123 | if (loop_information_ == nullptr || loop_information_->GetHeader() != this) { |
| 1124 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
| 1125 | } |
| 1126 | loop_information_->AddBackEdge(back_edge); |
| 1127 | } |
| 1128 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1129 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1130 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1131 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1132 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1133 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1134 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1135 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1136 | HBasicBlock* GetDominator() const { return dominator_; } |
| 1137 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1138 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 1139 | |
| 1140 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 1141 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 1142 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1143 | |
| 1144 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1145 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 1146 | } |
| 1147 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1148 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1149 | |
| 1150 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1151 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1154 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1155 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1156 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1157 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1158 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1159 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1160 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1161 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1162 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1163 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1164 | successors_.push_back(block); |
| 1165 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1168 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1169 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1170 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1171 | new_block->predecessors_.push_back(this); |
| 1172 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1175 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1176 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1177 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1178 | new_block->successors_.push_back(this); |
| 1179 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1182 | // Insert `this` between `predecessor` and `successor. This method |
Alex Light | 1e52a07 | 2019-06-25 09:12:04 -0700 | [diff] [blame] | 1183 | // preserves the indices, and will update the first edge found between |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1184 | // `predecessor` and `successor`. |
| 1185 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1186 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1187 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1188 | successor->predecessors_[predecessor_index] = this; |
| 1189 | predecessor->successors_[successor_index] = this; |
| 1190 | successors_.push_back(successor); |
| 1191 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1192 | } |
| 1193 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1194 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1195 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1198 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1199 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1202 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1203 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1207 | predecessors_.push_back(block); |
| 1208 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1209 | } |
| 1210 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1211 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1212 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1213 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1214 | } |
| 1215 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1216 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1217 | DCHECK_EQ(successors_.size(), 2u); |
| 1218 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1219 | } |
| 1220 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1221 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1222 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1223 | } |
| 1224 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1225 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1226 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1227 | } |
| 1228 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1229 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1230 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1231 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1235 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1236 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1240 | // predecessors is at index `idx`. |
| 1241 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1242 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1243 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1244 | } |
| 1245 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1246 | // Create a new block between this block and its predecessors. The new block |
| 1247 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1248 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1249 | // loop and try/catch information are not updated. |
| 1250 | HBasicBlock* CreateImmediateDominator(); |
| 1251 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1252 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1253 | // created, latter block. Note that this method will add the block to the |
| 1254 | // graph, create a Goto at the end of the former block and will create an edge |
| 1255 | // 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] | 1256 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1257 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1258 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1259 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1260 | // created block. Note that this method just updates raw block information, |
| 1261 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1262 | // update the graph, reverse post order, loop information, nor make sure the |
| 1263 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1264 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1265 | |
| 1266 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1267 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1268 | |
| 1269 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1270 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1271 | // that this method does not update the graph, reverse post order, loop |
| 1272 | // information, nor make sure the blocks are consistent (for example ending |
| 1273 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1274 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1275 | |
| 1276 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1277 | // of `this` are moved to `other`. |
| 1278 | // Note that this method does not update the graph, reverse post order, loop |
| 1279 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1280 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1281 | void ReplaceWith(HBasicBlock* other); |
| 1282 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1283 | // Merges the instructions of `other` at the end of `this`. |
| 1284 | void MergeInstructionsWith(HBasicBlock* other); |
| 1285 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1286 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1287 | // order, links to predecessors, successors, dominators and deletes the block |
| 1288 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1289 | // predecessor of `other` and vice versa. |
| 1290 | void MergeWith(HBasicBlock* other); |
| 1291 | |
| 1292 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1293 | // removes it from all loops it is included in and eventually from the graph. |
| 1294 | // The block must not dominate any other block. Predecessors and successors |
| 1295 | // are safely updated. |
| 1296 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1297 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1298 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1299 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1300 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1301 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1302 | // Replace phi `initial` with `replacement` within this block. |
| 1303 | void ReplaceAndRemovePhiWith(HPhi* initial, HPhi* replacement); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1304 | // Replace instruction `initial` with `replacement` within this block. |
| 1305 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1306 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1307 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1308 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1309 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1310 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1311 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1312 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1313 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1314 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1315 | |
| 1316 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1317 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1318 | } |
| 1319 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1320 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1321 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1322 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1323 | } |
| 1324 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1325 | bool IsFirstPredecessorBackEdge() const { |
| 1326 | DCHECK(IsLoopHeader()); |
| 1327 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1328 | } |
| 1329 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1330 | HLoopInformation* GetLoopInformation() const { |
| 1331 | return loop_information_; |
| 1332 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1333 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1334 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1335 | // 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] | 1336 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1337 | void SetInLoop(HLoopInformation* info) { |
| 1338 | if (IsLoopHeader()) { |
| 1339 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1340 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1341 | loop_information_ = info; |
| 1342 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1343 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1344 | // Note that a non loop header having a loop information means this loop information |
| 1345 | // has already been populated |
| 1346 | loop_information_ = info; |
| 1347 | } else { |
| 1348 | // Block is part of an inner loop. Do not update the loop information. |
| 1349 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1350 | // at this point, because this method is being called while populating `info`. |
| 1351 | } |
| 1352 | } |
| 1353 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1354 | // Raw update of the loop information. |
| 1355 | void SetLoopInformation(HLoopInformation* info) { |
| 1356 | loop_information_ = info; |
| 1357 | } |
| 1358 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1359 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1360 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1361 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1362 | |
| 1363 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1364 | try_catch_information_ = try_catch_information; |
| 1365 | } |
| 1366 | |
| 1367 | bool IsTryBlock() const { |
| 1368 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1369 | } |
| 1370 | |
| 1371 | bool IsCatchBlock() const { |
| 1372 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1373 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1374 | |
| 1375 | // Returns the try entry that this block's successors should have. They will |
| 1376 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1377 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1378 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1379 | |
Aart Bik | 75ff2c9 | 2018-04-21 01:28:11 +0000 | [diff] [blame] | 1380 | bool HasThrowingInstructions() const; |
| 1381 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1382 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1383 | bool Dominates(HBasicBlock* block) const; |
| 1384 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1385 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1386 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1387 | |
| 1388 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1389 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1390 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1391 | bool EndsWithControlFlowInstruction() const; |
Aart Bik | 4dc09e7 | 2018-05-11 14:40:31 -0700 | [diff] [blame] | 1392 | bool EndsWithReturn() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1393 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1394 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1395 | bool HasSinglePhi() const; |
| 1396 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1397 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1398 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1399 | ArenaVector<HBasicBlock*> predecessors_; |
| 1400 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1401 | HInstructionList instructions_; |
| 1402 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1403 | HLoopInformation* loop_information_; |
| 1404 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1405 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1406 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1407 | // The dex program counter of the first instruction of this block. |
| 1408 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1409 | size_t lifetime_start_; |
| 1410 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1411 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1412 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1413 | friend class HGraph; |
| 1414 | friend class HInstruction; |
| 1415 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1416 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1417 | }; |
| 1418 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1419 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1420 | // from the innermost to the outermost. |
| 1421 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1422 | public: |
| 1423 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1424 | : current_(block.GetLoopInformation()) {} |
| 1425 | |
| 1426 | bool Done() const { return current_ == nullptr; } |
| 1427 | |
| 1428 | void Advance() { |
| 1429 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1430 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | HLoopInformation* Current() const { |
| 1434 | DCHECK(!Done()); |
| 1435 | return current_; |
| 1436 | } |
| 1437 | |
| 1438 | private: |
| 1439 | HLoopInformation* current_; |
| 1440 | |
| 1441 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1442 | }; |
| 1443 | |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1444 | #define FOR_EACH_CONCRETE_INSTRUCTION_SCALAR_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1445 | M(Above, Condition) \ |
| 1446 | M(AboveOrEqual, Condition) \ |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 1447 | M(Abs, UnaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1448 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1449 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1450 | M(ArrayGet, Instruction) \ |
| 1451 | M(ArrayLength, Instruction) \ |
| 1452 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1453 | M(Below, Condition) \ |
| 1454 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1455 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1456 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1457 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1458 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1459 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1460 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1461 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1462 | M(Compare, BinaryOperation) \ |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1463 | M(ConstructorFence, Instruction) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1464 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1465 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1466 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1467 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1468 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1469 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1470 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1471 | M(Exit, Instruction) \ |
| 1472 | M(FloatConstant, Constant) \ |
| 1473 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1474 | M(GreaterThan, Condition) \ |
| 1475 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1476 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1477 | M(InstanceFieldGet, Instruction) \ |
| 1478 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1479 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1480 | M(IntConstant, Constant) \ |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 1481 | M(IntermediateAddress, Instruction) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1482 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1483 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1484 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1485 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1486 | M(InvokePolymorphic, Invoke) \ |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1487 | M(InvokeCustom, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1488 | M(LessThan, Condition) \ |
| 1489 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1490 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1491 | M(LoadException, Instruction) \ |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 1492 | M(LoadMethodHandle, Instruction) \ |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 1493 | M(LoadMethodType, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1494 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1495 | M(LongConstant, Constant) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1496 | M(Max, Instruction) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1497 | M(MemoryBarrier, Instruction) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1498 | M(Min, BinaryOperation) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1499 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1500 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1501 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1502 | M(Neg, UnaryOperation) \ |
| 1503 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1504 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1505 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1506 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1507 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1508 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1509 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1510 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1511 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1512 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1513 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1514 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1515 | M(Return, Instruction) \ |
| 1516 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1517 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1518 | M(Shl, BinaryOperation) \ |
| 1519 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1520 | M(StaticFieldGet, Instruction) \ |
| 1521 | M(StaticFieldSet, Instruction) \ |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 1522 | M(StringBuilderAppend, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1523 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1524 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1525 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1526 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1527 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1528 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1529 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1530 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1531 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1532 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1533 | M(UShr, BinaryOperation) \ |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1534 | M(Xor, BinaryOperation) |
| 1535 | |
| 1536 | #define FOR_EACH_CONCRETE_INSTRUCTION_VECTOR_COMMON(M) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1537 | M(VecReplicateScalar, VecUnaryOperation) \ |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1538 | M(VecExtractScalar, VecUnaryOperation) \ |
| 1539 | M(VecReduce, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1540 | M(VecCnv, VecUnaryOperation) \ |
| 1541 | M(VecNeg, VecUnaryOperation) \ |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1542 | M(VecAbs, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1543 | M(VecNot, VecUnaryOperation) \ |
| 1544 | M(VecAdd, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1545 | M(VecHalvingAdd, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1546 | M(VecSub, VecBinaryOperation) \ |
| 1547 | M(VecMul, VecBinaryOperation) \ |
| 1548 | M(VecDiv, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1549 | M(VecMin, VecBinaryOperation) \ |
| 1550 | M(VecMax, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1551 | M(VecAnd, VecBinaryOperation) \ |
| 1552 | M(VecAndNot, VecBinaryOperation) \ |
| 1553 | M(VecOr, VecBinaryOperation) \ |
| 1554 | M(VecXor, VecBinaryOperation) \ |
Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1555 | M(VecSaturationAdd, VecBinaryOperation) \ |
| 1556 | M(VecSaturationSub, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1557 | M(VecShl, VecBinaryOperation) \ |
| 1558 | M(VecShr, VecBinaryOperation) \ |
| 1559 | M(VecUShr, VecBinaryOperation) \ |
Aart Bik | 8de5916 | 2017-04-21 09:42:01 -0700 | [diff] [blame] | 1560 | M(VecSetScalars, VecOperation) \ |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1561 | M(VecMultiplyAccumulate, VecOperation) \ |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1562 | M(VecSADAccumulate, VecOperation) \ |
Artem Serov | aaac0e3 | 2018-08-07 00:52:22 +0100 | [diff] [blame] | 1563 | M(VecDotProd, VecOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1564 | M(VecLoad, VecMemoryOperation) \ |
| 1565 | M(VecStore, VecMemoryOperation) \ |
Artem Serov | 0771884 | 2020-02-24 18:51:42 +0000 | [diff] [blame] | 1566 | M(VecPredSetAll, VecPredSetOperation) \ |
| 1567 | M(VecPredWhile, VecPredSetOperation) \ |
| 1568 | M(VecPredCondition, VecOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1569 | |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1570 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1571 | FOR_EACH_CONCRETE_INSTRUCTION_SCALAR_COMMON(M) \ |
| 1572 | FOR_EACH_CONCRETE_INSTRUCTION_VECTOR_COMMON(M) |
| 1573 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1574 | /* |
| 1575 | * Instructions, shared across several (not all) architectures. |
| 1576 | */ |
| 1577 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1578 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1579 | #else |
| 1580 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1581 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1582 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1583 | M(MultiplyAccumulate, Instruction) \ |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 1584 | M(IntermediateAddressIndex, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1585 | #endif |
| 1586 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1587 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1588 | |
| 1589 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1590 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1591 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1592 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1593 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1594 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1595 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1596 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1597 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1598 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1599 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1600 | |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 1601 | #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64) |
| 1602 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) \ |
Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 1603 | M(X86AndNot, Instruction) \ |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 1604 | M(X86MaskOrResetLeastSetBit, Instruction) |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 1605 | #else |
| 1606 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) |
| 1607 | #endif |
| 1608 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1609 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1610 | |
| 1611 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1612 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1613 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1614 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1615 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
| 1616 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 1617 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) \ |
| 1618 | FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1619 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1620 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1621 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1622 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1623 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1624 | M(BinaryOperation, Instruction) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1625 | M(Invoke, Instruction) \ |
| 1626 | M(VecOperation, Instruction) \ |
| 1627 | M(VecUnaryOperation, VecOperation) \ |
| 1628 | M(VecBinaryOperation, VecOperation) \ |
Artem Serov | 0771884 | 2020-02-24 18:51:42 +0000 | [diff] [blame] | 1629 | M(VecMemoryOperation, VecOperation) \ |
| 1630 | M(VecPredSetOperation, VecOperation) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1631 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1632 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1633 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1634 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1635 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1636 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1637 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1638 | #undef FORWARD_DECLARATION |
| 1639 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1640 | #define DECLARE_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1641 | private: \ |
| 1642 | H##type& operator=(const H##type&) = delete; \ |
| 1643 | public: \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1644 | const char* DebugName() const override { return #type; } \ |
| 1645 | HInstruction* Clone(ArenaAllocator* arena) const override { \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1646 | DCHECK(IsClonable()); \ |
| 1647 | return new (arena) H##type(*this->As##type()); \ |
| 1648 | } \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1649 | void Accept(HGraphVisitor* visitor) override |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1650 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1651 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1652 | private: \ |
| 1653 | H##type& operator=(const H##type&) = delete; \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 1654 | public: |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1655 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1656 | #define DEFAULT_COPY_CONSTRUCTOR(type) \ |
| 1657 | explicit H##type(const H##type& other) = default; |
| 1658 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1659 | template <typename T> |
Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 1660 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode>, |
| 1661 | public IntrusiveForwardListNode<HUseListNode<T>> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1662 | public: |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1663 | // Get the instruction which has this use as one of the inputs. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1664 | T GetUser() const { return user_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1665 | // Get the position of the input record that this use corresponds to. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1666 | size_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1667 | // Set the position of the input record that this use corresponds to. |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1668 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1669 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1670 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1671 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1672 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1673 | |
| 1674 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1675 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1676 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1677 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1678 | |
| 1679 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1680 | }; |
| 1681 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1682 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1683 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1684 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1685 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1686 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1687 | // by the used instructions. |
| 1688 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1689 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1690 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1691 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1692 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1693 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1694 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1695 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1696 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1697 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1698 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1702 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1703 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1704 | |
| 1705 | private: |
| 1706 | // Instruction used by the user. |
| 1707 | HInstruction* instruction_; |
| 1708 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1709 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1710 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1711 | }; |
| 1712 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1713 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1714 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1715 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1716 | struct HInputExtractor { |
| 1717 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1718 | return record.GetInstruction(); |
| 1719 | } |
| 1720 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1721 | return record.GetInstruction(); |
| 1722 | } |
| 1723 | }; |
| 1724 | |
| 1725 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1726 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1727 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1728 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1729 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1730 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1731 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1732 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1733 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1734 | * modify the value of a reference field read [although it may modify the |
| 1735 | * reference fetch prior to reading the field, which is represented by its own |
| 1736 | * write/read dependence]). The analysis makes conservative points-to |
| 1737 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1738 | * the same, and any reference read depends on any reference read without |
| 1739 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1740 | * |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1741 | * kDependsOnGCBit is defined in the following way: instructions with kDependsOnGCBit must not be |
| 1742 | * alive across the point where garbage collection might happen. |
| 1743 | * |
| 1744 | * Note: Instructions with kCanTriggerGCBit do not depend on each other. |
| 1745 | * |
| 1746 | * kCanTriggerGCBit must be used for instructions for which GC might happen on the path across |
| 1747 | * those instructions from the compiler perspective (between this instruction and the next one |
| 1748 | * in the IR). |
| 1749 | * |
| 1750 | * Note: Instructions which can cause GC only on a fatal slow path do not need |
| 1751 | * kCanTriggerGCBit as the execution never returns to the instruction next to the exceptional |
| 1752 | * one. However the execution may return to compiled code if there is a catch block in the |
| 1753 | * current method; for this purpose the TryBoundary exit instruction has kCanTriggerGCBit |
| 1754 | * set. |
| 1755 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1756 | * The internal representation uses 38-bit and is described in the table below. |
| 1757 | * The first line indicates the side effect, and for field/array accesses the |
| 1758 | * 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] | 1759 | * DataType::Type enum). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1760 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1761 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1762 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1763 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1764 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1765 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1766 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1767 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1768 | * |
| 1769 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1770 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1771 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1772 | class SideEffects : public ValueObject { |
| 1773 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1774 | SideEffects() : flags_(0) {} |
| 1775 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1776 | static SideEffects None() { |
| 1777 | return SideEffects(0); |
| 1778 | } |
| 1779 | |
| 1780 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1781 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1782 | } |
| 1783 | |
| 1784 | static SideEffects AllChanges() { |
| 1785 | return SideEffects(kAllChangeBits); |
| 1786 | } |
| 1787 | |
| 1788 | static SideEffects AllDependencies() { |
| 1789 | return SideEffects(kAllDependOnBits); |
| 1790 | } |
| 1791 | |
| 1792 | static SideEffects AllExceptGCDependency() { |
| 1793 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1794 | } |
| 1795 | |
| 1796 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1797 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1798 | } |
| 1799 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1800 | static SideEffects AllWrites() { |
| 1801 | return SideEffects(kAllWrites); |
| 1802 | } |
| 1803 | |
| 1804 | static SideEffects AllReads() { |
| 1805 | return SideEffects(kAllReads); |
| 1806 | } |
| 1807 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1808 | static SideEffects FieldWriteOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1809 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1810 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1811 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1812 | } |
| 1813 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1814 | static SideEffects ArrayWriteOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1815 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1816 | } |
| 1817 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1818 | static SideEffects FieldReadOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1819 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1820 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1821 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1824 | static SideEffects ArrayReadOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1825 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1828 | // Returns whether GC might happen across this instruction from the compiler perspective so |
| 1829 | // the next instruction in the IR would see that. |
| 1830 | // |
| 1831 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1832 | static SideEffects CanTriggerGC() { |
| 1833 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1834 | } |
| 1835 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1836 | // Returns whether the instruction must not be alive across a GC point. |
| 1837 | // |
| 1838 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1839 | static SideEffects DependsOnGC() { |
| 1840 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1841 | } |
| 1842 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1843 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1844 | SideEffects Union(SideEffects other) const { |
| 1845 | return SideEffects(flags_ | other.flags_); |
| 1846 | } |
| 1847 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1848 | SideEffects Exclusion(SideEffects other) const { |
| 1849 | return SideEffects(flags_ & ~other.flags_); |
| 1850 | } |
| 1851 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1852 | void Add(SideEffects other) { |
| 1853 | flags_ |= other.flags_; |
| 1854 | } |
| 1855 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1856 | bool Includes(SideEffects other) const { |
| 1857 | return (other.flags_ & flags_) == other.flags_; |
| 1858 | } |
| 1859 | |
| 1860 | bool HasSideEffects() const { |
| 1861 | return (flags_ & kAllChangeBits); |
| 1862 | } |
| 1863 | |
| 1864 | bool HasDependencies() const { |
| 1865 | return (flags_ & kAllDependOnBits); |
| 1866 | } |
| 1867 | |
| 1868 | // Returns true if there are no side effects or dependencies. |
| 1869 | bool DoesNothing() const { |
| 1870 | return flags_ == 0; |
| 1871 | } |
| 1872 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1873 | // Returns true if something is written. |
| 1874 | bool DoesAnyWrite() const { |
| 1875 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1876 | } |
| 1877 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1878 | // Returns true if something is read. |
| 1879 | bool DoesAnyRead() const { |
| 1880 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1881 | } |
| 1882 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1883 | // Returns true if potentially everything is written and read |
| 1884 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1885 | bool DoesAllReadWrite() const { |
| 1886 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1887 | } |
| 1888 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1889 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1890 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1893 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1894 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1895 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1896 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1900 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1901 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1902 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1903 | for (int s = kLastBit; s >= 0; s--) { |
| 1904 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1905 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1906 | // This is a bit for the GC side effect. |
| 1907 | if (current_bit_is_set) { |
| 1908 | flags += "GC"; |
| 1909 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1910 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1911 | } else { |
| 1912 | // This is a bit for the array/field analysis. |
| 1913 | // The underscore character stands for the 'can trigger GC' bit. |
| 1914 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1915 | if (current_bit_is_set) { |
| 1916 | flags += kDebug[s]; |
| 1917 | } |
| 1918 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1919 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1920 | flags += "|"; |
| 1921 | } |
| 1922 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1923 | } |
| 1924 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1925 | } |
| 1926 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1927 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1928 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1929 | private: |
| 1930 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1931 | |
| 1932 | static constexpr int kFieldWriteOffset = 0; |
| 1933 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1934 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1935 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1936 | |
| 1937 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1938 | |
| 1939 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1940 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1941 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1942 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1943 | |
| 1944 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1945 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1946 | |
| 1947 | // Aliases. |
| 1948 | |
| 1949 | static_assert(kChangeBits == kDependOnBits, |
| 1950 | "the 'change' bits should match the 'depend on' bits."); |
| 1951 | |
| 1952 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1953 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1954 | static constexpr uint64_t kAllWrites = |
| 1955 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1956 | static constexpr uint64_t kAllReads = |
| 1957 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1958 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1959 | // 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] | 1960 | static uint64_t TypeFlag(DataType::Type type, int offset) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1961 | int shift; |
| 1962 | switch (type) { |
| 1963 | case DataType::Type::kReference: shift = 0; break; |
| 1964 | case DataType::Type::kBool: shift = 1; break; |
| 1965 | case DataType::Type::kInt8: shift = 2; break; |
| 1966 | case DataType::Type::kUint16: shift = 3; break; |
| 1967 | case DataType::Type::kInt16: shift = 4; break; |
| 1968 | case DataType::Type::kInt32: shift = 5; break; |
| 1969 | case DataType::Type::kInt64: shift = 6; break; |
| 1970 | case DataType::Type::kFloat32: shift = 7; break; |
| 1971 | case DataType::Type::kFloat64: shift = 8; break; |
| 1972 | default: |
| 1973 | LOG(FATAL) << "Unexpected data type " << type; |
| 1974 | UNREACHABLE(); |
| 1975 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1976 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1977 | DCHECK_LT(shift, kArrayWriteOffset); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1978 | return UINT64_C(1) << (shift + offset); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | // Private constructor on direct flags value. |
| 1982 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1983 | |
| 1984 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1985 | }; |
| 1986 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1987 | // 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] | 1988 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1989 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1990 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1991 | size_t number_of_vregs, |
| 1992 | ArtMethod* method, |
| 1993 | uint32_t dex_pc, |
| 1994 | HInstruction* holder) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1995 | : vregs_(number_of_vregs, allocator->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1996 | locations_(allocator->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1997 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1998 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1999 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2000 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2001 | } |
| 2002 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2003 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
| 2004 | const HEnvironment& to_copy, |
| 2005 | HInstruction* holder) |
| 2006 | : HEnvironment(allocator, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2007 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2008 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2009 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2010 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2011 | |
Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 2012 | void AllocateLocations() { |
| 2013 | DCHECK(locations_.empty()); |
| 2014 | locations_.resize(vregs_.size()); |
| 2015 | } |
| 2016 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2017 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2018 | if (parent_ != nullptr) { |
| 2019 | parent_->SetAndCopyParentChain(allocator, parent); |
| 2020 | } else { |
| 2021 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 2022 | parent_->CopyFrom(parent); |
| 2023 | if (parent->GetParent() != nullptr) { |
| 2024 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 2025 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2026 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 2029 | void CopyFrom(ArrayRef<HInstruction* const> locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 2030 | void CopyFrom(HEnvironment* environment); |
| 2031 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2032 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 2033 | // input to the loop phi instead. This is for inserting instructions that |
| 2034 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 2035 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2036 | |
| 2037 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2038 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2042 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2045 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2046 | |
Artem Serov | ca210e3 | 2017-12-15 13:43:20 +0000 | [diff] [blame] | 2047 | // Replaces the input at the position 'index' with the replacement; the replacement and old |
| 2048 | // input instructions' env_uses_ lists are adjusted. The function works similar to |
| 2049 | // HInstruction::ReplaceInput. |
| 2050 | void ReplaceInput(HInstruction* replacement, size_t index); |
| 2051 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2052 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2053 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2054 | HEnvironment* GetParent() const { return parent_; } |
| 2055 | |
| 2056 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2057 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2061 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | uint32_t GetDexPc() const { |
| 2065 | return dex_pc_; |
| 2066 | } |
| 2067 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2068 | ArtMethod* GetMethod() const { |
| 2069 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2070 | } |
| 2071 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2072 | HInstruction* GetHolder() const { |
| 2073 | return holder_; |
| 2074 | } |
| 2075 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 2076 | |
| 2077 | bool IsFromInlinedInvoke() const { |
| 2078 | return GetParent() != nullptr; |
| 2079 | } |
| 2080 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2081 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2082 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 2083 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2084 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2085 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2086 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2087 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 2088 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2089 | HInstruction* const holder_; |
| 2090 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 2091 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2092 | |
| 2093 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 2094 | }; |
| 2095 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2096 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2097 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2098 | #define DECLARE_KIND(type, super) k##type, |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 2099 | enum InstructionKind { // private marker to avoid generate-operator-out.py from processing. |
Vladimir Marko | e394622 | 2018-05-04 14:18:47 +0100 | [diff] [blame] | 2100 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_KIND) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2101 | kLastInstructionKind |
| 2102 | }; |
| 2103 | #undef DECLARE_KIND |
| 2104 | |
| 2105 | HInstruction(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2106 | : HInstruction(kind, DataType::Type::kVoid, side_effects, dex_pc) {} |
| 2107 | |
| 2108 | 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] | 2109 | : previous_(nullptr), |
| 2110 | next_(nullptr), |
| 2111 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2112 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2113 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2114 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2115 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2116 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2117 | locations_(nullptr), |
| 2118 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2119 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 2120 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2121 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2122 | SetPackedField<InstructionKindField>(kind); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2123 | SetPackedField<TypeField>(type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2124 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 2125 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2126 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2127 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2128 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2129 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2130 | HInstruction* GetNext() const { return next_; } |
| 2131 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2132 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2133 | HInstruction* GetNextDisregardingMoves() const; |
| 2134 | HInstruction* GetPreviousDisregardingMoves() const; |
| 2135 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2136 | HBasicBlock* GetBlock() const { return block_; } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2137 | ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2138 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 2139 | bool IsInBlock() const { return block_ != nullptr; } |
| 2140 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 2141 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 2142 | bool IsIrreducibleLoopHeaderPhi() const { |
| 2143 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 2144 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2145 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2146 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 2147 | |
| 2148 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 2149 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 2150 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 2151 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 2152 | } |
| 2153 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2154 | HInputsRef GetInputs() { |
| 2155 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2156 | } |
| 2157 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2158 | HConstInputsRef GetInputs() const { |
| 2159 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2163 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2164 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 2165 | bool HasInput(HInstruction* input) const { |
| 2166 | for (const HInstruction* i : GetInputs()) { |
| 2167 | if (i == input) { |
| 2168 | return true; |
| 2169 | } |
| 2170 | } |
| 2171 | return false; |
| 2172 | } |
| 2173 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2174 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 2175 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 2176 | } |
| 2177 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2178 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 2179 | virtual const char* DebugName() const = 0; |
| 2180 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2181 | DataType::Type GetType() const { |
| 2182 | return TypeField::Decode(GetPackedFields()); |
| 2183 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2184 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2185 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2186 | |
| 2187 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2188 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2189 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2190 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2191 | // Can the instruction throw? |
| 2192 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 2193 | // 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] | 2194 | virtual bool CanThrow() const { return false; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2195 | |
| 2196 | // Does the instruction always throw an exception unconditionally? |
| 2197 | virtual bool AlwaysThrows() const { return false; } |
| 2198 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2199 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2200 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2201 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2202 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2203 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2204 | // Does not apply for all instructions, but having this at top level greatly |
| 2205 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 2206 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2207 | virtual bool CanBeNull() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2208 | DCHECK_EQ(GetType(), DataType::Type::kReference) << "CanBeNull only applies to reference types"; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2209 | return true; |
| 2210 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2211 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2212 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 2213 | return false; |
| 2214 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2215 | |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 2216 | // If this instruction will do an implicit null check, return the `HNullCheck` associated |
| 2217 | // with it. Otherwise return null. |
| 2218 | HNullCheck* GetImplicitNullCheck() const { |
Vladimir Marko | ee1f126 | 2019-06-26 14:37:17 +0100 | [diff] [blame] | 2219 | // Go over previous non-move instructions that are emitted at use site. |
| 2220 | HInstruction* prev_not_move = GetPreviousDisregardingMoves(); |
| 2221 | while (prev_not_move != nullptr && prev_not_move->IsEmittedAtUseSite()) { |
| 2222 | if (prev_not_move->IsNullCheck()) { |
| 2223 | return prev_not_move->AsNullCheck(); |
| 2224 | } |
| 2225 | prev_not_move = prev_not_move->GetPreviousDisregardingMoves(); |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 2226 | } |
| 2227 | return nullptr; |
| 2228 | } |
| 2229 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2230 | virtual bool IsActualObject() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2231 | return GetType() == DataType::Type::kReference; |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2232 | } |
| 2233 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 2234 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2235 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2236 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2237 | DCHECK_EQ(GetType(), DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2238 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 2239 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2240 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2241 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2242 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2243 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2244 | // Note: fixup_end remains valid across push_front(). |
| 2245 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
Vladimir Marko | 3224f38 | 2020-06-23 14:19:53 +0100 | [diff] [blame] | 2246 | ArenaAllocator* allocator = user->GetBlock()->GetGraph()->GetAllocator(); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2247 | HUseListNode<HInstruction*>* new_node = |
Vladimir Marko | 3224f38 | 2020-06-23 14:19:53 +0100 | [diff] [blame] | 2248 | new (allocator) HUseListNode<HInstruction*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2249 | uses_.push_front(*new_node); |
| 2250 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2251 | } |
| 2252 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2253 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2254 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2255 | // Note: env_fixup_end remains valid across push_front(). |
| 2256 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2257 | HUseListNode<HEnvironment*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2258 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HEnvironment*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2259 | env_uses_.push_front(*new_node); |
| 2260 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2261 | } |
| 2262 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2263 | void RemoveAsUserOfInput(size_t input) { |
| 2264 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2265 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2266 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2267 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2268 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2269 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2270 | void RemoveAsUserOfAllInputs() { |
| 2271 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2272 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2273 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2274 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2275 | } |
| 2276 | } |
| 2277 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2278 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2279 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2280 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2281 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2282 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2283 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2284 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2285 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2286 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2287 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2288 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2289 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2290 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2291 | !CanThrow() && |
| 2292 | !IsSuspendCheck() && |
| 2293 | !IsControlFlow() && |
| 2294 | !IsNativeDebugInfo() && |
| 2295 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2296 | // If we added an explicit barrier then we should keep it. |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2297 | !IsMemoryBarrier() && |
| 2298 | !IsConstructorFence(); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2301 | bool IsDeadAndRemovable() const { |
| 2302 | return IsRemovable() && !HasUses(); |
| 2303 | } |
| 2304 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2305 | // Does this instruction strictly dominate `other_instruction`? |
| 2306 | // Returns false if this instruction and `other_instruction` are the same. |
| 2307 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2308 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2309 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2310 | int GetId() const { return id_; } |
| 2311 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2312 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2313 | int GetSsaIndex() const { return ssa_index_; } |
| 2314 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2315 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2316 | |
| 2317 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2318 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2319 | // Set the `environment_` field. Raw because this method does not |
| 2320 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2321 | void SetRawEnvironment(HEnvironment* environment) { |
| 2322 | DCHECK(environment_ == nullptr); |
| 2323 | DCHECK_EQ(environment->GetHolder(), this); |
| 2324 | environment_ = environment; |
| 2325 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2326 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2327 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2328 | DCHECK(environment_ != nullptr); |
| 2329 | DCHECK_EQ(environment->GetHolder(), this); |
| 2330 | DCHECK(environment->GetParent() == nullptr); |
| 2331 | environment->parent_ = environment_; |
| 2332 | environment_ = environment; |
| 2333 | } |
| 2334 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2335 | void RemoveEnvironment(); |
| 2336 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2337 | // Set the environment of this instruction, copying it from `environment`. While |
| 2338 | // copying, the uses lists are being updated. |
| 2339 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2340 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2341 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2342 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2343 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2344 | if (environment->GetParent() != nullptr) { |
| 2345 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2346 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2347 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2348 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2349 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2350 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2351 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2352 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2353 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2354 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2355 | if (environment->GetParent() != nullptr) { |
| 2356 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2357 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2360 | // Returns the number of entries in the environment. Typically, that is the |
| 2361 | // number of dex registers in a method. It could be more in case of inlining. |
| 2362 | size_t EnvironmentSize() const; |
| 2363 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2364 | LocationSummary* GetLocations() const { return locations_; } |
| 2365 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2366 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2367 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2368 | void ReplaceUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 8a62a4c | 2018-07-03 09:39:07 +0100 | [diff] [blame] | 2369 | void ReplaceEnvUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2370 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2371 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2372 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2373 | // uses of this instruction by `other` are *not* updated. |
| 2374 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2375 | ReplaceWith(other); |
| 2376 | other->ReplaceInput(this, use_index); |
| 2377 | } |
| 2378 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2379 | // Move `this` instruction before `cursor` |
| 2380 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2381 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2382 | // Move `this` before its first user and out of any loops. If there is no |
| 2383 | // out-of-loop user that dominates all other users, move the instruction |
| 2384 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2385 | // |
| 2386 | // This can be used only on non-throwing instructions with no side effects that |
| 2387 | // have at least one use but no environment uses. |
| 2388 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2389 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2390 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2391 | bool Is##type() const; |
| 2392 | |
| 2393 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2394 | #undef INSTRUCTION_TYPE_CHECK |
| 2395 | |
| 2396 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2397 | const H##type* As##type() const; \ |
| 2398 | H##type* As##type(); |
| 2399 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2400 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 2401 | #undef INSTRUCTION_TYPE_CAST |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2402 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2403 | // Return a clone of the instruction if it is clonable (shallow copy by default, custom copy |
| 2404 | // if a custom copy-constructor is provided for a particular type). If IsClonable() is false for |
| 2405 | // the instruction then the behaviour of this function is undefined. |
| 2406 | // |
| 2407 | // Note: It is semantically valid to create a clone of the instruction only until |
| 2408 | // prepare_for_register_allocator phase as lifetime, intervals and codegen info are not |
| 2409 | // copied. |
| 2410 | // |
| 2411 | // Note: HEnvironment and some other fields are not copied and are set to default values, see |
| 2412 | // 'explicit HInstruction(const HInstruction& other)' for details. |
| 2413 | virtual HInstruction* Clone(ArenaAllocator* arena ATTRIBUTE_UNUSED) const { |
| 2414 | LOG(FATAL) << "Cloning is not implemented for the instruction " << |
| 2415 | DebugName() << " " << GetId(); |
| 2416 | UNREACHABLE(); |
| 2417 | } |
| 2418 | |
| 2419 | // Return whether instruction can be cloned (copied). |
| 2420 | virtual bool IsClonable() const { return false; } |
| 2421 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2422 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2423 | // TODO: this method is used by LICM and GVN with possibly different |
| 2424 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2425 | virtual bool CanBeMoved() const { return false; } |
| 2426 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2427 | // Returns whether any data encoded in the two instructions is equal. |
| 2428 | // This method does not look at the inputs. Both instructions must be |
| 2429 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2430 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2431 | return false; |
| 2432 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2433 | |
| 2434 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2435 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2436 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2437 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2438 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2439 | InstructionKind GetKind() const { return GetPackedField<InstructionKindField>(); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2440 | |
| 2441 | virtual size_t ComputeHashCode() const { |
| 2442 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2443 | for (const HInstruction* input : GetInputs()) { |
| 2444 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2445 | } |
| 2446 | return result; |
| 2447 | } |
| 2448 | |
| 2449 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2450 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2451 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2452 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2453 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2454 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2455 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2456 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2457 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2458 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2459 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2460 | |
| 2461 | // Returns whether the code generation of the instruction will require to have access |
| 2462 | // to the current method. Such instructions are: |
| 2463 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2464 | // 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] | 2465 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2466 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2467 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2468 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2471 | // Returns whether the code generation of the instruction will require to have access |
| 2472 | // to the dex cache of the current method's declaring class via the current method. |
| 2473 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2474 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2475 | // Does this instruction have any use in an environment before |
| 2476 | // control flow hits 'other'? |
| 2477 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2478 | |
| 2479 | // Remove all references to environment uses of this instruction. |
| 2480 | // The caller must ensure that this is safe to do. |
| 2481 | void RemoveEnvironmentUsers(); |
| 2482 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2483 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2484 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2485 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2486 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2487 | // If set, the machine code for this instruction is assumed to be generated by |
| 2488 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2489 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2490 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2491 | static constexpr size_t kFieldInstructionKind = kFlagReferenceTypeIsExact + 1; |
| 2492 | static constexpr size_t kFieldInstructionKindSize = |
| 2493 | MinimumBitsToStore(static_cast<size_t>(InstructionKind::kLastInstructionKind - 1)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2494 | static constexpr size_t kFieldType = |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2495 | kFieldInstructionKind + kFieldInstructionKindSize; |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2496 | static constexpr size_t kFieldTypeSize = |
| 2497 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
| 2498 | static constexpr size_t kNumberOfGenericPackedBits = kFieldType + kFieldTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2499 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2500 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2501 | static_assert(kNumberOfGenericPackedBits <= kMaxNumberOfPackedBits, |
| 2502 | "Too many generic packed fields"); |
| 2503 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2504 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
| 2505 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2506 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2507 | return GetInputRecords()[i]; |
| 2508 | } |
| 2509 | |
| 2510 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2511 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2512 | input_records[index] = input; |
| 2513 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2514 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2515 | uint32_t GetPackedFields() const { |
| 2516 | return packed_fields_; |
| 2517 | } |
| 2518 | |
| 2519 | template <size_t flag> |
| 2520 | bool GetPackedFlag() const { |
| 2521 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2522 | } |
| 2523 | |
| 2524 | template <size_t flag> |
| 2525 | void SetPackedFlag(bool value = true) { |
| 2526 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2527 | } |
| 2528 | |
| 2529 | template <typename BitFieldType> |
| 2530 | typename BitFieldType::value_type GetPackedField() const { |
| 2531 | return BitFieldType::Decode(packed_fields_); |
| 2532 | } |
| 2533 | |
| 2534 | template <typename BitFieldType> |
| 2535 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2536 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2537 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2538 | } |
| 2539 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2540 | // Copy construction for the instruction (used for Clone function). |
| 2541 | // |
| 2542 | // Fields (e.g. lifetime, intervals and codegen info) associated with phases starting from |
| 2543 | // prepare_for_register_allocator are not copied (set to default values). |
| 2544 | // |
| 2545 | // Copy constructors must be provided for every HInstruction type; default copy constructor is |
| 2546 | // fine for most of them. However for some of the instructions a custom copy constructor must be |
| 2547 | // specified (when instruction has non-trivially copyable fields and must have a special behaviour |
| 2548 | // for copying them). |
| 2549 | explicit HInstruction(const HInstruction& other) |
| 2550 | : previous_(nullptr), |
| 2551 | next_(nullptr), |
| 2552 | block_(nullptr), |
| 2553 | dex_pc_(other.dex_pc_), |
| 2554 | id_(-1), |
| 2555 | ssa_index_(-1), |
| 2556 | packed_fields_(other.packed_fields_), |
| 2557 | environment_(nullptr), |
| 2558 | locations_(nullptr), |
| 2559 | live_interval_(nullptr), |
| 2560 | lifetime_position_(kNoLifetime), |
| 2561 | side_effects_(other.side_effects_), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2562 | reference_type_handle_(other.reference_type_handle_) { |
| 2563 | } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2564 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2565 | private: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2566 | using InstructionKindField = |
| 2567 | BitField<InstructionKind, kFieldInstructionKind, kFieldInstructionKindSize>; |
| 2568 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2569 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2570 | auto before_use_node = uses_.before_begin(); |
| 2571 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2572 | HInstruction* user = use_node->GetUser(); |
| 2573 | size_t input_index = use_node->GetIndex(); |
| 2574 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2575 | before_use_node = use_node; |
| 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2580 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2581 | if (next != uses_.end()) { |
| 2582 | HInstruction* next_user = next->GetUser(); |
| 2583 | size_t next_index = next->GetIndex(); |
| 2584 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2585 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2586 | } |
| 2587 | } |
| 2588 | |
| 2589 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2590 | auto before_env_use_node = env_uses_.before_begin(); |
| 2591 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2592 | HEnvironment* user = env_use_node->GetUser(); |
| 2593 | size_t input_index = env_use_node->GetIndex(); |
| 2594 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2595 | before_env_use_node = env_use_node; |
| 2596 | } |
| 2597 | } |
| 2598 | |
| 2599 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2600 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2601 | if (next != env_uses_.end()) { |
| 2602 | HEnvironment* next_user = next->GetUser(); |
| 2603 | size_t next_index = next->GetIndex(); |
| 2604 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2605 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2606 | } |
| 2607 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2608 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2609 | HInstruction* previous_; |
| 2610 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2611 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2612 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2613 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2614 | // An instruction gets an id when it is added to the graph. |
| 2615 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2616 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2617 | int id_; |
| 2618 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2619 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2620 | int ssa_index_; |
| 2621 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2622 | // Packed fields. |
| 2623 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2624 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2625 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2626 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2627 | |
| 2628 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2629 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2630 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2631 | // The environment associated with this instruction. Not null if the instruction |
| 2632 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2633 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2634 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2635 | // Set by the code generator. |
| 2636 | LocationSummary* locations_; |
| 2637 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2638 | // Set by the liveness analysis. |
| 2639 | LiveInterval* live_interval_; |
| 2640 | |
| 2641 | // Set by the liveness analysis, this is the position in a linear |
| 2642 | // order of blocks where this instruction's live interval start. |
| 2643 | size_t lifetime_position_; |
| 2644 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2645 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2646 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2647 | // The reference handle part of the reference type info. |
| 2648 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2649 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2650 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2651 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2652 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2653 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2654 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2655 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2656 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2657 | }; |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 2658 | std::ostream& operator<<(std::ostream& os, HInstruction::InstructionKind rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2659 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2660 | // Iterates over the instructions, while preserving the next instruction |
| 2661 | // in case the current instruction gets removed from the list by the user |
| 2662 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2663 | class HInstructionIterator : public ValueObject { |
| 2664 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2665 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2666 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2667 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2670 | bool Done() const { return instruction_ == nullptr; } |
| 2671 | HInstruction* Current() const { return instruction_; } |
| 2672 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2673 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2674 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | private: |
| 2678 | HInstruction* instruction_; |
| 2679 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2680 | |
| 2681 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2682 | }; |
| 2683 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2684 | // Iterates over the instructions without saving the next instruction, |
| 2685 | // therefore handling changes in the graph potentially made by the user |
| 2686 | // of this iterator. |
| 2687 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2688 | public: |
| 2689 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2690 | : instruction_(instructions.first_instruction_) { |
| 2691 | } |
| 2692 | |
| 2693 | bool Done() const { return instruction_ == nullptr; } |
| 2694 | HInstruction* Current() const { return instruction_; } |
| 2695 | void Advance() { |
| 2696 | instruction_ = instruction_->GetNext(); |
| 2697 | } |
| 2698 | |
| 2699 | private: |
| 2700 | HInstruction* instruction_; |
| 2701 | |
| 2702 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2703 | }; |
| 2704 | |
| 2705 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2706 | class HBackwardInstructionIterator : public ValueObject { |
| 2707 | public: |
| 2708 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2709 | : instruction_(instructions.last_instruction_) { |
| 2710 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2711 | } |
| 2712 | |
| 2713 | bool Done() const { return instruction_ == nullptr; } |
| 2714 | HInstruction* Current() const { return instruction_; } |
| 2715 | void Advance() { |
| 2716 | instruction_ = next_; |
| 2717 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2718 | } |
| 2719 | |
| 2720 | private: |
| 2721 | HInstruction* instruction_; |
| 2722 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2723 | |
| 2724 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2725 | }; |
| 2726 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2727 | class HVariableInputSizeInstruction : public HInstruction { |
| 2728 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2729 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2730 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2731 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2732 | } |
| 2733 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2734 | void AddInput(HInstruction* input); |
| 2735 | void InsertInputAt(size_t index, HInstruction* input); |
| 2736 | void RemoveInputAt(size_t index); |
| 2737 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2738 | // Removes all the inputs. |
| 2739 | // Also removes this instructions from each input's use list |
| 2740 | // (for non-environment uses only). |
| 2741 | void RemoveAllInputs(); |
| 2742 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2743 | protected: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2744 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2745 | SideEffects side_effects, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2746 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2747 | ArenaAllocator* allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2748 | size_t number_of_inputs, |
| 2749 | ArenaAllocKind kind) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2750 | : HInstruction(inst_kind, side_effects, dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2751 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2752 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2753 | DataType::Type type, |
| 2754 | SideEffects side_effects, |
| 2755 | uint32_t dex_pc, |
| 2756 | ArenaAllocator* allocator, |
| 2757 | size_t number_of_inputs, |
| 2758 | ArenaAllocKind kind) |
| 2759 | : HInstruction(inst_kind, type, side_effects, dex_pc), |
| 2760 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2761 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2762 | DEFAULT_COPY_CONSTRUCTOR(VariableInputSizeInstruction); |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2763 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2764 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2765 | }; |
| 2766 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2767 | template<size_t N> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2768 | class HExpression : public HInstruction { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2769 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2770 | HExpression<N>(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2771 | : HInstruction(kind, side_effects, dex_pc), inputs_() {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2772 | HExpression<N>(InstructionKind kind, |
| 2773 | DataType::Type type, |
| 2774 | SideEffects side_effects, |
| 2775 | uint32_t dex_pc) |
| 2776 | : HInstruction(kind, type, side_effects, dex_pc), inputs_() {} |
| 2777 | virtual ~HExpression() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2778 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2779 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 2780 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2781 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2784 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2785 | DEFAULT_COPY_CONSTRUCTOR(Expression<N>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2786 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2787 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2788 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2789 | |
| 2790 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2791 | }; |
| 2792 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2793 | // HExpression specialization for N=0. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2794 | template<> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2795 | class HExpression<0> : public HInstruction { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2796 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2797 | using HInstruction::HInstruction; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2798 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2799 | virtual ~HExpression() {} |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2800 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2801 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 2802 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2803 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2804 | } |
| 2805 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2806 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2807 | DEFAULT_COPY_CONSTRUCTOR(Expression<0>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2808 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2809 | private: |
| 2810 | friend class SsaBuilder; |
| 2811 | }; |
| 2812 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2813 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2814 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2815 | class HReturnVoid final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2816 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2817 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2818 | : HExpression(kReturnVoid, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2819 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2820 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2821 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2822 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2823 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2824 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2825 | protected: |
| 2826 | DEFAULT_COPY_CONSTRUCTOR(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2827 | }; |
| 2828 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2829 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2830 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2831 | class HReturn final : public HExpression<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2832 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2833 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2834 | : HExpression(kReturn, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2835 | SetRawInputAt(0, value); |
| 2836 | } |
| 2837 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2838 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2839 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2840 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2841 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2842 | protected: |
| 2843 | DEFAULT_COPY_CONSTRUCTOR(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2844 | }; |
| 2845 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2846 | class HPhi final : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2847 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2848 | HPhi(ArenaAllocator* allocator, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2849 | uint32_t reg_number, |
| 2850 | size_t number_of_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2851 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2852 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2853 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2854 | kPhi, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2855 | ToPhiType(type), |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2856 | SideEffects::None(), |
| 2857 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2858 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2859 | number_of_inputs, |
| 2860 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2861 | reg_number_(reg_number) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2862 | DCHECK_NE(GetType(), DataType::Type::kVoid); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2863 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2864 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2865 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2866 | SetPackedFlag<kFlagIsLive>(true); |
| 2867 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2868 | } |
| 2869 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2870 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2871 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2872 | // 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] | 2873 | static DataType::Type ToPhiType(DataType::Type type) { |
| 2874 | return DataType::Kind(type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2878 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2879 | void SetType(DataType::Type new_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2880 | // Make sure that only valid type changes occur. The following are allowed: |
| 2881 | // (1) int -> float/ref (primitive type propagation), |
| 2882 | // (2) long -> double (primitive type propagation). |
| 2883 | DCHECK(GetType() == new_type || |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2884 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kFloat32) || |
| 2885 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kReference) || |
| 2886 | (GetType() == DataType::Type::kInt64 && new_type == DataType::Type::kFloat64)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2887 | SetPackedField<TypeField>(new_type); |
| 2888 | } |
| 2889 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2890 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2891 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2892 | |
| 2893 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2894 | |
| 2895 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2896 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2897 | bool IsDead() const { return !IsLive(); } |
| 2898 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2899 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2900 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2901 | return other != nullptr |
| 2902 | && other->IsPhi() |
| 2903 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2904 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2905 | } |
| 2906 | |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 2907 | bool HasEquivalentPhi() const { |
| 2908 | if (GetPrevious() != nullptr && GetPrevious()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2909 | return true; |
| 2910 | } |
| 2911 | if (GetNext() != nullptr && GetNext()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2912 | return true; |
| 2913 | } |
| 2914 | return false; |
| 2915 | } |
| 2916 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2917 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2918 | // An equivalent phi is a phi having the same dex register and type. |
| 2919 | // It assumes that phis with the same dex register are adjacent. |
| 2920 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2921 | HInstruction* next = GetNext(); |
| 2922 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2923 | if (next->GetType() == GetType()) { |
| 2924 | return next->AsPhi(); |
| 2925 | } |
| 2926 | next = next->GetNext(); |
| 2927 | } |
| 2928 | return nullptr; |
| 2929 | } |
| 2930 | |
| 2931 | DECLARE_INSTRUCTION(Phi); |
| 2932 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2933 | protected: |
| 2934 | DEFAULT_COPY_CONSTRUCTOR(Phi); |
| 2935 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2936 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2937 | static constexpr size_t kFlagIsLive = HInstruction::kNumberOfGenericPackedBits; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2938 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2939 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2940 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2941 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2942 | const uint32_t reg_number_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2943 | }; |
| 2944 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2945 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2946 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2947 | // exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2948 | class HExit final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2949 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2950 | explicit HExit(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2951 | : HExpression(kExit, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2952 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2953 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2954 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2955 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2956 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2957 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2958 | protected: |
| 2959 | DEFAULT_COPY_CONSTRUCTOR(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2960 | }; |
| 2961 | |
| 2962 | // Jumps from one block to another. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2963 | class HGoto final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2964 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2965 | explicit HGoto(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2966 | : HExpression(kGoto, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2967 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2968 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2969 | bool IsClonable() const override { return true; } |
| 2970 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2971 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2972 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2973 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2974 | } |
| 2975 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2976 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2977 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2978 | protected: |
| 2979 | DEFAULT_COPY_CONSTRUCTOR(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2980 | }; |
| 2981 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2982 | class HConstant : public HExpression<0> { |
| 2983 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2984 | explicit HConstant(InstructionKind kind, DataType::Type type, uint32_t dex_pc = kNoDexPc) |
| 2985 | : HExpression(kind, type, SideEffects::None(), dex_pc) { |
| 2986 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2987 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2988 | bool CanBeMoved() const override { return true; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2989 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2990 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2991 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2992 | // Is this constant 0 in the arithmetic sense? |
| 2993 | virtual bool IsArithmeticZero() const { return false; } |
| 2994 | // Is this constant a 0-bit pattern? |
| 2995 | virtual bool IsZeroBitPattern() const { return false; } |
| 2996 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2997 | virtual bool IsOne() const { return false; } |
| 2998 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2999 | virtual uint64_t GetValueAsUint64() const = 0; |
| 3000 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3001 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3002 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3003 | protected: |
| 3004 | DEFAULT_COPY_CONSTRUCTOR(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3005 | }; |
| 3006 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3007 | class HNullConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3008 | public: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3009 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3010 | return true; |
| 3011 | } |
| 3012 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3013 | uint64_t GetValueAsUint64() const override { return 0; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3014 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3015 | size_t ComputeHashCode() const override { return 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3016 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3017 | // The null constant representation is a 0-bit pattern. |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame] | 3018 | bool IsZeroBitPattern() const override { return true; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3019 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3020 | DECLARE_INSTRUCTION(NullConstant); |
| 3021 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3022 | protected: |
| 3023 | DEFAULT_COPY_CONSTRUCTOR(NullConstant); |
| 3024 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3025 | private: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3026 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3027 | : HConstant(kNullConstant, DataType::Type::kReference, dex_pc) { |
| 3028 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3029 | |
| 3030 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3031 | }; |
| 3032 | |
| 3033 | // Constants of the type int. Those can be from Dex instructions, or |
| 3034 | // synthesized (for example with the if-eqz instruction). |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3035 | class HIntConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3036 | public: |
| 3037 | int32_t GetValue() const { return value_; } |
| 3038 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3039 | uint64_t GetValueAsUint64() const override { |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 3040 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 3041 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3042 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3043 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3044 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3045 | return other->AsIntConstant()->value_ == value_; |
| 3046 | } |
| 3047 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3048 | size_t ComputeHashCode() const override { return GetValue(); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3049 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3050 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 3051 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 3052 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 3053 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3054 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3055 | // Integer constants are used to encode Boolean values as well, |
| 3056 | // where 1 means true and 0 means false. |
| 3057 | bool IsTrue() const { return GetValue() == 1; } |
| 3058 | bool IsFalse() const { return GetValue() == 0; } |
| 3059 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3060 | DECLARE_INSTRUCTION(IntConstant); |
| 3061 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3062 | protected: |
| 3063 | DEFAULT_COPY_CONSTRUCTOR(IntConstant); |
| 3064 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3065 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3066 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3067 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), value_(value) { |
| 3068 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3069 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3070 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), |
| 3071 | value_(value ? 1 : 0) { |
| 3072 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3073 | |
| 3074 | const int32_t value_; |
| 3075 | |
| 3076 | friend class HGraph; |
| 3077 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 3078 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3079 | }; |
| 3080 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3081 | class HLongConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3082 | public: |
| 3083 | int64_t GetValue() const { return value_; } |
| 3084 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3085 | uint64_t GetValueAsUint64() const override { return value_; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3086 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3087 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3088 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3089 | return other->AsLongConstant()->value_ == value_; |
| 3090 | } |
| 3091 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3092 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3093 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3094 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 3095 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 3096 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 3097 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3098 | |
| 3099 | DECLARE_INSTRUCTION(LongConstant); |
| 3100 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3101 | protected: |
| 3102 | DEFAULT_COPY_CONSTRUCTOR(LongConstant); |
| 3103 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3104 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3105 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3106 | : HConstant(kLongConstant, DataType::Type::kInt64, dex_pc), |
| 3107 | value_(value) { |
| 3108 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3109 | |
| 3110 | const int64_t value_; |
| 3111 | |
| 3112 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3113 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3114 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3115 | class HFloatConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3116 | public: |
| 3117 | float GetValue() const { return value_; } |
| 3118 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3119 | uint64_t GetValueAsUint64() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3120 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3121 | } |
| 3122 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3123 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3124 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 3125 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3126 | } |
| 3127 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3128 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3129 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3130 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3131 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 3132 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3133 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3134 | return std::fpclassify(value_) == FP_ZERO; |
| 3135 | } |
| 3136 | bool IsArithmeticPositiveZero() const { |
| 3137 | return IsArithmeticZero() && !std::signbit(value_); |
| 3138 | } |
| 3139 | bool IsArithmeticNegativeZero() const { |
| 3140 | return IsArithmeticZero() && std::signbit(value_); |
| 3141 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3142 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3143 | 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] | 3144 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3145 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3146 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3147 | } |
| 3148 | bool IsNaN() const { |
| 3149 | return std::isnan(value_); |
| 3150 | } |
| 3151 | |
| 3152 | DECLARE_INSTRUCTION(FloatConstant); |
| 3153 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3154 | protected: |
| 3155 | DEFAULT_COPY_CONSTRUCTOR(FloatConstant); |
| 3156 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3157 | private: |
| 3158 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3159 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3160 | value_(value) { |
| 3161 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3162 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3163 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3164 | value_(bit_cast<float, int32_t>(value)) { |
| 3165 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3166 | |
| 3167 | const float value_; |
| 3168 | |
| 3169 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3170 | friend class SsaBuilder; |
| 3171 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3172 | }; |
| 3173 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3174 | class HDoubleConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3175 | public: |
| 3176 | double GetValue() const { return value_; } |
| 3177 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3178 | uint64_t GetValueAsUint64() const override { return bit_cast<uint64_t, double>(value_); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3179 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3180 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3181 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 3182 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3183 | } |
| 3184 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3185 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3186 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3187 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3188 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 3189 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3190 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3191 | return std::fpclassify(value_) == FP_ZERO; |
| 3192 | } |
| 3193 | bool IsArithmeticPositiveZero() const { |
| 3194 | return IsArithmeticZero() && !std::signbit(value_); |
| 3195 | } |
| 3196 | bool IsArithmeticNegativeZero() const { |
| 3197 | return IsArithmeticZero() && std::signbit(value_); |
| 3198 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3199 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3200 | 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] | 3201 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3202 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3203 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3204 | } |
| 3205 | bool IsNaN() const { |
| 3206 | return std::isnan(value_); |
| 3207 | } |
| 3208 | |
| 3209 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3210 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3211 | protected: |
| 3212 | DEFAULT_COPY_CONSTRUCTOR(DoubleConstant); |
| 3213 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3214 | private: |
| 3215 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3216 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3217 | value_(value) { |
| 3218 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3219 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3220 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3221 | value_(bit_cast<double, int64_t>(value)) { |
| 3222 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3223 | |
| 3224 | const double value_; |
| 3225 | |
| 3226 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3227 | friend class SsaBuilder; |
| 3228 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3229 | }; |
| 3230 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3231 | // Conditional branch. A block ending with an HIf instruction must have |
| 3232 | // two successors. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3233 | class HIf final : public HExpression<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3234 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3235 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3236 | : HExpression(kIf, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3237 | SetRawInputAt(0, input); |
| 3238 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3239 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3240 | bool IsClonable() const override { return true; } |
| 3241 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3242 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3243 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3244 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3248 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3251 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3252 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3253 | protected: |
| 3254 | DEFAULT_COPY_CONSTRUCTOR(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3255 | }; |
| 3256 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3257 | |
| 3258 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 3259 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 3260 | // non-exceptional control flow. |
| 3261 | // Normal-flow successor is stored at index zero, exception handlers under |
| 3262 | // higher indices in no particular order. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3263 | class HTryBoundary final : public HExpression<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3264 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3265 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3266 | kEntry, |
| 3267 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3268 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3269 | }; |
| 3270 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3271 | // SideEffects::CanTriggerGC prevents instructions with SideEffects::DependOnGC to be alive |
| 3272 | // across the catch block entering edges as GC might happen during throwing an exception. |
| 3273 | // TryBoundary with BoundaryKind::kExit is conservatively used for that as there is no |
| 3274 | // HInstruction which a catch block must start from. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3275 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3276 | : HExpression(kTryBoundary, |
| 3277 | (kind == BoundaryKind::kExit) ? SideEffects::CanTriggerGC() |
| 3278 | : SideEffects::None(), |
| 3279 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3280 | SetPackedField<BoundaryKindField>(kind); |
| 3281 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3282 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3283 | bool IsControlFlow() const override { return true; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3284 | |
| 3285 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3286 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3287 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 3288 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 3289 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 3290 | } |
| 3291 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3292 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 3293 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3294 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 3295 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 3296 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | // If not present already, adds `handler` to its block's list of exception |
| 3300 | // handlers. |
| 3301 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3302 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3303 | GetBlock()->AddSuccessor(handler); |
| 3304 | } |
| 3305 | } |
| 3306 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3307 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 3308 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3309 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3310 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 3311 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3312 | DECLARE_INSTRUCTION(TryBoundary); |
| 3313 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3314 | protected: |
| 3315 | DEFAULT_COPY_CONSTRUCTOR(TryBoundary); |
| 3316 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3317 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3318 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 3319 | static constexpr size_t kFieldBoundaryKindSize = |
| 3320 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 3321 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 3322 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 3323 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 3324 | "Too many packed fields."); |
| 3325 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3326 | }; |
| 3327 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3328 | // Deoptimize to interpreter, upon checking a condition. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3329 | class HDeoptimize final : public HVariableInputSizeInstruction { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3330 | public: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3331 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 3332 | // across. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3333 | HDeoptimize(ArenaAllocator* allocator, |
| 3334 | HInstruction* cond, |
| 3335 | DeoptimizationKind kind, |
| 3336 | uint32_t dex_pc) |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3337 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3338 | kDeoptimize, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3339 | SideEffects::All(), |
| 3340 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3341 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3342 | /* number_of_inputs= */ 1, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3343 | kArenaAllocMisc) { |
| 3344 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 3345 | SetPackedField<DeoptimizeKindField>(kind); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3346 | SetRawInputAt(0, cond); |
| 3347 | } |
| 3348 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3349 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3350 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3351 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3352 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3353 | // instead of `guard`. |
| 3354 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3355 | // at the point of the `HDeoptimize`. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3356 | HDeoptimize(ArenaAllocator* allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3357 | HInstruction* cond, |
| 3358 | HInstruction* guard, |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3359 | DeoptimizationKind kind, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3360 | uint32_t dex_pc) |
| 3361 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3362 | kDeoptimize, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3363 | guard->GetType(), |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3364 | SideEffects::CanTriggerGC(), |
| 3365 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3366 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3367 | /* number_of_inputs= */ 2, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3368 | kArenaAllocMisc) { |
| 3369 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3370 | SetPackedField<DeoptimizeKindField>(kind); |
| 3371 | SetRawInputAt(0, cond); |
| 3372 | SetRawInputAt(1, guard); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3373 | } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3374 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3375 | bool CanBeMoved() const override { return GetPackedFlag<kFieldCanBeMoved>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3376 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3377 | bool InstructionDataEquals(const HInstruction* other) const override { |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3378 | return (other->CanBeMoved() == CanBeMoved()) && (other->AsDeoptimize()->GetKind() == GetKind()); |
| 3379 | } |
| 3380 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3381 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3382 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3383 | bool CanThrow() const override { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3384 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3385 | DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3386 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3387 | bool GuardsAnInput() const { |
| 3388 | return InputCount() == 2; |
| 3389 | } |
| 3390 | |
| 3391 | HInstruction* GuardedInput() const { |
| 3392 | DCHECK(GuardsAnInput()); |
| 3393 | return InputAt(1); |
| 3394 | } |
| 3395 | |
| 3396 | void RemoveGuard() { |
| 3397 | RemoveInputAt(1); |
| 3398 | } |
| 3399 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3400 | DECLARE_INSTRUCTION(Deoptimize); |
| 3401 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3402 | protected: |
| 3403 | DEFAULT_COPY_CONSTRUCTOR(Deoptimize); |
| 3404 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3405 | private: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3406 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3407 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3408 | static constexpr size_t kFieldDeoptimizeKindSize = |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3409 | MinimumBitsToStore(static_cast<size_t>(DeoptimizationKind::kLast)); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3410 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3411 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3412 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3413 | "Too many packed fields."); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3414 | using DeoptimizeKindField = |
| 3415 | BitField<DeoptimizationKind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3416 | }; |
| 3417 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3418 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3419 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3420 | // if it's true, starts to do deoptimization. |
| 3421 | // It has a 4-byte slot on stack. |
| 3422 | // TODO: allocate a register for this flag. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3423 | class HShouldDeoptimizeFlag final : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3424 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3425 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3426 | // with regard to other passes. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3427 | HShouldDeoptimizeFlag(ArenaAllocator* allocator, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3428 | : HVariableInputSizeInstruction(kShouldDeoptimizeFlag, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3429 | DataType::Type::kInt32, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3430 | SideEffects::None(), |
| 3431 | dex_pc, |
| 3432 | allocator, |
| 3433 | 0, |
| 3434 | kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3437 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3438 | // further guard elimination/motion since a guard might have been used for justification |
| 3439 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3440 | // to avoid other optimizations trying to move it. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3441 | bool CanBeMoved() const override { return false; } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3442 | |
| 3443 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3444 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3445 | protected: |
| 3446 | DEFAULT_COPY_CONSTRUCTOR(ShouldDeoptimizeFlag); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3447 | }; |
| 3448 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3449 | // Represents the ArtMethod that was passed as a first argument to |
| 3450 | // the method. It is used by instructions that depend on it, like |
| 3451 | // instructions that work with the dex cache. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3452 | class HCurrentMethod final : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3453 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3454 | explicit HCurrentMethod(DataType::Type type, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3455 | : HExpression(kCurrentMethod, type, SideEffects::None(), dex_pc) { |
| 3456 | } |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3457 | |
| 3458 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3459 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3460 | protected: |
| 3461 | DEFAULT_COPY_CONSTRUCTOR(CurrentMethod); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3462 | }; |
| 3463 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3464 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3465 | // of a class. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3466 | class HClassTableGet final : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3467 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3468 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3469 | kVTable, |
| 3470 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3471 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3472 | }; |
| 3473 | HClassTableGet(HInstruction* cls, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3474 | DataType::Type type, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3475 | TableKind kind, |
| 3476 | size_t index, |
| 3477 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3478 | : HExpression(kClassTableGet, type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3479 | index_(index) { |
| 3480 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3481 | SetRawInputAt(0, cls); |
| 3482 | } |
| 3483 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3484 | bool IsClonable() const override { return true; } |
| 3485 | bool CanBeMoved() const override { return true; } |
| 3486 | bool InstructionDataEquals(const HInstruction* other) const override { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3487 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3488 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3489 | } |
| 3490 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3491 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3492 | size_t GetIndex() const { return index_; } |
| 3493 | |
| 3494 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3495 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3496 | protected: |
| 3497 | DEFAULT_COPY_CONSTRUCTOR(ClassTableGet); |
| 3498 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3499 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3500 | static constexpr size_t kFieldTableKind = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3501 | static constexpr size_t kFieldTableKindSize = |
| 3502 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3503 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3504 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3505 | "Too many packed fields."); |
| 3506 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3507 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3508 | // The index of the ArtMethod in the table. |
| 3509 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3510 | }; |
| 3511 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3512 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3513 | // have one successor for each entry in the switch table, and the final successor |
| 3514 | // will be the block containing the next Dex opcode. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3515 | class HPackedSwitch final : public HExpression<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3516 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3517 | HPackedSwitch(int32_t start_value, |
| 3518 | uint32_t num_entries, |
| 3519 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3520 | uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3521 | : HExpression(kPackedSwitch, SideEffects::None(), dex_pc), |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3522 | start_value_(start_value), |
| 3523 | num_entries_(num_entries) { |
| 3524 | SetRawInputAt(0, input); |
| 3525 | } |
| 3526 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3527 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3528 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3529 | bool IsControlFlow() const override { return true; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3530 | |
| 3531 | int32_t GetStartValue() const { return start_value_; } |
| 3532 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3533 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3534 | |
| 3535 | HBasicBlock* GetDefaultBlock() const { |
| 3536 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3537 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3538 | } |
| 3539 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3540 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3541 | protected: |
| 3542 | DEFAULT_COPY_CONSTRUCTOR(PackedSwitch); |
| 3543 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3544 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3545 | const int32_t start_value_; |
| 3546 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3547 | }; |
| 3548 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3549 | class HUnaryOperation : public HExpression<1> { |
| 3550 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3551 | HUnaryOperation(InstructionKind kind, |
| 3552 | DataType::Type result_type, |
| 3553 | HInstruction* input, |
| 3554 | uint32_t dex_pc = kNoDexPc) |
| 3555 | : HExpression(kind, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3556 | SetRawInputAt(0, input); |
| 3557 | } |
| 3558 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3559 | // All of the UnaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3560 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3561 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3562 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3563 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3564 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3565 | bool CanBeMoved() const override { return true; } |
| 3566 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3567 | return true; |
| 3568 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3569 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3570 | // Try to statically evaluate `this` and return a HConstant |
| 3571 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3572 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3573 | HConstant* TryStaticEvaluation() const; |
| 3574 | |
| 3575 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3576 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3577 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3578 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3579 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3580 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3581 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3582 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3583 | protected: |
| 3584 | DEFAULT_COPY_CONSTRUCTOR(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3585 | }; |
| 3586 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3587 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3588 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3589 | HBinaryOperation(InstructionKind kind, |
| 3590 | DataType::Type result_type, |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3591 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3592 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3593 | SideEffects side_effects = SideEffects::None(), |
| 3594 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3595 | : HExpression(kind, result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3596 | SetRawInputAt(0, left); |
| 3597 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3598 | } |
| 3599 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3600 | // All of the BinaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3601 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3602 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3603 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3604 | HInstruction* GetRight() const { return InputAt(1); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3605 | DataType::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3606 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3607 | virtual bool IsCommutative() const { return false; } |
| 3608 | |
| 3609 | // Put constant on the right. |
| 3610 | // Returns whether order is changed. |
| 3611 | bool OrderInputsWithConstantOnTheRight() { |
| 3612 | HInstruction* left = InputAt(0); |
| 3613 | HInstruction* right = InputAt(1); |
| 3614 | if (left->IsConstant() && !right->IsConstant()) { |
| 3615 | ReplaceInput(right, 0); |
| 3616 | ReplaceInput(left, 1); |
| 3617 | return true; |
| 3618 | } |
| 3619 | return false; |
| 3620 | } |
| 3621 | |
| 3622 | // Order inputs by instruction id, but favor constant on the right side. |
| 3623 | // This helps GVN for commutative ops. |
| 3624 | void OrderInputs() { |
| 3625 | DCHECK(IsCommutative()); |
| 3626 | HInstruction* left = InputAt(0); |
| 3627 | HInstruction* right = InputAt(1); |
| 3628 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3629 | return; |
| 3630 | } |
| 3631 | if (OrderInputsWithConstantOnTheRight()) { |
| 3632 | return; |
| 3633 | } |
| 3634 | // Order according to instruction id. |
| 3635 | if (left->GetId() > right->GetId()) { |
| 3636 | ReplaceInput(right, 0); |
| 3637 | ReplaceInput(left, 1); |
| 3638 | } |
| 3639 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3640 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3641 | bool CanBeMoved() const override { return true; } |
| 3642 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3643 | return true; |
| 3644 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3645 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3646 | // Try to statically evaluate `this` and return a HConstant |
| 3647 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3648 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3649 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3650 | |
| 3651 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3652 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3653 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3654 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3655 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3656 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3657 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3658 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3659 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3660 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3661 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3662 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3663 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3664 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3665 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3666 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3667 | // 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] | 3668 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3669 | HConstant* GetConstantRight() const; |
| 3670 | |
| 3671 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3672 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3673 | HInstruction* GetLeastConstantLeft() const; |
| 3674 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3675 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3676 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3677 | protected: |
| 3678 | DEFAULT_COPY_CONSTRUCTOR(BinaryOperation); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3679 | }; |
| 3680 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3681 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3682 | // comparisons are treated: |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 3683 | enum class ComparisonBias { // private marker to avoid generate-operator-out.py from processing. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3684 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3685 | kGtBias, // return 1 for NaN comparisons |
| 3686 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3687 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3688 | }; |
| 3689 | |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 3690 | std::ostream& operator<<(std::ostream& os, ComparisonBias rhs); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3691 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3692 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3693 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3694 | HCondition(InstructionKind kind, |
| 3695 | HInstruction* first, |
| 3696 | HInstruction* second, |
| 3697 | uint32_t dex_pc = kNoDexPc) |
| 3698 | : HBinaryOperation(kind, |
| 3699 | DataType::Type::kBool, |
| 3700 | first, |
| 3701 | second, |
| 3702 | SideEffects::None(), |
| 3703 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3704 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3705 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3706 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3707 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3708 | // `instruction`, and disregard moves in between. |
| 3709 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3710 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3711 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3712 | |
| 3713 | virtual IfCondition GetCondition() const = 0; |
| 3714 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3715 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3716 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3717 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3718 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3719 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3720 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3721 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3722 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3723 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3724 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3725 | } |
| 3726 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3727 | bool IsFPConditionTrueIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3728 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3729 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3730 | if (if_cond == kCondNE) { |
| 3731 | return true; |
| 3732 | } else if (if_cond == kCondEQ) { |
| 3733 | return false; |
| 3734 | } |
| 3735 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | bool IsFPConditionFalseIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3739 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3740 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3741 | if (if_cond == kCondEQ) { |
| 3742 | return true; |
| 3743 | } else if (if_cond == kCondNE) { |
| 3744 | return false; |
| 3745 | } |
| 3746 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3747 | } |
| 3748 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3749 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3750 | // Needed if we merge a HCompare into a HCondition. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3751 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3752 | static constexpr size_t kFieldComparisonBiasSize = |
| 3753 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3754 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3755 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3756 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3757 | using ComparisonBiasField = |
| 3758 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3759 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3760 | template <typename T> |
| 3761 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3762 | |
| 3763 | template <typename T> |
| 3764 | int32_t CompareFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3765 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3766 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3767 | // Handle the bias. |
| 3768 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3769 | } |
| 3770 | |
| 3771 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3772 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3773 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3774 | } |
| 3775 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3776 | DEFAULT_COPY_CONSTRUCTOR(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3777 | }; |
| 3778 | |
| 3779 | // Instruction to check if two inputs are equal to each other. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3780 | class HEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3781 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3782 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3783 | : HCondition(kEqual, first, second, dex_pc) { |
| 3784 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3785 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3786 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3787 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3788 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3789 | HNullConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3790 | return MakeConstantCondition(true, GetDexPc()); |
| 3791 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3792 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3793 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3794 | } |
| 3795 | // In the following Evaluate methods, a HCompare instruction has |
| 3796 | // been merged into this HEqual instruction; evaluate it as |
| 3797 | // `Compare(x, y) == 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3798 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3799 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3800 | GetDexPc()); |
| 3801 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3802 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3803 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3804 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3805 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3806 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3807 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3808 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3809 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3810 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3811 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3812 | return kCondEQ; |
| 3813 | } |
| 3814 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3815 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3816 | return kCondNE; |
| 3817 | } |
| 3818 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3819 | protected: |
| 3820 | DEFAULT_COPY_CONSTRUCTOR(Equal); |
| 3821 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3822 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3823 | 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] | 3824 | }; |
| 3825 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3826 | class HNotEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3827 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3828 | HNotEqual(HInstruction* first, HInstruction* second, |
| 3829 | uint32_t dex_pc = kNoDexPc) |
| 3830 | : HCondition(kNotEqual, first, second, dex_pc) { |
| 3831 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3832 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3833 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3834 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3835 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3836 | HNullConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3837 | return MakeConstantCondition(false, GetDexPc()); |
| 3838 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3839 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3840 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3841 | } |
| 3842 | // In the following Evaluate methods, a HCompare instruction has |
| 3843 | // been merged into this HNotEqual instruction; evaluate it as |
| 3844 | // `Compare(x, y) != 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3845 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3846 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3847 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3848 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3849 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3850 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3851 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3852 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3853 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3854 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3855 | DECLARE_INSTRUCTION(NotEqual); |
| 3856 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3857 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3858 | return kCondNE; |
| 3859 | } |
| 3860 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3861 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3862 | return kCondEQ; |
| 3863 | } |
| 3864 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3865 | protected: |
| 3866 | DEFAULT_COPY_CONSTRUCTOR(NotEqual); |
| 3867 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3868 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3869 | 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] | 3870 | }; |
| 3871 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3872 | class HLessThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3873 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3874 | HLessThan(HInstruction* first, HInstruction* second, |
| 3875 | uint32_t dex_pc = kNoDexPc) |
| 3876 | : HCondition(kLessThan, first, second, dex_pc) { |
| 3877 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3878 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3879 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3880 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3881 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3882 | // In the following Evaluate methods, a HCompare instruction has |
| 3883 | // been merged into this HLessThan instruction; evaluate it as |
| 3884 | // `Compare(x, y) < 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3885 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3886 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3887 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3888 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3889 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3890 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3891 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3892 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3893 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3894 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3895 | DECLARE_INSTRUCTION(LessThan); |
| 3896 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3897 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3898 | return kCondLT; |
| 3899 | } |
| 3900 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3901 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3902 | return kCondGE; |
| 3903 | } |
| 3904 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3905 | protected: |
| 3906 | DEFAULT_COPY_CONSTRUCTOR(LessThan); |
| 3907 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3908 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3909 | 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] | 3910 | }; |
| 3911 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3912 | class HLessThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3913 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3914 | HLessThanOrEqual(HInstruction* first, HInstruction* second, |
| 3915 | uint32_t dex_pc = kNoDexPc) |
| 3916 | : HCondition(kLessThanOrEqual, first, second, dex_pc) { |
| 3917 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3918 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3919 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3920 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3921 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3922 | // In the following Evaluate methods, a HCompare instruction has |
| 3923 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3924 | // `Compare(x, y) <= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3925 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3926 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3927 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3928 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3929 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3930 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3931 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3932 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3933 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3934 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3935 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3936 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3937 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3938 | return kCondLE; |
| 3939 | } |
| 3940 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3941 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3942 | return kCondGT; |
| 3943 | } |
| 3944 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3945 | protected: |
| 3946 | DEFAULT_COPY_CONSTRUCTOR(LessThanOrEqual); |
| 3947 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3948 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3949 | 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] | 3950 | }; |
| 3951 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3952 | class HGreaterThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3953 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3954 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3955 | : HCondition(kGreaterThan, first, second, dex_pc) { |
| 3956 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3957 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3958 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3959 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3960 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3961 | // In the following Evaluate methods, a HCompare instruction has |
| 3962 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3963 | // `Compare(x, y) > 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3964 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3965 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3966 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3967 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3968 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3969 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3970 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3971 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3972 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3973 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3974 | DECLARE_INSTRUCTION(GreaterThan); |
| 3975 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3976 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3977 | return kCondGT; |
| 3978 | } |
| 3979 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3980 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3981 | return kCondLE; |
| 3982 | } |
| 3983 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3984 | protected: |
| 3985 | DEFAULT_COPY_CONSTRUCTOR(GreaterThan); |
| 3986 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3987 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3988 | 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] | 3989 | }; |
| 3990 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3991 | class HGreaterThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3992 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3993 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3994 | : HCondition(kGreaterThanOrEqual, first, second, dex_pc) { |
| 3995 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3996 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3997 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3998 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3999 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4000 | // In the following Evaluate methods, a HCompare instruction has |
| 4001 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 4002 | // `Compare(x, y) >= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4003 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4004 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4005 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4006 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4007 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4008 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4009 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4010 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4011 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4012 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4013 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 4014 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4015 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4016 | return kCondGE; |
| 4017 | } |
| 4018 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4019 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4020 | return kCondLT; |
| 4021 | } |
| 4022 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4023 | protected: |
| 4024 | DEFAULT_COPY_CONSTRUCTOR(GreaterThanOrEqual); |
| 4025 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4026 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4027 | 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] | 4028 | }; |
| 4029 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4030 | class HBelow final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4031 | public: |
| 4032 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4033 | : HCondition(kBelow, first, second, dex_pc) { |
| 4034 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4035 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4036 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4037 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4038 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4039 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4040 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4041 | } |
| 4042 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4043 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4044 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4045 | UNREACHABLE(); |
| 4046 | } |
| 4047 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4048 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4049 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4050 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | DECLARE_INSTRUCTION(Below); |
| 4054 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4055 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4056 | return kCondB; |
| 4057 | } |
| 4058 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4059 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4060 | return kCondAE; |
| 4061 | } |
| 4062 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4063 | protected: |
| 4064 | DEFAULT_COPY_CONSTRUCTOR(Below); |
| 4065 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4066 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4067 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4068 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 4069 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4070 | }; |
| 4071 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4072 | class HBelowOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4073 | public: |
| 4074 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4075 | : HCondition(kBelowOrEqual, first, second, dex_pc) { |
| 4076 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4077 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4078 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4079 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4080 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4081 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4082 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4083 | } |
| 4084 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4085 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4086 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4087 | UNREACHABLE(); |
| 4088 | } |
| 4089 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4090 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4091 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4092 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 4096 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4097 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4098 | return kCondBE; |
| 4099 | } |
| 4100 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4101 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4102 | return kCondA; |
| 4103 | } |
| 4104 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4105 | protected: |
| 4106 | DEFAULT_COPY_CONSTRUCTOR(BelowOrEqual); |
| 4107 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4108 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4109 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4110 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 4111 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4112 | }; |
| 4113 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4114 | class HAbove final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4115 | public: |
| 4116 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4117 | : HCondition(kAbove, first, second, dex_pc) { |
| 4118 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4119 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4120 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4121 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4122 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4123 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4124 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4125 | } |
| 4126 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4127 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4128 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4129 | UNREACHABLE(); |
| 4130 | } |
| 4131 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4132 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4133 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4134 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | DECLARE_INSTRUCTION(Above); |
| 4138 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4139 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4140 | return kCondA; |
| 4141 | } |
| 4142 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4143 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4144 | return kCondBE; |
| 4145 | } |
| 4146 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4147 | protected: |
| 4148 | DEFAULT_COPY_CONSTRUCTOR(Above); |
| 4149 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4150 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4151 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4152 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 4153 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4154 | }; |
| 4155 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4156 | class HAboveOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4157 | public: |
| 4158 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4159 | : HCondition(kAboveOrEqual, first, second, dex_pc) { |
| 4160 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4161 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4162 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4163 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4164 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4165 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4166 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4167 | } |
| 4168 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4169 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4170 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4171 | UNREACHABLE(); |
| 4172 | } |
| 4173 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4174 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4175 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4176 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 4180 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4181 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4182 | return kCondAE; |
| 4183 | } |
| 4184 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4185 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4186 | return kCondB; |
| 4187 | } |
| 4188 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4189 | protected: |
| 4190 | DEFAULT_COPY_CONSTRUCTOR(AboveOrEqual); |
| 4191 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4192 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4193 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4194 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 4195 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4196 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4197 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4198 | // Instruction to check how two inputs compare to each other. |
| 4199 | // 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] | 4200 | class HCompare final : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4201 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4202 | // Note that `comparison_type` is the type of comparison performed |
| 4203 | // between the comparison's inputs, not the type of the instantiated |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4204 | // HCompare instruction (which is always DataType::Type::kInt). |
| 4205 | HCompare(DataType::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4206 | HInstruction* first, |
| 4207 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4208 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4209 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4210 | : HBinaryOperation(kCompare, |
| 4211 | DataType::Type::kInt32, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4212 | first, |
| 4213 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4214 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4215 | dex_pc) { |
| 4216 | SetPackedField<ComparisonBiasField>(bias); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4217 | } |
| 4218 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4219 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4220 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 4221 | |
| 4222 | template <typename T> |
| 4223 | int32_t ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4224 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4225 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 4226 | // Handle the bias. |
| 4227 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 4228 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4229 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4230 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4231 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 4232 | // reach this code path when processing a freshly built HIR |
| 4233 | // graph. However HCompare integer instructions can be synthesized |
| 4234 | // by the instruction simplifier to implement IntegerCompare and |
| 4235 | // IntegerSignum intrinsics, so we have to handle this case. |
| 4236 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4237 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4238 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4239 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4240 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4241 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4242 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4243 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4244 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4245 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4246 | } |
| 4247 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4248 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4249 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4250 | } |
| 4251 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4252 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4253 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4254 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4255 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4256 | bool IsGtBias() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4257 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4258 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4259 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4260 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4261 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type type ATTRIBUTE_UNUSED) { |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 4262 | // Comparisons do not require a runtime call in any back end. |
| 4263 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4264 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4265 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4266 | DECLARE_INSTRUCTION(Compare); |
| 4267 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4268 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4269 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4270 | static constexpr size_t kFieldComparisonBiasSize = |
| 4271 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 4272 | static constexpr size_t kNumberOfComparePackedBits = |
| 4273 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 4274 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4275 | using ComparisonBiasField = |
| 4276 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 4277 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4278 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 4279 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 4280 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 4281 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 4282 | } |
| 4283 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4284 | DEFAULT_COPY_CONSTRUCTOR(Compare); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4285 | }; |
| 4286 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4287 | class HNewInstance final : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4288 | public: |
| 4289 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4290 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4291 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4292 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4293 | bool finalizable, |
| 4294 | QuickEntrypointEnum entrypoint) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4295 | : HExpression(kNewInstance, |
| 4296 | DataType::Type::kReference, |
| 4297 | SideEffects::CanTriggerGC(), |
| 4298 | dex_pc), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4299 | type_index_(type_index), |
| 4300 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4301 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4302 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4303 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4304 | } |
| 4305 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4306 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4307 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4308 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4309 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4310 | |
| 4311 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4312 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4313 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4314 | // 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] | 4315 | bool CanThrow() const override { return true; } |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4316 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4317 | bool NeedsChecks() const { |
| 4318 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 4319 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4320 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4321 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4322 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4323 | bool CanBeNull() const override { return false; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4324 | |
| 4325 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4326 | |
| 4327 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 4328 | entrypoint_ = entrypoint; |
| 4329 | } |
| 4330 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4331 | HLoadClass* GetLoadClass() const { |
| 4332 | HInstruction* input = InputAt(0); |
| 4333 | if (input->IsClinitCheck()) { |
| 4334 | input = input->InputAt(0); |
| 4335 | } |
| 4336 | DCHECK(input->IsLoadClass()); |
| 4337 | return input->AsLoadClass(); |
| 4338 | } |
| 4339 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4340 | bool IsStringAlloc() const; |
| 4341 | |
| 4342 | DECLARE_INSTRUCTION(NewInstance); |
| 4343 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4344 | protected: |
| 4345 | DEFAULT_COPY_CONSTRUCTOR(NewInstance); |
| 4346 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4347 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4348 | static constexpr size_t kFlagFinalizable = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4349 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 4350 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 4351 | "Too many packed fields."); |
| 4352 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4353 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4354 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4355 | QuickEntrypointEnum entrypoint_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4356 | }; |
| 4357 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 4358 | enum IntrinsicNeedsEnvironmentOrCache { |
| 4359 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 4360 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4361 | }; |
| 4362 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4363 | enum IntrinsicSideEffects { |
| 4364 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 4365 | kReadSideEffects, // Intrinsic may read heap memory. |
| 4366 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 4367 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 4368 | }; |
| 4369 | |
| 4370 | enum IntrinsicExceptions { |
| 4371 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 4372 | kCanThrow // Intrinsic may throw exceptions. |
| 4373 | }; |
| 4374 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4375 | // Determines how to load an ArtMethod*. |
| 4376 | enum class MethodLoadKind { |
| 4377 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4378 | kStringInit, |
| 4379 | |
| 4380 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4381 | kRecursive, |
| 4382 | |
| 4383 | // Use PC-relative boot image ArtMethod* address that will be known at link time. |
| 4384 | // Used for boot image methods referenced by boot image code. |
| 4385 | kBootImageLinkTimePcRelative, |
| 4386 | |
| 4387 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| 4388 | // Used for app->boot calls with relocatable image. |
| 4389 | kBootImageRelRo, |
| 4390 | |
| 4391 | // Load from an entry in the .bss section using a PC-relative load. |
| 4392 | // Used for methods outside boot image referenced by AOT-compiled app and boot image code. |
| 4393 | kBssEntry, |
| 4394 | |
| 4395 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4396 | // Used for for JIT-compiled calls. |
| 4397 | kJitDirectAddress, |
| 4398 | |
| 4399 | // Make a runtime call to resolve and call the method. This is the last-resort-kind |
| 4400 | // used when other kinds are unimplemented on a particular architecture. |
| 4401 | kRuntimeCall, |
| 4402 | }; |
| 4403 | |
| 4404 | // Determines the location of the code pointer of an invoke. |
| 4405 | enum class CodePtrLocation { |
| 4406 | // Recursive call, use local PC-relative call instruction. |
| 4407 | kCallSelf, |
| 4408 | |
| 4409 | // Use native pointer from the Artmethod*. |
| 4410 | // Used for @CriticalNative to avoid going through the compiled stub. This call goes through |
| 4411 | // a special resolution stub if the class is not initialized or no native code is registered. |
| 4412 | kCallCriticalNative, |
| 4413 | |
| 4414 | // Use code pointer from the ArtMethod*. |
| 4415 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4416 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4417 | kCallArtMethod, |
| 4418 | }; |
| 4419 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4420 | static inline bool IsPcRelativeMethodLoadKind(MethodLoadKind load_kind) { |
| 4421 | return load_kind == MethodLoadKind::kBootImageLinkTimePcRelative || |
| 4422 | load_kind == MethodLoadKind::kBootImageRelRo || |
| 4423 | load_kind == MethodLoadKind::kBssEntry; |
| 4424 | } |
| 4425 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4426 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4427 | public: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4428 | bool NeedsEnvironment() const override; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4429 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 4430 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4431 | SetRawInputAt(index, argument); |
| 4432 | } |
| 4433 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4434 | // Return the number of arguments. This number can be lower than |
| 4435 | // the number of inputs returned by InputCount(), as some invoke |
| 4436 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 4437 | // inputs at the end of their list of inputs. |
| 4438 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 4439 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4440 | InvokeType GetInvokeType() const { |
| 4441 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4442 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4443 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 4444 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4445 | return intrinsic_; |
| 4446 | } |
| 4447 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4448 | void SetIntrinsic(Intrinsics intrinsic, |
| 4449 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 4450 | IntrinsicSideEffects side_effects, |
| 4451 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4452 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4453 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4454 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4455 | } |
| 4456 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4457 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4458 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4459 | bool CanThrow() const override { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4460 | |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4461 | void SetAlwaysThrows(bool always_throws) { SetPackedFlag<kFlagAlwaysThrows>(always_throws); } |
| 4462 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4463 | bool AlwaysThrows() const override { return GetPackedFlag<kFlagAlwaysThrows>(); } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4464 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4465 | bool CanBeMoved() const override { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4466 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4467 | bool InstructionDataEquals(const HInstruction* other) const override { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4468 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 4469 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4470 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4471 | uint32_t* GetIntrinsicOptimizations() { |
| 4472 | return &intrinsic_optimizations_; |
| 4473 | } |
| 4474 | |
| 4475 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4476 | return &intrinsic_optimizations_; |
| 4477 | } |
| 4478 | |
| 4479 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4480 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4481 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4482 | void SetResolvedMethod(ArtMethod* method); |
| 4483 | |
| 4484 | MethodReference GetMethodReference() const { return method_reference_; } |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4485 | |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4486 | const MethodReference GetResolvedMethodReference() const { |
| 4487 | return resolved_method_reference_; |
| 4488 | } |
| 4489 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4490 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4491 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4492 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4493 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4494 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4495 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4496 | static constexpr size_t kFlagCanThrow = kFieldInvokeType + kFieldInvokeTypeSize; |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4497 | static constexpr size_t kFlagAlwaysThrows = kFlagCanThrow + 1; |
| 4498 | static constexpr size_t kNumberOfInvokePackedBits = kFlagAlwaysThrows + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4499 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4500 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4501 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4502 | HInvoke(InstructionKind kind, |
| 4503 | ArenaAllocator* allocator, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4504 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4505 | uint32_t number_of_other_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4506 | DataType::Type return_type, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4507 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4508 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4509 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4510 | MethodReference resolved_method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4511 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4512 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4513 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4514 | return_type, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4515 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4516 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4517 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4518 | number_of_arguments + number_of_other_inputs, |
| 4519 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4520 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4521 | method_reference_(method_reference), |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4522 | resolved_method_reference_(resolved_method_reference), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4523 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4524 | intrinsic_optimizations_(0) { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4525 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4526 | SetPackedFlag<kFlagCanThrow>(true); |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 4527 | SetResolvedMethod(resolved_method); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4528 | } |
| 4529 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4530 | DEFAULT_COPY_CONSTRUCTOR(Invoke); |
| 4531 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4532 | uint32_t number_of_arguments_; |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4533 | ArtMethod* resolved_method_; |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4534 | const MethodReference method_reference_; |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4535 | // Cached values of the resolved method, to avoid needing the mutator lock. |
| 4536 | const MethodReference resolved_method_reference_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4537 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4538 | |
| 4539 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4540 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4541 | }; |
| 4542 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4543 | class HInvokeUnresolved final : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4544 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4545 | HInvokeUnresolved(ArenaAllocator* allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4546 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4547 | DataType::Type return_type, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4548 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4549 | MethodReference method_reference, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4550 | InvokeType invoke_type) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4551 | : HInvoke(kInvokeUnresolved, |
| 4552 | allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4553 | number_of_arguments, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4554 | /* number_of_other_inputs= */ 0u, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4555 | return_type, |
| 4556 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4557 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4558 | nullptr, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4559 | MethodReference(nullptr, 0u), |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4560 | invoke_type) { |
| 4561 | } |
| 4562 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4563 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4564 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4565 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4566 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4567 | protected: |
| 4568 | DEFAULT_COPY_CONSTRUCTOR(InvokeUnresolved); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4569 | }; |
| 4570 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4571 | class HInvokePolymorphic final : public HInvoke { |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4572 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4573 | HInvokePolymorphic(ArenaAllocator* allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4574 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4575 | DataType::Type return_type, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4576 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4577 | MethodReference method_reference, |
Andra Danciu | b931b8c | 2020-07-27 13:16:37 +0000 | [diff] [blame] | 4578 | // resolved_method is the ArtMethod object corresponding to the polymorphic |
| 4579 | // method (e.g. VarHandle.get), resolved using the class linker. It is needed |
| 4580 | // to pass intrinsic information to the HInvokePolymorphic node. |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4581 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4582 | MethodReference resolved_method_reference, |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4583 | dex::ProtoIndex proto_idx) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4584 | : HInvoke(kInvokePolymorphic, |
| 4585 | allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4586 | number_of_arguments, |
Andra Danciu | 49a19f3 | 2020-08-27 12:44:25 +0000 | [diff] [blame] | 4587 | /* number_of_other_inputs= */ 0u, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4588 | return_type, |
| 4589 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4590 | method_reference, |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4591 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4592 | resolved_method_reference, |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4593 | kPolymorphic), |
| 4594 | proto_idx_(proto_idx) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4595 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4596 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4597 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4598 | |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4599 | dex::ProtoIndex GetProtoIndex() { return proto_idx_; } |
| 4600 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4601 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4602 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4603 | protected: |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4604 | dex::ProtoIndex proto_idx_; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4605 | DEFAULT_COPY_CONSTRUCTOR(InvokePolymorphic); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4606 | }; |
| 4607 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4608 | class HInvokeCustom final : public HInvoke { |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4609 | public: |
| 4610 | HInvokeCustom(ArenaAllocator* allocator, |
| 4611 | uint32_t number_of_arguments, |
| 4612 | uint32_t call_site_index, |
| 4613 | DataType::Type return_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4614 | uint32_t dex_pc, |
| 4615 | MethodReference method_reference) |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4616 | : HInvoke(kInvokeCustom, |
| 4617 | allocator, |
| 4618 | number_of_arguments, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4619 | /* number_of_other_inputs= */ 0u, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4620 | return_type, |
| 4621 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4622 | method_reference, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4623 | /* resolved_method= */ nullptr, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4624 | MethodReference(nullptr, 0u), |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4625 | kStatic), |
| 4626 | call_site_index_(call_site_index) { |
| 4627 | } |
| 4628 | |
| 4629 | uint32_t GetCallSiteIndex() const { return call_site_index_; } |
| 4630 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4631 | bool IsClonable() const override { return true; } |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4632 | |
| 4633 | DECLARE_INSTRUCTION(InvokeCustom); |
| 4634 | |
| 4635 | protected: |
| 4636 | DEFAULT_COPY_CONSTRUCTOR(InvokeCustom); |
| 4637 | |
| 4638 | private: |
| 4639 | uint32_t call_site_index_; |
| 4640 | }; |
| 4641 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4642 | class HInvokeStaticOrDirect final : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4643 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4644 | // Requirements of this method call regarding the class |
| 4645 | // initialization (clinit) check of its declaring class. |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 4646 | enum class ClinitCheckRequirement { // private marker to avoid generate-operator-out.py from processing. |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4647 | kNone, // Class already initialized. |
| 4648 | kExplicit, // Static call having explicit clinit check as last input. |
| 4649 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4650 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4651 | }; |
| 4652 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4653 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4654 | MethodLoadKind method_load_kind; |
| 4655 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4656 | // The method load data holds |
| 4657 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4658 | // Note that there are multiple string init methods, each having its own offset. |
| 4659 | // - the method address for kDirectAddress |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4660 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4661 | }; |
| 4662 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4663 | HInvokeStaticOrDirect(ArenaAllocator* allocator, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4664 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4665 | DataType::Type return_type, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4666 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4667 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4668 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4669 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4670 | InvokeType invoke_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4671 | MethodReference resolved_method_reference, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4672 | ClinitCheckRequirement clinit_check_requirement) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4673 | : HInvoke(kInvokeStaticOrDirect, |
| 4674 | allocator, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4675 | number_of_arguments, |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4676 | // There is potentially one extra argument for the HCurrentMethod input, |
| 4677 | // and one other if the clinit check is explicit. These can be removed later. |
| 4678 | (NeedsCurrentMethodInput(dispatch_info) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4679 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4680 | return_type, |
| 4681 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4682 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4683 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4684 | resolved_method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4685 | invoke_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4686 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4687 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4688 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4689 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4690 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4691 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4692 | void SetDispatchInfo(DispatchInfo dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4693 | bool had_current_method_input = HasCurrentMethodInput(); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4694 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4695 | |
| 4696 | // Using the current method is the default and once we find a better |
| 4697 | // method load kind, we should not go back to using the current method. |
| 4698 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4699 | |
| 4700 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4701 | DCHECK_EQ(InputAt(GetCurrentMethodIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4702 | RemoveInputAt(GetCurrentMethodIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4703 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4704 | dispatch_info_ = dispatch_info; |
| 4705 | } |
| 4706 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 4707 | DispatchInfo GetDispatchInfo() const { |
| 4708 | return dispatch_info_; |
| 4709 | } |
| 4710 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4711 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4712 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4713 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4714 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4715 | DCHECK(!input_records.empty()); |
| 4716 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4717 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4718 | // Note: `last_input` may be null during arguments setup. |
| 4719 | if (last_input != nullptr) { |
| 4720 | // `last_input` is the last input of a static invoke marked as having |
| 4721 | // an explicit clinit check. It must either be: |
| 4722 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4723 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4724 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4725 | } |
| 4726 | } |
| 4727 | return input_records; |
| 4728 | } |
| 4729 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4730 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4731 | // We do not access the method via object reference, so we cannot do an implicit null check. |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4732 | // TODO: for intrinsics we can generate implicit null checks. |
| 4733 | return false; |
| 4734 | } |
| 4735 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4736 | bool CanBeNull() const override { |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4737 | return GetType() == DataType::Type::kReference && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4738 | } |
| 4739 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4740 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4741 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4742 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4743 | bool NeedsDexCacheOfDeclaringClass() const override; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4744 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4745 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kJitDirectAddress; } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4746 | bool HasPcRelativeMethodLoadKind() const { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4747 | return IsPcRelativeMethodLoadKind(GetMethodLoadKind()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4748 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4749 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4750 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4751 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4752 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | uint64_t GetMethodAddress() const { |
| 4756 | DCHECK(HasMethodAddress()); |
| 4757 | return dispatch_info_.method_load_data; |
| 4758 | } |
| 4759 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4760 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4761 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4762 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4763 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4764 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4765 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4766 | // Is this instruction a call to a static method? |
| 4767 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4768 | return GetInvokeType() == kStatic; |
| 4769 | } |
| 4770 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4771 | // Does this method load kind need the current method as an input? |
| 4772 | static bool NeedsCurrentMethodInput(DispatchInfo dispatch_info) { |
| 4773 | return dispatch_info.method_load_kind == MethodLoadKind::kRecursive || |
| 4774 | dispatch_info.method_load_kind == MethodLoadKind::kRuntimeCall || |
| 4775 | dispatch_info.code_ptr_location == CodePtrLocation::kCallCriticalNative; |
| 4776 | } |
| 4777 | |
| 4778 | // Get the index of the current method input. |
| 4779 | size_t GetCurrentMethodIndex() const { |
| 4780 | DCHECK(HasCurrentMethodInput()); |
| 4781 | return GetCurrentMethodIndexUnchecked(); |
| 4782 | } |
| 4783 | size_t GetCurrentMethodIndexUnchecked() const { |
| 4784 | return GetNumberOfArguments(); |
| 4785 | } |
| 4786 | |
| 4787 | // Check if the method has a current method input. |
| 4788 | bool HasCurrentMethodInput() const { |
| 4789 | if (NeedsCurrentMethodInput(GetDispatchInfo())) { |
| 4790 | DCHECK(InputAt(GetCurrentMethodIndexUnchecked()) == nullptr || // During argument setup. |
| 4791 | InputAt(GetCurrentMethodIndexUnchecked())->IsCurrentMethod()); |
| 4792 | return true; |
| 4793 | } else { |
| 4794 | DCHECK(InputCount() == GetCurrentMethodIndexUnchecked() || |
| 4795 | InputAt(GetCurrentMethodIndexUnchecked()) == nullptr || // During argument setup. |
| 4796 | !InputAt(GetCurrentMethodIndexUnchecked())->IsCurrentMethod()); |
| 4797 | return false; |
| 4798 | } |
| 4799 | } |
| 4800 | |
| 4801 | // Get the index of the special input. |
| 4802 | size_t GetSpecialInputIndex() const { |
| 4803 | DCHECK(HasSpecialInput()); |
| 4804 | return GetSpecialInputIndexUnchecked(); |
| 4805 | } |
| 4806 | size_t GetSpecialInputIndexUnchecked() const { |
| 4807 | return GetNumberOfArguments() + (HasCurrentMethodInput() ? 1u : 0u); |
| 4808 | } |
| 4809 | |
| 4810 | // Check if the method has a special input. |
| 4811 | bool HasSpecialInput() const { |
| 4812 | size_t other_inputs = |
| 4813 | GetSpecialInputIndexUnchecked() + (IsStaticWithExplicitClinitCheck() ? 1u : 0u); |
| 4814 | size_t input_count = InputCount(); |
| 4815 | DCHECK_LE(input_count - other_inputs, 1u) << other_inputs << " " << input_count; |
| 4816 | return other_inputs != input_count; |
| 4817 | } |
| 4818 | |
| 4819 | void AddSpecialInput(HInstruction* input) { |
| 4820 | // We allow only one special input. |
| 4821 | DCHECK(!HasSpecialInput()); |
| 4822 | InsertInputAt(GetSpecialInputIndexUnchecked(), input); |
| 4823 | } |
| 4824 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4825 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4826 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4827 | // instruction; only relevant for static calls with explicit clinit check. |
| 4828 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4829 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4830 | size_t last_input_index = inputs_.size() - 1u; |
| 4831 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4832 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4833 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4834 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4835 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4836 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4837 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | // 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] | 4841 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4842 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4843 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | // Is this a call to a static method whose declaring class has an |
| 4847 | // implicit intialization check requirement? |
| 4848 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4849 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4850 | } |
| 4851 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4852 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4853 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4854 | protected: |
| 4855 | DEFAULT_COPY_CONSTRUCTOR(InvokeStaticOrDirect); |
| 4856 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4857 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4858 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4859 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4860 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4861 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4862 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4863 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4864 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4865 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4866 | kFieldClinitCheckRequirement, |
| 4867 | kFieldClinitCheckRequirementSize>; |
| 4868 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4869 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4870 | }; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4871 | std::ostream& operator<<(std::ostream& os, MethodLoadKind rhs); |
| 4872 | std::ostream& operator<<(std::ostream& os, CodePtrLocation rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4873 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4874 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4875 | class HInvokeVirtual final : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4876 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4877 | HInvokeVirtual(ArenaAllocator* allocator, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4878 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4879 | DataType::Type return_type, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4880 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4881 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4882 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4883 | MethodReference resolved_method_reference, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4884 | uint32_t vtable_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4885 | : HInvoke(kInvokeVirtual, |
| 4886 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4887 | number_of_arguments, |
| 4888 | 0u, |
| 4889 | return_type, |
| 4890 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4891 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4892 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4893 | resolved_method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4894 | kVirtual), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4895 | vtable_index_(vtable_index) { |
| 4896 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4897 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4898 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4899 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4900 | bool CanBeNull() const override { |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4901 | switch (GetIntrinsic()) { |
| 4902 | case Intrinsics::kThreadCurrentThread: |
| 4903 | case Intrinsics::kStringBufferAppend: |
| 4904 | case Intrinsics::kStringBufferToString: |
Vladimir Marko | d456117 | 2017-10-30 17:48:25 +0000 | [diff] [blame] | 4905 | case Intrinsics::kStringBuilderAppendObject: |
| 4906 | case Intrinsics::kStringBuilderAppendString: |
| 4907 | case Intrinsics::kStringBuilderAppendCharSequence: |
| 4908 | case Intrinsics::kStringBuilderAppendCharArray: |
| 4909 | case Intrinsics::kStringBuilderAppendBoolean: |
| 4910 | case Intrinsics::kStringBuilderAppendChar: |
| 4911 | case Intrinsics::kStringBuilderAppendInt: |
| 4912 | case Intrinsics::kStringBuilderAppendLong: |
| 4913 | case Intrinsics::kStringBuilderAppendFloat: |
| 4914 | case Intrinsics::kStringBuilderAppendDouble: |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4915 | case Intrinsics::kStringBuilderToString: |
| 4916 | return false; |
| 4917 | default: |
| 4918 | return HInvoke::CanBeNull(); |
| 4919 | } |
| 4920 | } |
| 4921 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4922 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4923 | // TODO: Add implicit null checks in intrinsics. |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 4924 | return (obj == InputAt(0)) && !IsIntrinsic(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4927 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4928 | |
| 4929 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4930 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4931 | protected: |
| 4932 | DEFAULT_COPY_CONSTRUCTOR(InvokeVirtual); |
| 4933 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4934 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4935 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4936 | const uint32_t vtable_index_; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4937 | }; |
| 4938 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4939 | class HInvokeInterface final : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4940 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4941 | HInvokeInterface(ArenaAllocator* allocator, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4942 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4943 | DataType::Type return_type, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4944 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4945 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4946 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4947 | MethodReference resolved_method_reference, |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4948 | uint32_t imt_index, |
| 4949 | MethodLoadKind load_kind) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4950 | : HInvoke(kInvokeInterface, |
| 4951 | allocator, |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4952 | number_of_arguments + (NeedsCurrentMethod(load_kind) ? 1 : 0), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4953 | 0u, |
| 4954 | return_type, |
| 4955 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4956 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4957 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4958 | resolved_method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4959 | kInterface), |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4960 | imt_index_(imt_index), |
| 4961 | hidden_argument_load_kind_(load_kind) { |
| 4962 | } |
| 4963 | |
| 4964 | static bool NeedsCurrentMethod(MethodLoadKind load_kind) { |
| 4965 | return load_kind == MethodLoadKind::kRecursive; |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4966 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4967 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4968 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4969 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4970 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4971 | // TODO: Add implicit null checks in intrinsics. |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 4972 | return (obj == InputAt(0)) && !IsIntrinsic(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4973 | } |
| 4974 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4975 | bool NeedsDexCacheOfDeclaringClass() const override { |
Nicolas Geoffray | fbdfa6d | 2017-02-03 10:43:13 +0000 | [diff] [blame] | 4976 | // The assembly stub currently needs it. |
| 4977 | return true; |
| 4978 | } |
| 4979 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4980 | size_t GetSpecialInputIndex() const { |
| 4981 | return GetNumberOfArguments(); |
| 4982 | } |
| 4983 | |
| 4984 | void AddSpecialInput(HInstruction* input) { |
| 4985 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4986 | } |
| 4987 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4988 | uint32_t GetImtIndex() const { return imt_index_; } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4989 | MethodLoadKind GetHiddenArgumentLoadKind() const { return hidden_argument_load_kind_; } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4990 | |
| 4991 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4992 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4993 | protected: |
| 4994 | DEFAULT_COPY_CONSTRUCTOR(InvokeInterface); |
| 4995 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4996 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4997 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4998 | const uint32_t imt_index_; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4999 | |
| 5000 | // How the hidden argument (the interface method) is being loaded. |
| 5001 | const MethodLoadKind hidden_argument_load_kind_; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5002 | }; |
| 5003 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5004 | class HNeg final : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5005 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5006 | 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] | 5007 | : HUnaryOperation(kNeg, result_type, input, dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5008 | DCHECK_EQ(result_type, DataType::Kind(input->GetType())); |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 5009 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5010 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5011 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5012 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5013 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5014 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5015 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5016 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5017 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5018 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5019 | HConstant* Evaluate(HFloatConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5020 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 5021 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5022 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5023 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 5024 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 5025 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5026 | DECLARE_INSTRUCTION(Neg); |
| 5027 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5028 | protected: |
| 5029 | DEFAULT_COPY_CONSTRUCTOR(Neg); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5030 | }; |
| 5031 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5032 | class HNewArray final : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5033 | public: |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5034 | HNewArray(HInstruction* cls, HInstruction* length, uint32_t dex_pc, size_t component_size_shift) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5035 | : HExpression(kNewArray, DataType::Type::kReference, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5036 | SetRawInputAt(0, cls); |
| 5037 | SetRawInputAt(1, length); |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5038 | SetPackedField<ComponentSizeShiftField>(component_size_shift); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5039 | } |
| 5040 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5041 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5042 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5043 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5044 | bool NeedsEnvironment() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5045 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 5046 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5047 | bool CanThrow() const override { return true; } |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 5048 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5049 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5050 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5051 | HLoadClass* GetLoadClass() const { |
| 5052 | DCHECK(InputAt(0)->IsLoadClass()); |
| 5053 | return InputAt(0)->AsLoadClass(); |
| 5054 | } |
| 5055 | |
| 5056 | HInstruction* GetLength() const { |
| 5057 | return InputAt(1); |
| 5058 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 5059 | |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5060 | size_t GetComponentSizeShift() { |
| 5061 | return GetPackedField<ComponentSizeShiftField>(); |
| 5062 | } |
| 5063 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5064 | DECLARE_INSTRUCTION(NewArray); |
| 5065 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5066 | protected: |
| 5067 | DEFAULT_COPY_CONSTRUCTOR(NewArray); |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5068 | |
| 5069 | private: |
| 5070 | static constexpr size_t kFieldComponentSizeShift = kNumberOfGenericPackedBits; |
| 5071 | static constexpr size_t kFieldComponentSizeShiftSize = MinimumBitsToStore(3u); |
| 5072 | static constexpr size_t kNumberOfNewArrayPackedBits = |
| 5073 | kFieldComponentSizeShift + kFieldComponentSizeShiftSize; |
| 5074 | static_assert(kNumberOfNewArrayPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5075 | using ComponentSizeShiftField = |
| 5076 | BitField<size_t, kFieldComponentSizeShift, kFieldComponentSizeShift>; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5077 | }; |
| 5078 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5079 | class HAdd final : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5080 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5081 | HAdd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5082 | HInstruction* left, |
| 5083 | HInstruction* right, |
| 5084 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5085 | : HBinaryOperation(kAdd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5086 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5087 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5088 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5089 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5090 | 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] | 5091 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5092 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5093 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5094 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5095 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5096 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5097 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5098 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5099 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5100 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5101 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5102 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5103 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5104 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5105 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5106 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5107 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 5108 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5109 | DECLARE_INSTRUCTION(Add); |
| 5110 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5111 | protected: |
| 5112 | DEFAULT_COPY_CONSTRUCTOR(Add); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5113 | }; |
| 5114 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5115 | class HSub final : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5116 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5117 | HSub(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5118 | HInstruction* left, |
| 5119 | HInstruction* right, |
| 5120 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5121 | : HBinaryOperation(kSub, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5122 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5123 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5124 | 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] | 5125 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5126 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5127 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5128 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5129 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5130 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5131 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5132 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5133 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5134 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5135 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5136 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5137 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5138 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5139 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5140 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5141 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 5142 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5143 | DECLARE_INSTRUCTION(Sub); |
| 5144 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5145 | protected: |
| 5146 | DEFAULT_COPY_CONSTRUCTOR(Sub); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5147 | }; |
| 5148 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5149 | class HMul final : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5150 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5151 | HMul(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5152 | HInstruction* left, |
| 5153 | HInstruction* right, |
| 5154 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5155 | : HBinaryOperation(kMul, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5156 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5157 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5158 | bool IsCommutative() const override { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5159 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5160 | 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] | 5161 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5162 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5163 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5164 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5165 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5166 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5167 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5168 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5169 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5170 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5171 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5172 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5173 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5174 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5175 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5176 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5177 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5178 | |
| 5179 | DECLARE_INSTRUCTION(Mul); |
| 5180 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5181 | protected: |
| 5182 | DEFAULT_COPY_CONSTRUCTOR(Mul); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5183 | }; |
| 5184 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5185 | class HDiv final : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5186 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5187 | HDiv(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5188 | HInstruction* left, |
| 5189 | HInstruction* right, |
| 5190 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5191 | : HBinaryOperation(kDiv, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5192 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5193 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5194 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5195 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5196 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5197 | // Our graph structure ensures we never have 0 for `y` during |
| 5198 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5199 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5200 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5201 | return (y == -1) ? -x : x / y; |
| 5202 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5203 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5204 | template <typename T> |
| 5205 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5206 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5207 | return x / y; |
| 5208 | } |
| 5209 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5210 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5211 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5212 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5213 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5214 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5215 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5216 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5217 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5218 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5219 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5220 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5221 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5222 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5223 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5224 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5225 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5226 | |
| 5227 | DECLARE_INSTRUCTION(Div); |
| 5228 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5229 | protected: |
| 5230 | DEFAULT_COPY_CONSTRUCTOR(Div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5231 | }; |
| 5232 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5233 | class HRem final : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5234 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5235 | HRem(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5236 | HInstruction* left, |
| 5237 | HInstruction* right, |
| 5238 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5239 | : HBinaryOperation(kRem, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5240 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5241 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5242 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5243 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5244 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5245 | // Our graph structure ensures we never have 0 for `y` during |
| 5246 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5247 | DCHECK_NE(y, 0); |
| 5248 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 5249 | return (y == -1) ? 0 : x % y; |
| 5250 | } |
| 5251 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5252 | template <typename T> |
| 5253 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5254 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5255 | return std::fmod(x, y); |
| 5256 | } |
| 5257 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5258 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5259 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5260 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5261 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5262 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5263 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5264 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5265 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5266 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5267 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5268 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5269 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5270 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5271 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5272 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5273 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5274 | |
| 5275 | DECLARE_INSTRUCTION(Rem); |
| 5276 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5277 | protected: |
| 5278 | DEFAULT_COPY_CONSTRUCTOR(Rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5279 | }; |
| 5280 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5281 | class HMin final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5282 | public: |
| 5283 | HMin(DataType::Type result_type, |
| 5284 | HInstruction* left, |
| 5285 | HInstruction* right, |
| 5286 | uint32_t dex_pc) |
| 5287 | : HBinaryOperation(kMin, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5288 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5289 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5290 | |
| 5291 | // Evaluation for integral values. |
| 5292 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5293 | return (x <= y) ? x : y; |
| 5294 | } |
| 5295 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5296 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5297 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5298 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5299 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5300 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5301 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5302 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5303 | } |
| 5304 | // TODO: Evaluation for floating-point values. |
| 5305 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5306 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5307 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5308 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5309 | |
| 5310 | DECLARE_INSTRUCTION(Min); |
| 5311 | |
| 5312 | protected: |
| 5313 | DEFAULT_COPY_CONSTRUCTOR(Min); |
| 5314 | }; |
| 5315 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5316 | class HMax final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5317 | public: |
| 5318 | HMax(DataType::Type result_type, |
| 5319 | HInstruction* left, |
| 5320 | HInstruction* right, |
| 5321 | uint32_t dex_pc) |
| 5322 | : HBinaryOperation(kMax, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5323 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5324 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5325 | |
| 5326 | // Evaluation for integral values. |
| 5327 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5328 | return (x >= y) ? x : y; |
| 5329 | } |
| 5330 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5331 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5332 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5333 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5334 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5335 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5336 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5337 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5338 | } |
| 5339 | // TODO: Evaluation for floating-point values. |
| 5340 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5341 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5342 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5343 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5344 | |
| 5345 | DECLARE_INSTRUCTION(Max); |
| 5346 | |
| 5347 | protected: |
| 5348 | DEFAULT_COPY_CONSTRUCTOR(Max); |
| 5349 | }; |
| 5350 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5351 | class HAbs final : public HUnaryOperation { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5352 | public: |
| 5353 | HAbs(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5354 | : HUnaryOperation(kAbs, result_type, input, dex_pc) {} |
| 5355 | |
| 5356 | // Evaluation for integral values. |
| 5357 | template <typename T> static T ComputeIntegral(T x) { |
| 5358 | return x < 0 ? -x : x; |
| 5359 | } |
| 5360 | |
| 5361 | // Evaluation for floating-point values. |
| 5362 | // Note, as a "quality of implementation", rather than pure "spec compliance", |
| 5363 | // we require that Math.abs() clears the sign bit (but changes nothing else) |
| 5364 | // for all floating-point numbers, including NaN (signaling NaN may become quiet though). |
| 5365 | // http://b/30758343 |
| 5366 | template <typename T, typename S> static T ComputeFP(T x) { |
| 5367 | S bits = bit_cast<S, T>(x); |
| 5368 | return bit_cast<T, S>(bits & std::numeric_limits<S>::max()); |
| 5369 | } |
| 5370 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5371 | HConstant* Evaluate(HIntConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5372 | return GetBlock()->GetGraph()->GetIntConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5373 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5374 | HConstant* Evaluate(HLongConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5375 | return GetBlock()->GetGraph()->GetLongConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5376 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5377 | HConstant* Evaluate(HFloatConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5378 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5379 | ComputeFP<float, int32_t>(x->GetValue()), GetDexPc()); |
| 5380 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5381 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5382 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5383 | ComputeFP<double, int64_t>(x->GetValue()), GetDexPc()); |
| 5384 | } |
| 5385 | |
| 5386 | DECLARE_INSTRUCTION(Abs); |
| 5387 | |
| 5388 | protected: |
| 5389 | DEFAULT_COPY_CONSTRUCTOR(Abs); |
| 5390 | }; |
| 5391 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5392 | class HDivZeroCheck final : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5393 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 5394 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5395 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5396 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5397 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5398 | : HExpression(kDivZeroCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5399 | SetRawInputAt(0, value); |
| 5400 | } |
| 5401 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5402 | bool IsClonable() const override { return true; } |
| 5403 | bool CanBeMoved() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5404 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5405 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5406 | return true; |
| 5407 | } |
| 5408 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5409 | bool NeedsEnvironment() const override { return true; } |
| 5410 | bool CanThrow() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5411 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5412 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 5413 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5414 | protected: |
| 5415 | DEFAULT_COPY_CONSTRUCTOR(DivZeroCheck); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5416 | }; |
| 5417 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5418 | class HShl final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5419 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5420 | HShl(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5421 | HInstruction* value, |
| 5422 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5423 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5424 | : HBinaryOperation(kShl, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5425 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5426 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5427 | } |
| 5428 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5429 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5430 | 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] | 5431 | return value << (distance & max_shift_distance); |
| 5432 | } |
| 5433 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5434 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5435 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5436 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5437 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5438 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5439 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5440 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5441 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5442 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5443 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5444 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5445 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5446 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5447 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5448 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5449 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5450 | UNREACHABLE(); |
| 5451 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5452 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5453 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5454 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5455 | UNREACHABLE(); |
| 5456 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5457 | |
| 5458 | DECLARE_INSTRUCTION(Shl); |
| 5459 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5460 | protected: |
| 5461 | DEFAULT_COPY_CONSTRUCTOR(Shl); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5462 | }; |
| 5463 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5464 | class HShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5465 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5466 | HShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5467 | HInstruction* value, |
| 5468 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5469 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5470 | : HBinaryOperation(kShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5471 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5472 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5473 | } |
| 5474 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5475 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5476 | 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] | 5477 | return value >> (distance & max_shift_distance); |
| 5478 | } |
| 5479 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5480 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5481 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5482 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5483 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5484 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5485 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5486 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5487 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5488 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5489 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5490 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5491 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5492 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5493 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5494 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5495 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5496 | UNREACHABLE(); |
| 5497 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5498 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5499 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5500 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5501 | UNREACHABLE(); |
| 5502 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5503 | |
| 5504 | DECLARE_INSTRUCTION(Shr); |
| 5505 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5506 | protected: |
| 5507 | DEFAULT_COPY_CONSTRUCTOR(Shr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5508 | }; |
| 5509 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5510 | class HUShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5511 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5512 | HUShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5513 | HInstruction* value, |
| 5514 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5515 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5516 | : HBinaryOperation(kUShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5517 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5518 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5519 | } |
| 5520 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5521 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5522 | 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] | 5523 | typedef typename std::make_unsigned<T>::type V; |
| 5524 | V ux = static_cast<V>(value); |
| 5525 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 5526 | } |
| 5527 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5528 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5529 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5530 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5531 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5532 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5533 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5534 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5535 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5536 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5537 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5538 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5539 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5540 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5541 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5542 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5543 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5544 | UNREACHABLE(); |
| 5545 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5546 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5547 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5548 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5549 | UNREACHABLE(); |
| 5550 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5551 | |
| 5552 | DECLARE_INSTRUCTION(UShr); |
| 5553 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5554 | protected: |
| 5555 | DEFAULT_COPY_CONSTRUCTOR(UShr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5556 | }; |
| 5557 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5558 | class HAnd final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5559 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5560 | HAnd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5561 | HInstruction* left, |
| 5562 | HInstruction* right, |
| 5563 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5564 | : HBinaryOperation(kAnd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5565 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5566 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5567 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5568 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5569 | 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] | 5570 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5571 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5572 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5573 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5574 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5575 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5576 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5577 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5578 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5579 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5580 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5581 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5582 | UNREACHABLE(); |
| 5583 | } |
| 5584 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5585 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5586 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5587 | UNREACHABLE(); |
| 5588 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5589 | |
| 5590 | DECLARE_INSTRUCTION(And); |
| 5591 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5592 | protected: |
| 5593 | DEFAULT_COPY_CONSTRUCTOR(And); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5594 | }; |
| 5595 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5596 | class HOr final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5597 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5598 | HOr(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5599 | HInstruction* left, |
| 5600 | HInstruction* right, |
| 5601 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5602 | : HBinaryOperation(kOr, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5603 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5604 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5605 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5606 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5607 | 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] | 5608 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5609 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5610 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5611 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5612 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5613 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5614 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5615 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5616 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5617 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5618 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5619 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5620 | UNREACHABLE(); |
| 5621 | } |
| 5622 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5623 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5624 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5625 | UNREACHABLE(); |
| 5626 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5627 | |
| 5628 | DECLARE_INSTRUCTION(Or); |
| 5629 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5630 | protected: |
| 5631 | DEFAULT_COPY_CONSTRUCTOR(Or); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5632 | }; |
| 5633 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5634 | class HXor final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5635 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5636 | HXor(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5637 | HInstruction* left, |
| 5638 | HInstruction* right, |
| 5639 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5640 | : HBinaryOperation(kXor, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5641 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5642 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5643 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5644 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5645 | 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] | 5646 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5647 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5648 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5649 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5650 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5651 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5652 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5653 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5654 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5655 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5656 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5657 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5658 | UNREACHABLE(); |
| 5659 | } |
| 5660 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5661 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5662 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5663 | UNREACHABLE(); |
| 5664 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5665 | |
| 5666 | DECLARE_INSTRUCTION(Xor); |
| 5667 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5668 | protected: |
| 5669 | DEFAULT_COPY_CONSTRUCTOR(Xor); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5670 | }; |
| 5671 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5672 | class HRor final : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5673 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5674 | HRor(DataType::Type result_type, HInstruction* value, HInstruction* distance) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5675 | : HBinaryOperation(kRor, result_type, value, distance) { |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5676 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5677 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5678 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5679 | 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] | 5680 | typedef typename std::make_unsigned<T>::type V; |
| 5681 | V ux = static_cast<V>(value); |
| 5682 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5683 | return static_cast<T>(ux); |
| 5684 | } else { |
| 5685 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5686 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 5687 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5688 | } |
| 5689 | } |
| 5690 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5691 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5692 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5693 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5694 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5695 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5696 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5697 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5698 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5699 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5700 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5701 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5702 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5703 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5704 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5705 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5706 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5707 | UNREACHABLE(); |
| 5708 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5709 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5710 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5711 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5712 | UNREACHABLE(); |
| 5713 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5714 | |
| 5715 | DECLARE_INSTRUCTION(Ror); |
| 5716 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5717 | protected: |
| 5718 | DEFAULT_COPY_CONSTRUCTOR(Ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5719 | }; |
| 5720 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5721 | // The value of a parameter in this method. Its location depends on |
| 5722 | // the calling convention. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5723 | class HParameterValue final : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5724 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5725 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5726 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5727 | uint8_t index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5728 | DataType::Type parameter_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5729 | bool is_this = false) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5730 | : HExpression(kParameterValue, parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5731 | dex_file_(dex_file), |
| 5732 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5733 | index_(index) { |
| 5734 | SetPackedFlag<kFlagIsThis>(is_this); |
| 5735 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 5736 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5737 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5738 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5739 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5740 | uint8_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5741 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5742 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5743 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5744 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5745 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5746 | DECLARE_INSTRUCTION(ParameterValue); |
| 5747 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5748 | protected: |
| 5749 | DEFAULT_COPY_CONSTRUCTOR(ParameterValue); |
| 5750 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5751 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5752 | // Whether or not the parameter value corresponds to 'this' argument. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5753 | static constexpr size_t kFlagIsThis = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5754 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 5755 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 5756 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 5757 | "Too many packed fields."); |
| 5758 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5759 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5760 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5761 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5762 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5763 | const uint8_t index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5764 | }; |
| 5765 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5766 | class HNot final : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5767 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5768 | 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] | 5769 | : HUnaryOperation(kNot, result_type, input, dex_pc) { |
| 5770 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5771 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5772 | bool CanBeMoved() const override { return true; } |
| 5773 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5774 | return true; |
| 5775 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5776 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5777 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5778 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5779 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5780 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5781 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5782 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5783 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5784 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5785 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5786 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5787 | UNREACHABLE(); |
| 5788 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5789 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5790 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5791 | UNREACHABLE(); |
| 5792 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5793 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5794 | DECLARE_INSTRUCTION(Not); |
| 5795 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5796 | protected: |
| 5797 | DEFAULT_COPY_CONSTRUCTOR(Not); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5798 | }; |
| 5799 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5800 | class HBooleanNot final : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5801 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5802 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5803 | : HUnaryOperation(kBooleanNot, DataType::Type::kBool, input, dex_pc) { |
| 5804 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5805 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5806 | bool CanBeMoved() const override { return true; } |
| 5807 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5808 | return true; |
| 5809 | } |
| 5810 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5811 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5812 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5813 | return !x; |
| 5814 | } |
| 5815 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5816 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5817 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5818 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5819 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5820 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5821 | UNREACHABLE(); |
| 5822 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5823 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5824 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5825 | UNREACHABLE(); |
| 5826 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5827 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5828 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5829 | UNREACHABLE(); |
| 5830 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5831 | |
| 5832 | DECLARE_INSTRUCTION(BooleanNot); |
| 5833 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5834 | protected: |
| 5835 | DEFAULT_COPY_CONSTRUCTOR(BooleanNot); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5836 | }; |
| 5837 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5838 | class HTypeConversion final : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5839 | public: |
| 5840 | // Instantiate a type conversion of `input` to `result_type`. |
Vladimir Marko | c8fb211 | 2017-10-03 11:37:52 +0100 | [diff] [blame] | 5841 | 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] | 5842 | : HExpression(kTypeConversion, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5843 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5844 | // Invariant: We should never generate a conversion to a Boolean value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5845 | DCHECK_NE(DataType::Type::kBool, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5849 | DataType::Type GetInputType() const { return GetInput()->GetType(); } |
| 5850 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5851 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5852 | bool IsClonable() const override { return true; } |
| 5853 | bool CanBeMoved() const override { return true; } |
| 5854 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5855 | return true; |
| 5856 | } |
Nicolas Geoffray | acc56ac | 2018-10-09 08:45:24 +0100 | [diff] [blame] | 5857 | // Return whether the conversion is implicit. This includes conversion to the same type. |
| 5858 | bool IsImplicitConversion() const { |
| 5859 | return DataType::IsTypeConversionImplicit(GetInputType(), GetResultType()); |
| 5860 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5861 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5862 | // Try to statically evaluate the conversion and return a HConstant |
| 5863 | // containing the result. If the input cannot be converted, return nullptr. |
| 5864 | HConstant* TryStaticEvaluation() const; |
| 5865 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5866 | DECLARE_INSTRUCTION(TypeConversion); |
| 5867 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5868 | protected: |
| 5869 | DEFAULT_COPY_CONSTRUCTOR(TypeConversion); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5870 | }; |
| 5871 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5872 | static constexpr uint32_t kNoRegNumber = -1; |
| 5873 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5874 | class HNullCheck final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5875 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5876 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5877 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5878 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5879 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5880 | : HExpression(kNullCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5881 | SetRawInputAt(0, value); |
| 5882 | } |
| 5883 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5884 | bool IsClonable() const override { return true; } |
| 5885 | bool CanBeMoved() const override { return true; } |
| 5886 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5887 | return true; |
| 5888 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5889 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5890 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5891 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5892 | bool CanThrow() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5893 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5894 | bool CanBeNull() const override { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5895 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5896 | DECLARE_INSTRUCTION(NullCheck); |
| 5897 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5898 | protected: |
| 5899 | DEFAULT_COPY_CONSTRUCTOR(NullCheck); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5900 | }; |
| 5901 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5902 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5903 | // 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] | 5904 | class FieldInfo : public ValueObject { |
| 5905 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5906 | FieldInfo(ArtField* field, |
| 5907 | MemberOffset field_offset, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5908 | DataType::Type field_type, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5909 | bool is_volatile, |
| 5910 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5911 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5912 | const DexFile& dex_file) |
| 5913 | : field_(field), |
| 5914 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5915 | field_type_(field_type), |
| 5916 | is_volatile_(is_volatile), |
| 5917 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5918 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5919 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5920 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5921 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5922 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5923 | DataType::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5924 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5925 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5926 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5927 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5928 | |
| 5929 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5930 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5931 | const MemberOffset field_offset_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5932 | const DataType::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5933 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5934 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5935 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5936 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5937 | }; |
| 5938 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5939 | class HInstanceFieldGet final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5940 | public: |
| 5941 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5942 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5943 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5944 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5945 | bool is_volatile, |
| 5946 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5947 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5948 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5949 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5950 | : HExpression(kInstanceFieldGet, |
| 5951 | field_type, |
| 5952 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5953 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5954 | field_info_(field, |
| 5955 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5956 | field_type, |
| 5957 | is_volatile, |
| 5958 | field_idx, |
| 5959 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5960 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5961 | SetRawInputAt(0, value); |
| 5962 | } |
| 5963 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5964 | bool IsClonable() const override { return true; } |
| 5965 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5966 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5967 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5968 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5969 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5970 | } |
| 5971 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5972 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5973 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5974 | } |
| 5975 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5976 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5977 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5978 | } |
| 5979 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5980 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5981 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5982 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5983 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5984 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5985 | void SetType(DataType::Type new_type) { |
| 5986 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5987 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5988 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5989 | SetPackedField<TypeField>(new_type); |
| 5990 | } |
| 5991 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5992 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5993 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5994 | protected: |
| 5995 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldGet); |
| 5996 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5997 | private: |
| 5998 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5999 | }; |
| 6000 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6001 | class HInstanceFieldSet final : public HExpression<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6002 | public: |
| 6003 | HInstanceFieldSet(HInstruction* object, |
| 6004 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6005 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6006 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6007 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6008 | bool is_volatile, |
| 6009 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6010 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6011 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6012 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6013 | : HExpression(kInstanceFieldSet, |
| 6014 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 6015 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6016 | field_info_(field, |
| 6017 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6018 | field_type, |
| 6019 | is_volatile, |
| 6020 | field_idx, |
| 6021 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6022 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6023 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6024 | SetRawInputAt(0, object); |
| 6025 | SetRawInputAt(1, value); |
| 6026 | } |
| 6027 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6028 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6029 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6030 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 6031 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6032 | } |
| 6033 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6034 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6035 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6036 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6037 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6038 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6039 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6040 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6041 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6042 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 6043 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6044 | protected: |
| 6045 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldSet); |
| 6046 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6047 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6048 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6049 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6050 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6051 | "Too many packed fields."); |
| 6052 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6053 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6054 | }; |
| 6055 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6056 | class HArrayGet final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6057 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6058 | HArrayGet(HInstruction* array, |
| 6059 | HInstruction* index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6060 | DataType::Type type, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6061 | uint32_t dex_pc) |
| 6062 | : HArrayGet(array, |
| 6063 | index, |
| 6064 | type, |
| 6065 | SideEffects::ArrayReadOfType(type), |
| 6066 | dex_pc, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6067 | /* is_string_char_at= */ false) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6068 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6069 | |
| 6070 | HArrayGet(HInstruction* array, |
| 6071 | HInstruction* index, |
| 6072 | DataType::Type type, |
| 6073 | SideEffects side_effects, |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6074 | uint32_t dex_pc, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6075 | bool is_string_char_at) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6076 | : HExpression(kArrayGet, type, side_effects, dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6077 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6078 | SetRawInputAt(0, array); |
| 6079 | SetRawInputAt(1, index); |
| 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 ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6088 | // TODO: We can be smarter here. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6089 | // Currently, unless the array is the result of NewArray, the array access is always |
| 6090 | // preceded by some form of null NullCheck necessary for the bounds check, usually |
| 6091 | // implicit null check on the ArrayLength input to BoundsCheck or Deoptimize for |
| 6092 | // dynamic BCE. There are cases when these could be removed to produce better code. |
| 6093 | // If we ever add optimizations to do so we should allow an implicit check here |
| 6094 | // (as long as the address falls in the first page). |
| 6095 | // |
| 6096 | // As an example of such fancy optimization, we could eliminate BoundsCheck for |
| 6097 | // a = cond ? new int[1] : null; |
| 6098 | // a[0]; // The Phi does not need bounds check for either input. |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6099 | return false; |
| 6100 | } |
| 6101 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 6102 | bool IsEquivalentOf(HArrayGet* other) const { |
| 6103 | bool result = (GetDexPc() == other->GetDexPc()); |
| 6104 | if (kIsDebugBuild && result) { |
| 6105 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 6106 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 6107 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6108 | if (DataType::IsIntOrLongType(GetType())) { |
| 6109 | DCHECK(DataType::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 6110 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6111 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| 6112 | DCHECK(DataType::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 6113 | } |
| 6114 | } |
| 6115 | return result; |
| 6116 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6117 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6118 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 6119 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6120 | HInstruction* GetArray() const { return InputAt(0); } |
| 6121 | HInstruction* GetIndex() const { return InputAt(1); } |
| 6122 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6123 | void SetType(DataType::Type new_type) { |
| 6124 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6125 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6126 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6127 | SetPackedField<TypeField>(new_type); |
| 6128 | } |
| 6129 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6130 | DECLARE_INSTRUCTION(ArrayGet); |
| 6131 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6132 | protected: |
| 6133 | DEFAULT_COPY_CONSTRUCTOR(ArrayGet); |
| 6134 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6135 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6136 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 6137 | // intrinsic in the instruction simplifier. We can always determine whether |
| 6138 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 6139 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 6140 | // 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] | 6141 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6142 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 6143 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6144 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6145 | }; |
| 6146 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6147 | class HArraySet final : public HExpression<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6148 | public: |
| 6149 | HArraySet(HInstruction* array, |
| 6150 | HInstruction* index, |
| 6151 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6152 | DataType::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 6153 | uint32_t dex_pc) |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6154 | : HArraySet(array, |
| 6155 | index, |
| 6156 | value, |
| 6157 | expected_component_type, |
| 6158 | // Make a best guess for side effects now, may be refined during SSA building. |
| 6159 | ComputeSideEffects(GetComponentType(value->GetType(), expected_component_type)), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6160 | dex_pc) { |
| 6161 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6162 | |
| 6163 | HArraySet(HInstruction* array, |
| 6164 | HInstruction* index, |
| 6165 | HInstruction* value, |
| 6166 | DataType::Type expected_component_type, |
| 6167 | SideEffects side_effects, |
| 6168 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6169 | : HExpression(kArraySet, side_effects, dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6170 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6171 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6172 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 6173 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6174 | SetRawInputAt(0, array); |
| 6175 | SetRawInputAt(1, index); |
| 6176 | SetRawInputAt(2, value); |
| 6177 | } |
| 6178 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6179 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6180 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6181 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6182 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6183 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6184 | } |
| 6185 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 6186 | // Can throw ArrayStoreException. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6187 | bool CanThrow() const override { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 6188 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6189 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6190 | // TODO: Same as for ArrayGet. |
| 6191 | return false; |
| 6192 | } |
| 6193 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6194 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6195 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6196 | } |
| 6197 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6198 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6199 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6200 | } |
| 6201 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6202 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6203 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6204 | } |
| 6205 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6206 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6207 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 6208 | bool StaticTypeOfArrayIsObjectArray() const { |
| 6209 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 6210 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6211 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6212 | HInstruction* GetArray() const { return InputAt(0); } |
| 6213 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6214 | HInstruction* GetValue() const { return InputAt(2); } |
| 6215 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6216 | DataType::Type GetComponentType() const { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6217 | return GetComponentType(GetValue()->GetType(), GetRawExpectedComponentType()); |
| 6218 | } |
| 6219 | |
| 6220 | static DataType::Type GetComponentType(DataType::Type value_type, |
| 6221 | DataType::Type expected_component_type) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6222 | // The Dex format does not type floating point index operations. Since the |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6223 | // `expected_component_type` comes from SSA building and can therefore not |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6224 | // be correct, we also check what is the value type. If it is a floating |
| 6225 | // point type, we must use that type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6226 | return ((value_type == DataType::Type::kFloat32) || (value_type == DataType::Type::kFloat64)) |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6227 | ? value_type |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6228 | : expected_component_type; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6229 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6230 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6231 | DataType::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6232 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6233 | } |
| 6234 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6235 | static SideEffects ComputeSideEffects(DataType::Type type) { |
| 6236 | return SideEffects::ArrayWriteOfType(type).Union(SideEffectsForArchRuntimeCalls(type)); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 6237 | } |
| 6238 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6239 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type value_type) { |
| 6240 | return (value_type == DataType::Type::kReference) ? SideEffects::CanTriggerGC() |
| 6241 | : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6242 | } |
| 6243 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6244 | DECLARE_INSTRUCTION(ArraySet); |
| 6245 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6246 | protected: |
| 6247 | DEFAULT_COPY_CONSTRUCTOR(ArraySet); |
| 6248 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6249 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6250 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 6251 | static constexpr size_t kFieldExpectedComponentTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6252 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6253 | static constexpr size_t kFlagNeedsTypeCheck = |
| 6254 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 6255 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6256 | // Cached information for the reference_type_info_ so that codegen |
| 6257 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6258 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 6259 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 6260 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 6261 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6262 | using ExpectedComponentTypeField = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6263 | BitField<DataType::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6264 | }; |
| 6265 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6266 | class HArrayLength final : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6267 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6268 | 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] | 6269 | : HExpression(kArrayLength, DataType::Type::kInt32, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6270 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6271 | // Note that arrays do not change length, so the instruction does not |
| 6272 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6273 | SetRawInputAt(0, array); |
| 6274 | } |
| 6275 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6276 | bool IsClonable() const override { return true; } |
| 6277 | bool CanBeMoved() const override { return true; } |
| 6278 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6279 | return true; |
| 6280 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6281 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 6282 | return obj == InputAt(0); |
| 6283 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6284 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6285 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 6286 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6287 | DECLARE_INSTRUCTION(ArrayLength); |
| 6288 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6289 | protected: |
| 6290 | DEFAULT_COPY_CONSTRUCTOR(ArrayLength); |
| 6291 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6292 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6293 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 6294 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 6295 | // determine whether a particular HArrayLength is actually a String.length() by |
| 6296 | // looking at the type of the input but that requires holding the mutator lock, so |
| 6297 | // 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] | 6298 | static constexpr size_t kFlagIsStringLength = kNumberOfGenericPackedBits; |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6299 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 6300 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6301 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6302 | }; |
| 6303 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6304 | class HBoundsCheck final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6305 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 6306 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6307 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 6308 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6309 | HBoundsCheck(HInstruction* index, |
| 6310 | HInstruction* length, |
| 6311 | uint32_t dex_pc, |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6312 | bool is_string_char_at = false) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6313 | : HExpression(kBoundsCheck, index->GetType(), SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6314 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(index->GetType())); |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6315 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6316 | SetRawInputAt(0, index); |
| 6317 | SetRawInputAt(1, length); |
| 6318 | } |
| 6319 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6320 | bool IsClonable() const override { return true; } |
| 6321 | bool CanBeMoved() const override { return true; } |
| 6322 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6323 | return true; |
| 6324 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6325 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6326 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6327 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6328 | bool CanThrow() const override { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 6329 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 6330 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6331 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6332 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6333 | |
| 6334 | DECLARE_INSTRUCTION(BoundsCheck); |
| 6335 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6336 | protected: |
| 6337 | DEFAULT_COPY_CONSTRUCTOR(BoundsCheck); |
| 6338 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6339 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6340 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | f02046e | 2018-10-02 15:31:32 +0100 | [diff] [blame] | 6341 | static constexpr size_t kNumberOfBoundsCheckPackedBits = kFlagIsStringCharAt + 1; |
| 6342 | static_assert(kNumberOfBoundsCheckPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6343 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6344 | }; |
| 6345 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6346 | class HSuspendCheck final : public HExpression<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6347 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 6348 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6349 | : HExpression(kSuspendCheck, SideEffects::CanTriggerGC(), dex_pc), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6350 | slow_path_(nullptr) { |
| 6351 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6352 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6353 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6354 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6355 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6356 | return true; |
| 6357 | } |
| 6358 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6359 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 6360 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6361 | |
| 6362 | DECLARE_INSTRUCTION(SuspendCheck); |
| 6363 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6364 | protected: |
| 6365 | DEFAULT_COPY_CONSTRUCTOR(SuspendCheck); |
| 6366 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6367 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6368 | // Only used for code generation, in order to share the same slow path between back edges |
| 6369 | // of a same loop. |
| 6370 | SlowPathCode* slow_path_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6371 | }; |
| 6372 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6373 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 6374 | // 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] | 6375 | class HNativeDebugInfo : public HExpression<0> { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6376 | public: |
| 6377 | explicit HNativeDebugInfo(uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6378 | : HExpression<0>(kNativeDebugInfo, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6379 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6380 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6381 | bool NeedsEnvironment() const override { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6382 | return true; |
| 6383 | } |
| 6384 | |
| 6385 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 6386 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6387 | protected: |
| 6388 | DEFAULT_COPY_CONSTRUCTOR(NativeDebugInfo); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6389 | }; |
| 6390 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6391 | /** |
| 6392 | * Instruction to load a Class object. |
| 6393 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6394 | class HLoadClass final : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6395 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6396 | // Determines how to load the Class. |
| 6397 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6398 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 6399 | kInvalid = -1, |
| 6400 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6401 | // Use the Class* from the method's own ArtMethod*. |
| 6402 | kReferrersClass, |
| 6403 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6404 | // 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] | 6405 | // Used for boot image classes referenced by boot image code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6406 | kBootImageLinkTimePcRelative, |
| 6407 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6408 | // 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] | 6409 | // Used for boot image classes referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6410 | kBootImageRelRo, |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6411 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6412 | // 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] | 6413 | // 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] | 6414 | kBssEntry, |
| 6415 | |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6416 | // Load from an entry for public class in the .bss section using a PC-relative load. |
| 6417 | // Used for classes that were unresolved during AOT-compilation outside the literal |
| 6418 | // package of the compiling class. Such classes are accessible only if they are public |
| 6419 | // and the .bss entry shall therefore be filled only if the resolved class is public. |
| 6420 | kBssEntryPublic, |
| 6421 | |
| 6422 | // Load from an entry for package class in the .bss section using a PC-relative load. |
| 6423 | // Used for classes that were unresolved during AOT-compilation but within the literal |
| 6424 | // package of the compiling class. Such classes are accessible if they are public or |
| 6425 | // in the same package which, given the literal package match, requires only matching |
| 6426 | // defining class loader and the .bss entry shall therefore be filled only if at least |
| 6427 | // one of those conditions holds. Note that all code in an oat file belongs to classes |
| 6428 | // with the same defining class loader. |
| 6429 | kBssEntryPackage, |
| 6430 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6431 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 6432 | // Used for boot image classes referenced by apps in JIT-compiled code. |
| 6433 | kJitBootImageAddress, |
| 6434 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6435 | // Load from the root table associated with the JIT compiled method. |
| 6436 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6437 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6438 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6439 | // the codegen is unable to use another appropriate kind. |
| 6440 | kRuntimeCall, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6441 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6442 | kLast = kRuntimeCall |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6443 | }; |
| 6444 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6445 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6446 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6447 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6448 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6449 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6450 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6451 | bool needs_access_check) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6452 | : HInstruction(kLoadClass, |
| 6453 | DataType::Type::kReference, |
| 6454 | SideEffectsForArchRuntimeCalls(), |
| 6455 | dex_pc), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6456 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6457 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6458 | dex_file_(dex_file), |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6459 | klass_(klass) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 6460 | // Referrers class should not need access check. We never inline unverified |
| 6461 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6462 | DCHECK(!is_referrers_class || !needs_access_check); |
| 6463 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6464 | SetPackedField<LoadKindField>( |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6465 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kRuntimeCall); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6466 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6467 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6468 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6469 | SetPackedFlag<kFlagValidLoadedClassRTI>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6470 | } |
| 6471 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6472 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6473 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6474 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6475 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6476 | LoadKind GetLoadKind() const { |
| 6477 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6478 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6479 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6480 | bool HasPcRelativeLoadKind() const { |
| 6481 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6482 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6483 | GetLoadKind() == LoadKind::kBssEntry || |
| 6484 | GetLoadKind() == LoadKind::kBssEntryPublic || |
| 6485 | GetLoadKind() == LoadKind::kBssEntryPackage; |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6486 | } |
| 6487 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6488 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6489 | |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame] | 6490 | bool InstructionDataEquals(const HInstruction* other) const override; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6491 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6492 | size_t ComputeHashCode() const override { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6493 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6494 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6495 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6496 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6497 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6498 | } |
| 6499 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 6500 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6501 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6502 | } |
| 6503 | |
| 6504 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6505 | return NeedsAccessCheck() || |
| 6506 | MustGenerateClinitCheck() || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6507 | GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6508 | GetLoadKind() == LoadKind::kBssEntry; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6509 | } |
| 6510 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6511 | bool CanThrow() const override { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6512 | return NeedsAccessCheck() || |
| 6513 | MustGenerateClinitCheck() || |
| 6514 | // 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] | 6515 | ((GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6516 | GetLoadKind() == LoadKind::kBssEntry) && |
| 6517 | !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6518 | } |
| 6519 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6520 | ReferenceTypeInfo GetLoadedClassRTI() { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6521 | if (GetPackedFlag<kFlagValidLoadedClassRTI>()) { |
| 6522 | // Note: The is_exact flag from the return value should not be used. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6523 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact= */ true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6524 | } else { |
| 6525 | return ReferenceTypeInfo::CreateInvalid(); |
| 6526 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6527 | } |
| 6528 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6529 | // Loaded class RTI is marked as valid by RTP if the klass_ is admissible. |
| 6530 | void SetValidLoadedClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 6531 | DCHECK(klass_ != nullptr); |
| 6532 | SetPackedFlag<kFlagValidLoadedClassRTI>(true); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6533 | } |
| 6534 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6535 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6536 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6537 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6538 | bool NeedsDexCacheOfDeclaringClass() const override { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6539 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6540 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 6541 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6542 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6543 | return SideEffects::CanTriggerGC(); |
| 6544 | } |
| 6545 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6546 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6547 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6548 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6549 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6550 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6551 | bool MustResolveTypeOnSlowPath() const { |
| 6552 | // Check that this instruction has a slow path. |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6553 | LoadKind load_kind = GetLoadKind(); |
| 6554 | DCHECK(load_kind != LoadKind::kRuntimeCall); // kRuntimeCall calls on main path. |
| 6555 | bool must_resolve_type_on_slow_path = |
| 6556 | load_kind == LoadKind::kBssEntry || |
| 6557 | load_kind == LoadKind::kBssEntryPublic || |
| 6558 | load_kind == LoadKind::kBssEntryPackage; |
| 6559 | DCHECK(must_resolve_type_on_slow_path || MustGenerateClinitCheck()); |
| 6560 | return must_resolve_type_on_slow_path; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6561 | } |
| 6562 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6563 | void MarkInBootImage() { |
| 6564 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 6565 | } |
| 6566 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6567 | void AddSpecialInput(HInstruction* special_input); |
| 6568 | |
| 6569 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6570 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6571 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6572 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6573 | } |
| 6574 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6575 | Handle<mirror::Class> GetClass() const { |
| 6576 | return klass_; |
| 6577 | } |
| 6578 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6579 | DECLARE_INSTRUCTION(LoadClass); |
| 6580 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6581 | protected: |
| 6582 | DEFAULT_COPY_CONSTRUCTOR(LoadClass); |
| 6583 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6584 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6585 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6586 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6587 | // Whether this instruction must generate the initialization check. |
| 6588 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6589 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6590 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 6591 | static constexpr size_t kFieldLoadKindSize = |
| 6592 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6593 | static constexpr size_t kFlagValidLoadedClassRTI = kFieldLoadKind + kFieldLoadKindSize; |
| 6594 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagValidLoadedClassRTI + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6595 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6596 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 6597 | |
| 6598 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6599 | return load_kind == LoadKind::kReferrersClass || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6600 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6601 | load_kind == LoadKind::kBssEntry || |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6602 | load_kind == LoadKind::kBssEntryPublic || |
| 6603 | load_kind == LoadKind::kBssEntryPackage || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6604 | load_kind == LoadKind::kRuntimeCall; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6605 | } |
| 6606 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6607 | void SetLoadKindInternal(LoadKind load_kind); |
| 6608 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6609 | // The special input is the HCurrentMethod for kRuntimeCall or kReferrersClass. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6610 | // For other load kinds it's empty or possibly some architecture-specific instruction |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6611 | // for PC-relative loads, i.e. kBssEntry* or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6612 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6613 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6614 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 6615 | // - The compiling method's dex file if the class is defined there too. |
| 6616 | // - The compiling method's dex file if the class is referenced there. |
| 6617 | // - The dex file where the class is defined. When the load kind can only be |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6618 | // kBssEntry* or kRuntimeCall, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6619 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6620 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6621 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6622 | Handle<mirror::Class> klass_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6623 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6624 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 6625 | |
| 6626 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6627 | inline void HLoadClass::SetLoadKind(LoadKind load_kind) { |
| 6628 | // The load kind should be determined before inserting the instruction to the graph. |
| 6629 | DCHECK(GetBlock() == nullptr); |
| 6630 | DCHECK(GetEnvironment() == nullptr); |
| 6631 | SetPackedField<LoadKindField>(load_kind); |
| 6632 | if (load_kind != LoadKind::kRuntimeCall && load_kind != LoadKind::kReferrersClass) { |
| 6633 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6634 | } |
| 6635 | if (!NeedsEnvironment()) { |
| 6636 | SetSideEffects(SideEffects::None()); |
| 6637 | } |
| 6638 | } |
| 6639 | |
| 6640 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6641 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6642 | // The special input is used for PC-relative loads on some architectures, |
| 6643 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6644 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6645 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6646 | GetLoadKind() == LoadKind::kBssEntry || |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6647 | GetLoadKind() == LoadKind::kBssEntryPublic || |
| 6648 | GetLoadKind() == LoadKind::kBssEntryPackage || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6649 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6650 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6651 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 6652 | special_input->AddUseAt(this, 0); |
| 6653 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6654 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6655 | class HLoadString final : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6656 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6657 | // Determines how to load the String. |
| 6658 | enum class LoadKind { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6659 | // 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] | 6660 | // Used for boot image strings referenced by boot image code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6661 | kBootImageLinkTimePcRelative, |
| 6662 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6663 | // 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] | 6664 | // Used for boot image strings referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6665 | kBootImageRelRo, |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6666 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6667 | // 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] | 6668 | // 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] | 6669 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6670 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6671 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 6672 | // Used for boot image strings referenced by apps in JIT-compiled code. |
| 6673 | kJitBootImageAddress, |
| 6674 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6675 | // Load from the root table associated with the JIT compiled method. |
| 6676 | kJitTableAddress, |
| 6677 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6678 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6679 | // the codegen is unable to use another appropriate kind. |
| 6680 | kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6681 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6682 | kLast = kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6683 | }; |
| 6684 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6685 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6686 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6687 | const DexFile& dex_file, |
| 6688 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6689 | : HInstruction(kLoadString, |
| 6690 | DataType::Type::kReference, |
| 6691 | SideEffectsForArchRuntimeCalls(), |
| 6692 | dex_pc), |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6693 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6694 | string_index_(string_index), |
| 6695 | dex_file_(dex_file) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6696 | SetPackedField<LoadKindField>(LoadKind::kRuntimeCall); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6697 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6698 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6699 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6700 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6701 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6702 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6703 | LoadKind GetLoadKind() const { |
| 6704 | return GetPackedField<LoadKindField>(); |
| 6705 | } |
| 6706 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6707 | bool HasPcRelativeLoadKind() const { |
| 6708 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6709 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 6710 | GetLoadKind() == LoadKind::kBssEntry; |
| 6711 | } |
| 6712 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6713 | const DexFile& GetDexFile() const { |
| 6714 | return dex_file_; |
| 6715 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6716 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6717 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6718 | return string_index_; |
| 6719 | } |
| 6720 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6721 | Handle<mirror::String> GetString() const { |
| 6722 | return string_; |
| 6723 | } |
| 6724 | |
| 6725 | void SetString(Handle<mirror::String> str) { |
| 6726 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6727 | } |
| 6728 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6729 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6730 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6731 | bool InstructionDataEquals(const HInstruction* other) const override; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6732 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6733 | size_t ComputeHashCode() const override { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6734 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6735 | // Will call the runtime if we need to load the string through |
| 6736 | // 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] | 6737 | bool NeedsEnvironment() const override { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6738 | LoadKind load_kind = GetLoadKind(); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6739 | if (load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6740 | load_kind == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6741 | load_kind == LoadKind::kJitBootImageAddress || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6742 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6743 | return false; |
| 6744 | } |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6745 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6746 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6747 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6748 | bool NeedsDexCacheOfDeclaringClass() const override { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6749 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6750 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6751 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6752 | bool CanBeNull() const override { return false; } |
| 6753 | bool CanThrow() const override { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6754 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6755 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6756 | return SideEffects::CanTriggerGC(); |
| 6757 | } |
| 6758 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6759 | void AddSpecialInput(HInstruction* special_input); |
| 6760 | |
| 6761 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6762 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6763 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6764 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6765 | } |
| 6766 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6767 | DECLARE_INSTRUCTION(LoadString); |
| 6768 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6769 | protected: |
| 6770 | DEFAULT_COPY_CONSTRUCTOR(LoadString); |
| 6771 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6772 | private: |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6773 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6774 | static constexpr size_t kFieldLoadKindSize = |
| 6775 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 6776 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6777 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6778 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6779 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6780 | void SetLoadKindInternal(LoadKind load_kind); |
| 6781 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6782 | // The special input is the HCurrentMethod for kRuntimeCall. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6783 | // 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] | 6784 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6785 | HUserRecord<HInstruction*> special_input_; |
| 6786 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6787 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6788 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6789 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6790 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6791 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6792 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 6793 | |
| 6794 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6795 | inline void HLoadString::SetLoadKind(LoadKind load_kind) { |
| 6796 | // The load kind should be determined before inserting the instruction to the graph. |
| 6797 | DCHECK(GetBlock() == nullptr); |
| 6798 | DCHECK(GetEnvironment() == nullptr); |
| 6799 | DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); |
| 6800 | SetPackedField<LoadKindField>(load_kind); |
| 6801 | if (load_kind != LoadKind::kRuntimeCall) { |
| 6802 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6803 | } |
| 6804 | if (!NeedsEnvironment()) { |
| 6805 | SetSideEffects(SideEffects::None()); |
| 6806 | } |
| 6807 | } |
| 6808 | |
| 6809 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6810 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6811 | // The special input is used for PC-relative loads on some architectures, |
| 6812 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6813 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6814 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6815 | GetLoadKind() == LoadKind::kBssEntry || |
| 6816 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6817 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 6818 | // so use the GetInputRecords() from the base class to set the input record. |
| 6819 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6820 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6821 | special_input->AddUseAt(this, 0); |
| 6822 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6823 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6824 | class HLoadMethodHandle final : public HInstruction { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6825 | public: |
| 6826 | HLoadMethodHandle(HCurrentMethod* current_method, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 6827 | uint16_t method_handle_idx, |
| 6828 | const DexFile& dex_file, |
| 6829 | uint32_t dex_pc) |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6830 | : HInstruction(kLoadMethodHandle, |
| 6831 | DataType::Type::kReference, |
| 6832 | SideEffectsForArchRuntimeCalls(), |
| 6833 | dex_pc), |
| 6834 | special_input_(HUserRecord<HInstruction*>(current_method)), |
| 6835 | method_handle_idx_(method_handle_idx), |
| 6836 | dex_file_(dex_file) { |
| 6837 | } |
| 6838 | |
| 6839 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6840 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6841 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6842 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6843 | } |
| 6844 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6845 | bool IsClonable() const override { return true; } |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6846 | |
| 6847 | uint16_t GetMethodHandleIndex() const { return method_handle_idx_; } |
| 6848 | |
| 6849 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6850 | |
| 6851 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6852 | return SideEffects::CanTriggerGC(); |
| 6853 | } |
| 6854 | |
| 6855 | DECLARE_INSTRUCTION(LoadMethodHandle); |
| 6856 | |
| 6857 | protected: |
| 6858 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodHandle); |
| 6859 | |
| 6860 | private: |
| 6861 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6862 | HUserRecord<HInstruction*> special_input_; |
| 6863 | |
| 6864 | const uint16_t method_handle_idx_; |
| 6865 | const DexFile& dex_file_; |
| 6866 | }; |
| 6867 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6868 | class HLoadMethodType final : public HInstruction { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6869 | public: |
| 6870 | HLoadMethodType(HCurrentMethod* current_method, |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6871 | dex::ProtoIndex proto_index, |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6872 | const DexFile& dex_file, |
| 6873 | uint32_t dex_pc) |
| 6874 | : HInstruction(kLoadMethodType, |
| 6875 | DataType::Type::kReference, |
| 6876 | SideEffectsForArchRuntimeCalls(), |
| 6877 | dex_pc), |
| 6878 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6879 | proto_index_(proto_index), |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6880 | dex_file_(dex_file) { |
| 6881 | } |
| 6882 | |
| 6883 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6884 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6885 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6886 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6887 | } |
| 6888 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6889 | bool IsClonable() const override { return true; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6890 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6891 | dex::ProtoIndex GetProtoIndex() const { return proto_index_; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6892 | |
| 6893 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6894 | |
| 6895 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6896 | return SideEffects::CanTriggerGC(); |
| 6897 | } |
| 6898 | |
| 6899 | DECLARE_INSTRUCTION(LoadMethodType); |
| 6900 | |
| 6901 | protected: |
| 6902 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodType); |
| 6903 | |
| 6904 | private: |
| 6905 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6906 | HUserRecord<HInstruction*> special_input_; |
| 6907 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6908 | const dex::ProtoIndex proto_index_; |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6909 | const DexFile& dex_file_; |
| 6910 | }; |
| 6911 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6912 | /** |
| 6913 | * Performs an initialization check on its Class object input. |
| 6914 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6915 | class HClinitCheck final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6916 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 6917 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 6918 | : HExpression( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6919 | kClinitCheck, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6920 | DataType::Type::kReference, |
Mingyao Yang | 217eb06 | 2017-12-11 15:20:07 -0800 | [diff] [blame] | 6921 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6922 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6923 | SetRawInputAt(0, constant); |
| 6924 | } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 6925 | // TODO: Make ClinitCheck clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6926 | bool CanBeMoved() const override { return true; } |
| 6927 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6928 | return true; |
| 6929 | } |
| 6930 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6931 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6932 | // May call runtime to initialize the class. |
| 6933 | return true; |
| 6934 | } |
| 6935 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6936 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6937 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6938 | HLoadClass* GetLoadClass() const { |
| 6939 | DCHECK(InputAt(0)->IsLoadClass()); |
| 6940 | return InputAt(0)->AsLoadClass(); |
| 6941 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6942 | |
| 6943 | DECLARE_INSTRUCTION(ClinitCheck); |
| 6944 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6945 | |
| 6946 | protected: |
| 6947 | DEFAULT_COPY_CONSTRUCTOR(ClinitCheck); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6948 | }; |
| 6949 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6950 | class HStaticFieldGet final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6951 | public: |
| 6952 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6953 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6954 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6955 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6956 | bool is_volatile, |
| 6957 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6958 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6959 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6960 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6961 | : HExpression(kStaticFieldGet, |
| 6962 | field_type, |
| 6963 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 6964 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6965 | field_info_(field, |
| 6966 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6967 | field_type, |
| 6968 | is_volatile, |
| 6969 | field_idx, |
| 6970 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6971 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6972 | SetRawInputAt(0, cls); |
| 6973 | } |
| 6974 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6975 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6976 | bool IsClonable() const override { return true; } |
| 6977 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6978 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6979 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6980 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6981 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6982 | } |
| 6983 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6984 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6985 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6986 | } |
| 6987 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6988 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6989 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6990 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6991 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6992 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6993 | void SetType(DataType::Type new_type) { |
| 6994 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6995 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6996 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6997 | SetPackedField<TypeField>(new_type); |
| 6998 | } |
| 6999 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7000 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 7001 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7002 | protected: |
| 7003 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldGet); |
| 7004 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7005 | private: |
| 7006 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7007 | }; |
| 7008 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7009 | class HStaticFieldSet final : public HExpression<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7010 | public: |
| 7011 | HStaticFieldSet(HInstruction* cls, |
| 7012 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7013 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7014 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7015 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 7016 | bool is_volatile, |
| 7017 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 7018 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 7019 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 7020 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7021 | : HExpression(kStaticFieldSet, |
| 7022 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 7023 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7024 | field_info_(field, |
| 7025 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 7026 | field_type, |
| 7027 | is_volatile, |
| 7028 | field_idx, |
| 7029 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7030 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7031 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7032 | SetRawInputAt(0, cls); |
| 7033 | SetRawInputAt(1, value); |
| 7034 | } |
| 7035 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7036 | bool IsClonable() const override { return true; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7037 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7038 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7039 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7040 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7041 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 7042 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7043 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 7044 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 7045 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7046 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 7047 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7048 | protected: |
| 7049 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldSet); |
| 7050 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7051 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7052 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 7053 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 7054 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 7055 | "Too many packed fields."); |
| 7056 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7057 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7058 | }; |
| 7059 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 7060 | class HStringBuilderAppend final : public HVariableInputSizeInstruction { |
| 7061 | public: |
| 7062 | HStringBuilderAppend(HIntConstant* format, |
| 7063 | uint32_t number_of_arguments, |
| 7064 | ArenaAllocator* allocator, |
| 7065 | uint32_t dex_pc) |
| 7066 | : HVariableInputSizeInstruction( |
| 7067 | kStringBuilderAppend, |
| 7068 | DataType::Type::kReference, |
| 7069 | // The runtime call may read memory from inputs. It never writes outside |
| 7070 | // of the newly allocated result object (or newly allocated helper objects). |
| 7071 | SideEffects::AllReads().Union(SideEffects::CanTriggerGC()), |
| 7072 | dex_pc, |
| 7073 | allocator, |
| 7074 | number_of_arguments + /* format */ 1u, |
| 7075 | kArenaAllocInvokeInputs) { |
| 7076 | DCHECK_GE(number_of_arguments, 1u); // There must be something to append. |
| 7077 | SetRawInputAt(FormatIndex(), format); |
| 7078 | } |
| 7079 | |
| 7080 | void SetArgumentAt(size_t index, HInstruction* argument) { |
| 7081 | DCHECK_LE(index, GetNumberOfArguments()); |
| 7082 | SetRawInputAt(index, argument); |
| 7083 | } |
| 7084 | |
| 7085 | // Return the number of arguments, excluding the format. |
| 7086 | size_t GetNumberOfArguments() const { |
| 7087 | DCHECK_GE(InputCount(), 1u); |
| 7088 | return InputCount() - 1u; |
| 7089 | } |
| 7090 | |
| 7091 | size_t FormatIndex() const { |
| 7092 | return GetNumberOfArguments(); |
| 7093 | } |
| 7094 | |
| 7095 | HIntConstant* GetFormat() { |
| 7096 | return InputAt(FormatIndex())->AsIntConstant(); |
| 7097 | } |
| 7098 | |
| 7099 | bool NeedsEnvironment() const override { return true; } |
| 7100 | |
| 7101 | bool CanThrow() const override { return true; } |
| 7102 | |
Vladimir Marko | b1fe5e1 | 2020-03-10 14:30:49 +0000 | [diff] [blame] | 7103 | bool CanBeNull() const override { return false; } |
| 7104 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 7105 | DECLARE_INSTRUCTION(StringBuilderAppend); |
| 7106 | |
| 7107 | protected: |
| 7108 | DEFAULT_COPY_CONSTRUCTOR(StringBuilderAppend); |
| 7109 | }; |
| 7110 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7111 | class HUnresolvedInstanceFieldGet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7112 | public: |
| 7113 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7114 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7115 | uint32_t field_index, |
| 7116 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7117 | : HExpression(kUnresolvedInstanceFieldGet, |
| 7118 | field_type, |
| 7119 | SideEffects::AllExceptGCDependency(), |
| 7120 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7121 | field_index_(field_index) { |
| 7122 | SetRawInputAt(0, obj); |
| 7123 | } |
| 7124 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7125 | bool IsClonable() const override { return true; } |
| 7126 | bool NeedsEnvironment() const override { return true; } |
| 7127 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7128 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7129 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7130 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7131 | |
| 7132 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 7133 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7134 | protected: |
| 7135 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldGet); |
| 7136 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7137 | private: |
| 7138 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7139 | }; |
| 7140 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7141 | class HUnresolvedInstanceFieldSet final : public HExpression<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7142 | public: |
| 7143 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 7144 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7145 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7146 | uint32_t field_index, |
| 7147 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7148 | : HExpression(kUnresolvedInstanceFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7149 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7150 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7151 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7152 | SetRawInputAt(0, obj); |
| 7153 | SetRawInputAt(1, value); |
| 7154 | } |
| 7155 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7156 | bool IsClonable() const override { return true; } |
| 7157 | bool NeedsEnvironment() const override { return true; } |
| 7158 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7159 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7160 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7161 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7162 | |
| 7163 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 7164 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7165 | protected: |
| 7166 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldSet); |
| 7167 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7168 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7169 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 7170 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7171 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7172 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 7173 | kFieldFieldType + kFieldFieldTypeSize; |
| 7174 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7175 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7176 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7177 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7178 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7179 | }; |
| 7180 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7181 | class HUnresolvedStaticFieldGet final : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7182 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7183 | HUnresolvedStaticFieldGet(DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7184 | uint32_t field_index, |
| 7185 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7186 | : HExpression(kUnresolvedStaticFieldGet, |
| 7187 | field_type, |
| 7188 | SideEffects::AllExceptGCDependency(), |
| 7189 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7190 | field_index_(field_index) { |
| 7191 | } |
| 7192 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7193 | bool IsClonable() const override { return true; } |
| 7194 | bool NeedsEnvironment() const override { return true; } |
| 7195 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7196 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7197 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7198 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7199 | |
| 7200 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 7201 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7202 | protected: |
| 7203 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldGet); |
| 7204 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7205 | private: |
| 7206 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7207 | }; |
| 7208 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7209 | class HUnresolvedStaticFieldSet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7210 | public: |
| 7211 | HUnresolvedStaticFieldSet(HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7212 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7213 | uint32_t field_index, |
| 7214 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7215 | : HExpression(kUnresolvedStaticFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7216 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7217 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7218 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7219 | SetRawInputAt(0, value); |
| 7220 | } |
| 7221 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7222 | bool IsClonable() const override { return true; } |
| 7223 | bool NeedsEnvironment() const override { return true; } |
| 7224 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7225 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7226 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7227 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7228 | |
| 7229 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 7230 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7231 | protected: |
| 7232 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldSet); |
| 7233 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7234 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7235 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 7236 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7237 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7238 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 7239 | kFieldFieldType + kFieldFieldTypeSize; |
| 7240 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7241 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7242 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7243 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7244 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7245 | }; |
| 7246 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7247 | // Implement the move-exception DEX instruction. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7248 | class HLoadException final : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7249 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7250 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7251 | : HExpression(kLoadException, DataType::Type::kReference, SideEffects::None(), dex_pc) { |
| 7252 | } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7253 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7254 | bool CanBeNull() const override { return false; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 7255 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7256 | DECLARE_INSTRUCTION(LoadException); |
| 7257 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7258 | protected: |
| 7259 | DEFAULT_COPY_CONSTRUCTOR(LoadException); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7260 | }; |
| 7261 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7262 | // Implicit part of move-exception which clears thread-local exception storage. |
| 7263 | // 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] | 7264 | class HClearException final : public HExpression<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7265 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7266 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7267 | : HExpression(kClearException, SideEffects::AllWrites(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7268 | } |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7269 | |
| 7270 | DECLARE_INSTRUCTION(ClearException); |
| 7271 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7272 | protected: |
| 7273 | DEFAULT_COPY_CONSTRUCTOR(ClearException); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7274 | }; |
| 7275 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7276 | class HThrow final : public HExpression<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7277 | public: |
| 7278 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7279 | : HExpression(kThrow, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7280 | SetRawInputAt(0, exception); |
| 7281 | } |
| 7282 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7283 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7284 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7285 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7286 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7287 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7288 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7289 | bool AlwaysThrows() const override { return true; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 7290 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7291 | DECLARE_INSTRUCTION(Throw); |
| 7292 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7293 | protected: |
| 7294 | DEFAULT_COPY_CONSTRUCTOR(Throw); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7295 | }; |
| 7296 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7297 | /** |
| 7298 | * Implementation strategies for the code generator of a HInstanceOf |
| 7299 | * or `HCheckCast`. |
| 7300 | */ |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 7301 | enum class TypeCheckKind { // private marker to avoid generate-operator-out.py from processing. |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7302 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7303 | kExactCheck, // Can do a single class compare. |
| 7304 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 7305 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 7306 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 7307 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7308 | kArrayCheck, // No optimization yet when checking against a generic array. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7309 | kBitstringCheck, // Compare the type check bitstring. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7310 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7311 | }; |
| 7312 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 7313 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 7314 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7315 | // Note: HTypeCheckInstruction is just a helper class, not an abstract instruction with an |
| 7316 | // `IsTypeCheckInstruction()`. (New virtual methods in the HInstruction class have a high cost.) |
| 7317 | class HTypeCheckInstruction : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7318 | public: |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7319 | HTypeCheckInstruction(InstructionKind kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7320 | DataType::Type type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7321 | HInstruction* object, |
| 7322 | HInstruction* target_class_or_null, |
| 7323 | TypeCheckKind check_kind, |
| 7324 | Handle<mirror::Class> klass, |
| 7325 | uint32_t dex_pc, |
| 7326 | ArenaAllocator* allocator, |
| 7327 | HIntConstant* bitstring_path_to_root, |
| 7328 | HIntConstant* bitstring_mask, |
| 7329 | SideEffects side_effects) |
| 7330 | : HVariableInputSizeInstruction( |
| 7331 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7332 | type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7333 | side_effects, |
| 7334 | dex_pc, |
| 7335 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7336 | /* number_of_inputs= */ check_kind == TypeCheckKind::kBitstringCheck ? 4u : 2u, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7337 | kArenaAllocTypeCheckInputs), |
| 7338 | klass_(klass) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7339 | SetPackedField<TypeCheckKindField>(check_kind); |
| 7340 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7341 | SetPackedFlag<kFlagValidTargetClassRTI>(false); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7342 | SetRawInputAt(0, object); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7343 | SetRawInputAt(1, target_class_or_null); |
| 7344 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_path_to_root != nullptr); |
| 7345 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_mask != nullptr); |
| 7346 | if (check_kind == TypeCheckKind::kBitstringCheck) { |
| 7347 | DCHECK(target_class_or_null->IsNullConstant()); |
| 7348 | SetRawInputAt(2, bitstring_path_to_root); |
| 7349 | SetRawInputAt(3, bitstring_mask); |
| 7350 | } else { |
| 7351 | DCHECK(target_class_or_null->IsLoadClass()); |
| 7352 | } |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7353 | } |
| 7354 | |
| 7355 | HLoadClass* GetTargetClass() const { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7356 | DCHECK_NE(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7357 | HInstruction* load_class = InputAt(1); |
| 7358 | DCHECK(load_class->IsLoadClass()); |
| 7359 | return load_class->AsLoadClass(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7360 | } |
| 7361 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7362 | uint32_t GetBitstringPathToRoot() const { |
| 7363 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7364 | HInstruction* path_to_root = InputAt(2); |
| 7365 | DCHECK(path_to_root->IsIntConstant()); |
| 7366 | return static_cast<uint32_t>(path_to_root->AsIntConstant()->GetValue()); |
| 7367 | } |
| 7368 | |
| 7369 | uint32_t GetBitstringMask() const { |
| 7370 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7371 | HInstruction* mask = InputAt(3); |
| 7372 | DCHECK(mask->IsIntConstant()); |
| 7373 | return static_cast<uint32_t>(mask->AsIntConstant()->GetValue()); |
| 7374 | } |
| 7375 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7376 | bool IsClonable() const override { return true; } |
| 7377 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7378 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7379 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7380 | DCHECK(other->IsInstanceOf() || other->IsCheckCast()) << other->DebugName(); |
| 7381 | return GetPackedFields() == down_cast<const HTypeCheckInstruction*>(other)->GetPackedFields(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7382 | } |
| 7383 | |
Andreas Gampe | 3fbd3ad | 2018-03-26 21:14:46 +0000 | [diff] [blame] | 7384 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 7385 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 7386 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 7387 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
| 7388 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7389 | ReferenceTypeInfo GetTargetClassRTI() { |
| 7390 | if (GetPackedFlag<kFlagValidTargetClassRTI>()) { |
| 7391 | // Note: The is_exact flag from the return value should not be used. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7392 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact= */ true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7393 | } else { |
| 7394 | return ReferenceTypeInfo::CreateInvalid(); |
| 7395 | } |
| 7396 | } |
| 7397 | |
| 7398 | // Target class RTI is marked as valid by RTP if the klass_ is admissible. |
| 7399 | void SetValidTargetClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 7400 | DCHECK(klass_ != nullptr); |
| 7401 | SetPackedFlag<kFlagValidTargetClassRTI>(true); |
| 7402 | } |
| 7403 | |
| 7404 | Handle<mirror::Class> GetClass() const { |
| 7405 | return klass_; |
| 7406 | } |
| 7407 | |
| 7408 | protected: |
| 7409 | DEFAULT_COPY_CONSTRUCTOR(TypeCheckInstruction); |
| 7410 | |
| 7411 | private: |
| 7412 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 7413 | static constexpr size_t kFieldTypeCheckKindSize = |
| 7414 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 7415 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 7416 | static constexpr size_t kFlagValidTargetClassRTI = kFlagMustDoNullCheck + 1; |
| 7417 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagValidTargetClassRTI + 1; |
| 7418 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7419 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
| 7420 | |
| 7421 | Handle<mirror::Class> klass_; |
| 7422 | }; |
| 7423 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7424 | class HInstanceOf final : public HTypeCheckInstruction { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7425 | public: |
| 7426 | HInstanceOf(HInstruction* object, |
| 7427 | HInstruction* target_class_or_null, |
| 7428 | TypeCheckKind check_kind, |
| 7429 | Handle<mirror::Class> klass, |
| 7430 | uint32_t dex_pc, |
| 7431 | ArenaAllocator* allocator, |
| 7432 | HIntConstant* bitstring_path_to_root, |
| 7433 | HIntConstant* bitstring_mask) |
| 7434 | : HTypeCheckInstruction(kInstanceOf, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7435 | DataType::Type::kBool, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7436 | object, |
| 7437 | target_class_or_null, |
| 7438 | check_kind, |
| 7439 | klass, |
| 7440 | dex_pc, |
| 7441 | allocator, |
| 7442 | bitstring_path_to_root, |
| 7443 | bitstring_mask, |
| 7444 | SideEffectsForArchRuntimeCalls(check_kind)) {} |
| 7445 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7446 | bool IsClonable() const override { return true; } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 7447 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7448 | bool NeedsEnvironment() const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7449 | return CanCallRuntime(GetTypeCheckKind()); |
| 7450 | } |
| 7451 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7452 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
Vladimir Marko | 54f4fbd | 2020-02-12 10:52:22 +0000 | [diff] [blame] | 7453 | // TODO: Re-evaluate now that mips codegen has been removed. |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7454 | return check_kind != TypeCheckKind::kExactCheck; |
| 7455 | } |
| 7456 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7457 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7458 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7459 | } |
| 7460 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7461 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7462 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7463 | protected: |
| 7464 | DEFAULT_COPY_CONSTRUCTOR(InstanceOf); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7465 | }; |
| 7466 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7467 | class HBoundType final : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7468 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 7469 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7470 | : HExpression(kBoundType, DataType::Type::kReference, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7471 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 7472 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 7473 | SetPackedFlag<kFlagCanBeNull>(true); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7474 | DCHECK_EQ(input->GetType(), DataType::Type::kReference); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7475 | SetRawInputAt(0, input); |
| 7476 | } |
| 7477 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7478 | bool InstructionDataEquals(const HInstruction* other) const override; |
| 7479 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7480 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7481 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7482 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7483 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7484 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7485 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7486 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7487 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 7488 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7489 | } |
| 7490 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7491 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7492 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7493 | DECLARE_INSTRUCTION(BoundType); |
| 7494 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7495 | protected: |
| 7496 | DEFAULT_COPY_CONSTRUCTOR(BoundType); |
| 7497 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7498 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7499 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 7500 | // is false then CanBeNull() cannot be true). |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7501 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7502 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 7503 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 7504 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7505 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7506 | // 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] | 7507 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 7508 | // It is used to bound the type in cases like: |
| 7509 | // if (x instanceof ClassX) { |
| 7510 | // // uper_bound_ will be ClassX |
| 7511 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7512 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7513 | }; |
| 7514 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7515 | class HCheckCast final : public HTypeCheckInstruction { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7516 | public: |
| 7517 | HCheckCast(HInstruction* object, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7518 | HInstruction* target_class_or_null, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7519 | TypeCheckKind check_kind, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7520 | Handle<mirror::Class> klass, |
| 7521 | uint32_t dex_pc, |
| 7522 | ArenaAllocator* allocator, |
| 7523 | HIntConstant* bitstring_path_to_root, |
| 7524 | HIntConstant* bitstring_mask) |
| 7525 | : HTypeCheckInstruction(kCheckCast, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7526 | DataType::Type::kVoid, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7527 | object, |
| 7528 | target_class_or_null, |
| 7529 | check_kind, |
| 7530 | klass, |
| 7531 | dex_pc, |
| 7532 | allocator, |
| 7533 | bitstring_path_to_root, |
| 7534 | bitstring_mask, |
| 7535 | SideEffects::CanTriggerGC()) {} |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7536 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7537 | bool IsClonable() const override { return true; } |
| 7538 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7539 | // Instruction may throw a CheckCastError. |
| 7540 | return true; |
| 7541 | } |
| 7542 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7543 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7544 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7545 | DECLARE_INSTRUCTION(CheckCast); |
| 7546 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7547 | protected: |
| 7548 | DEFAULT_COPY_CONSTRUCTOR(CheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7549 | }; |
| 7550 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 7551 | /** |
| 7552 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 7553 | * @details We define the combined barrier types that are actually required |
| 7554 | * by the Java Memory Model, rather than using exactly the terminology from |
| 7555 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 7556 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 7557 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 7558 | * The current recipe is as follows: |
| 7559 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 7560 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 7561 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 7562 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 7563 | * class has final fields. |
| 7564 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 7565 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 7566 | */ |
| 7567 | enum MemBarrierKind { |
| 7568 | kAnyStore, |
| 7569 | kLoadAny, |
| 7570 | kStoreStore, |
| 7571 | kAnyAny, |
| 7572 | kNTStoreStore, |
| 7573 | kLastBarrierKind = kNTStoreStore |
| 7574 | }; |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 7575 | std::ostream& operator<<(std::ostream& os, MemBarrierKind kind); |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 7576 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7577 | class HMemoryBarrier final : public HExpression<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7578 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7579 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7580 | : HExpression(kMemoryBarrier, |
| 7581 | SideEffects::AllWritesAndReads(), // Assume write/read on all fields/arrays. |
| 7582 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7583 | SetPackedField<BarrierKindField>(barrier_kind); |
| 7584 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7585 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7586 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7587 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7588 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7589 | |
| 7590 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 7591 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7592 | protected: |
| 7593 | DEFAULT_COPY_CONSTRUCTOR(MemoryBarrier); |
| 7594 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7595 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7596 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 7597 | static constexpr size_t kFieldBarrierKindSize = |
| 7598 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 7599 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 7600 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 7601 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 7602 | "Too many packed fields."); |
| 7603 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7604 | }; |
| 7605 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7606 | // A constructor fence orders all prior stores to fields that could be accessed via a final field of |
| 7607 | // the specified object(s), with respect to any subsequent store that might "publish" |
| 7608 | // (i.e. make visible) the specified object to another thread. |
| 7609 | // |
| 7610 | // JLS 17.5.1 "Semantics of final fields" states that a freeze action happens |
| 7611 | // for all final fields (that were set) at the end of the invoked constructor. |
| 7612 | // |
| 7613 | // The constructor fence models the freeze actions for the final fields of an object |
| 7614 | // being constructed (semantically at the end of the constructor). Constructor fences |
| 7615 | // have a per-object affinity; two separate objects being constructed get two separate |
| 7616 | // constructor fences. |
| 7617 | // |
| 7618 | // (Note: that if calling a super-constructor or forwarding to another constructor, |
| 7619 | // the freezes would happen at the end of *that* constructor being invoked). |
| 7620 | // |
| 7621 | // The memory model guarantees that when the object being constructed is "published" after |
| 7622 | // constructor completion (i.e. escapes the current thread via a store), then any final field |
| 7623 | // writes must be observable on other threads (once they observe that publication). |
| 7624 | // |
| 7625 | // Further, anything written before the freeze, and read by dereferencing through the final field, |
| 7626 | // must also be visible (so final object field could itself have an object with non-final fields; |
| 7627 | // yet the freeze must also extend to them). |
| 7628 | // |
| 7629 | // Constructor example: |
| 7630 | // |
| 7631 | // class HasFinal { |
| 7632 | // final int field; Optimizing IR for <init>()V: |
| 7633 | // HasFinal() { |
| 7634 | // field = 123; HInstanceFieldSet(this, HasFinal.field, 123) |
| 7635 | // // freeze(this.field); HConstructorFence(this) |
| 7636 | // } HReturn |
| 7637 | // } |
| 7638 | // |
| 7639 | // HConstructorFence can serve double duty as a fence for new-instance/new-array allocations of |
| 7640 | // already-initialized classes; in that case the allocation must act as a "default-initializer" |
| 7641 | // of the object which effectively writes the class pointer "final field". |
| 7642 | // |
| 7643 | // For example, we can model default-initialiation as roughly the equivalent of the following: |
| 7644 | // |
| 7645 | // class Object { |
| 7646 | // private final Class header; |
| 7647 | // } |
| 7648 | // |
| 7649 | // Java code: Optimizing IR: |
| 7650 | // |
| 7651 | // T new_instance<T>() { |
| 7652 | // Object obj = allocate_memory(T.class.size); obj = HInvoke(art_quick_alloc_object, T) |
| 7653 | // obj.header = T.class; // header write is done by above call. |
| 7654 | // // freeze(obj.header) HConstructorFence(obj) |
| 7655 | // return (T)obj; |
| 7656 | // } |
| 7657 | // |
| 7658 | // See also: |
Vladimir Marko | c1c3452 | 2018-10-31 13:56:49 +0000 | [diff] [blame] | 7659 | // * DexCompilationUnit::RequiresConstructorBarrier |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7660 | // * QuasiAtomic::ThreadFenceForConstructor |
| 7661 | // |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7662 | class HConstructorFence final : public HVariableInputSizeInstruction { |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7663 | // A fence has variable inputs because the inputs can be removed |
| 7664 | // after prepare_for_register_allocation phase. |
| 7665 | // (TODO: In the future a fence could freeze multiple objects |
| 7666 | // after merging two fences together.) |
| 7667 | public: |
| 7668 | // `fence_object` is the reference that needs to be protected for correct publication. |
| 7669 | // |
| 7670 | // It makes sense in the following situations: |
| 7671 | // * <init> constructors, it's the "this" parameter (i.e. HParameterValue, s.t. IsThis() == true). |
| 7672 | // * new-instance-like instructions, it's the return value (i.e. HNewInstance). |
| 7673 | // |
| 7674 | // After construction the `fence_object` becomes the 0th input. |
| 7675 | // This is not an input in a real sense, but just a convenient place to stash the information |
| 7676 | // about the associated object. |
| 7677 | HConstructorFence(HInstruction* fence_object, |
| 7678 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7679 | ArenaAllocator* allocator) |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7680 | // We strongly suspect there is not a more accurate way to describe the fine-grained reordering |
| 7681 | // constraints described in the class header. We claim that these SideEffects constraints |
| 7682 | // enforce a superset of the real constraints. |
| 7683 | // |
| 7684 | // The ordering described above is conservatively modeled with SideEffects as follows: |
| 7685 | // |
| 7686 | // * To prevent reordering of the publication stores: |
| 7687 | // ----> "Reads of objects" is the initial SideEffect. |
| 7688 | // * For every primitive final field store in the constructor: |
| 7689 | // ----> Union that field's type as a read (e.g. "Read of T") into the SideEffect. |
| 7690 | // * If there are any stores to reference final fields in the constructor: |
| 7691 | // ----> Use a more conservative "AllReads" SideEffect because any stores to any references |
| 7692 | // that are reachable from `fence_object` also need to be prevented for reordering |
| 7693 | // (and we do not want to do alias analysis to figure out what those stores are). |
| 7694 | // |
| 7695 | // In the implementation, this initially starts out as an "all reads" side effect; this is an |
| 7696 | // even more conservative approach than the one described above, and prevents all of the |
| 7697 | // above reordering without analyzing any of the instructions in the constructor. |
| 7698 | // |
| 7699 | // If in a later phase we discover that there are no writes to reference final fields, |
| 7700 | // 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] | 7701 | : HVariableInputSizeInstruction(kConstructorFence, |
| 7702 | SideEffects::AllReads(), |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7703 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7704 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7705 | /* number_of_inputs= */ 1, |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7706 | kArenaAllocConstructorFenceInputs) { |
| 7707 | DCHECK(fence_object != nullptr); |
| 7708 | SetRawInputAt(0, fence_object); |
| 7709 | } |
| 7710 | |
| 7711 | // The object associated with this constructor fence. |
| 7712 | // |
| 7713 | // (Note: This will be null after the prepare_for_register_allocation phase, |
| 7714 | // as all constructor fence inputs are removed there). |
| 7715 | HInstruction* GetFenceObject() const { |
| 7716 | return InputAt(0); |
| 7717 | } |
| 7718 | |
| 7719 | // Find all the HConstructorFence uses (`fence_use`) for `this` and: |
| 7720 | // - Delete `fence_use` from `this`'s use list. |
| 7721 | // - Delete `this` from `fence_use`'s inputs list. |
| 7722 | // - If the `fence_use` is dead, remove it from the graph. |
| 7723 | // |
| 7724 | // A fence is considered dead once it no longer has any uses |
| 7725 | // and all of the inputs are dead. |
| 7726 | // |
| 7727 | // This must *not* be called during/after prepare_for_register_allocation, |
| 7728 | // because that removes all the inputs to the fences but the fence is actually |
| 7729 | // still considered live. |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7730 | // |
| 7731 | // Returns how many HConstructorFence instructions were removed from graph. |
| 7732 | static size_t RemoveConstructorFences(HInstruction* instruction); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7733 | |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7734 | // Combine all inputs of `this` and `other` instruction and remove |
| 7735 | // `other` from the graph. |
| 7736 | // |
| 7737 | // Inputs are unique after the merge. |
| 7738 | // |
| 7739 | // Requirement: `this` must not be the same as `other. |
| 7740 | void Merge(HConstructorFence* other); |
| 7741 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7742 | // Check if this constructor fence is protecting |
| 7743 | // an HNewInstance or HNewArray that is also the immediate |
| 7744 | // predecessor of `this`. |
| 7745 | // |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7746 | // If `ignore_inputs` is true, then the immediate predecessor doesn't need |
| 7747 | // to be one of the inputs of `this`. |
| 7748 | // |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7749 | // Returns the associated HNewArray or HNewInstance, |
| 7750 | // or null otherwise. |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7751 | HInstruction* GetAssociatedAllocation(bool ignore_inputs = false); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7752 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7753 | DECLARE_INSTRUCTION(ConstructorFence); |
| 7754 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7755 | protected: |
| 7756 | DEFAULT_COPY_CONSTRUCTOR(ConstructorFence); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7757 | }; |
| 7758 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7759 | class HMonitorOperation final : public HExpression<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7760 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7761 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7762 | kEnter, |
| 7763 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7764 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7765 | }; |
| 7766 | |
| 7767 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7768 | : HExpression(kMonitorOperation, |
| 7769 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 7770 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7771 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7772 | SetRawInputAt(0, object); |
| 7773 | } |
| 7774 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7775 | // Instruction may go into runtime, so we need an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7776 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 7777 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7778 | bool CanThrow() const override { |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 7779 | // Verifier guarantees that monitor-exit cannot throw. |
| 7780 | // This is important because it allows the HGraphBuilder to remove |
| 7781 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 7782 | return IsEnter(); |
| 7783 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7784 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7785 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 7786 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7787 | |
| 7788 | DECLARE_INSTRUCTION(MonitorOperation); |
| 7789 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7790 | protected: |
| 7791 | DEFAULT_COPY_CONSTRUCTOR(MonitorOperation); |
| 7792 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7793 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7794 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 7795 | static constexpr size_t kFieldOperationKindSize = |
| 7796 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 7797 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 7798 | kFieldOperationKind + kFieldOperationKindSize; |
| 7799 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7800 | "Too many packed fields."); |
| 7801 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7802 | }; |
| 7803 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7804 | class HSelect final : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7805 | public: |
| 7806 | HSelect(HInstruction* condition, |
| 7807 | HInstruction* true_value, |
| 7808 | HInstruction* false_value, |
| 7809 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7810 | : HExpression(kSelect, HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7811 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 7812 | |
| 7813 | // First input must be `true_value` or `false_value` to allow codegens to |
| 7814 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 7815 | // that architectures which implement HSelect as a conditional move also |
| 7816 | // will not need to invert the condition. |
| 7817 | SetRawInputAt(0, false_value); |
| 7818 | SetRawInputAt(1, true_value); |
| 7819 | SetRawInputAt(2, condition); |
| 7820 | } |
| 7821 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7822 | bool IsClonable() const override { return true; } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7823 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 7824 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 7825 | HInstruction* GetCondition() const { return InputAt(2); } |
| 7826 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7827 | bool CanBeMoved() const override { return true; } |
| 7828 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7829 | return true; |
| 7830 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7831 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7832 | bool CanBeNull() const override { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7833 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 7834 | } |
| 7835 | |
| 7836 | DECLARE_INSTRUCTION(Select); |
| 7837 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7838 | protected: |
| 7839 | DEFAULT_COPY_CONSTRUCTOR(Select); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7840 | }; |
| 7841 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 7842 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7843 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7844 | MoveOperands(Location source, |
| 7845 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7846 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7847 | HInstruction* instruction) |
| 7848 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7849 | |
| 7850 | Location GetSource() const { return source_; } |
| 7851 | Location GetDestination() const { return destination_; } |
| 7852 | |
| 7853 | void SetSource(Location value) { source_ = value; } |
| 7854 | void SetDestination(Location value) { destination_ = value; } |
| 7855 | |
| 7856 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 7857 | // destination (but not the source). |
| 7858 | Location MarkPending() { |
| 7859 | DCHECK(!IsPending()); |
| 7860 | Location dest = destination_; |
| 7861 | destination_ = Location::NoLocation(); |
| 7862 | return dest; |
| 7863 | } |
| 7864 | |
| 7865 | void ClearPending(Location dest) { |
| 7866 | DCHECK(IsPending()); |
| 7867 | destination_ = dest; |
| 7868 | } |
| 7869 | |
| 7870 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7871 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 7872 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7873 | } |
| 7874 | |
| 7875 | // True if this blocks a move from the given location. |
| 7876 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 7877 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7878 | } |
| 7879 | |
| 7880 | // A move is redundant if it's been eliminated, if its source and |
| 7881 | // destination are the same, or if its destination is unneeded. |
| 7882 | bool IsRedundant() const { |
| 7883 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 7884 | } |
| 7885 | |
| 7886 | // We clear both operands to indicate move that's been eliminated. |
| 7887 | void Eliminate() { |
| 7888 | source_ = destination_ = Location::NoLocation(); |
| 7889 | } |
| 7890 | |
| 7891 | bool IsEliminated() const { |
| 7892 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 7893 | return source_.IsInvalid(); |
| 7894 | } |
| 7895 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7896 | DataType::Type GetType() const { return type_; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7897 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7898 | bool Is64BitMove() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7899 | return DataType::Is64BitType(type_); |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7900 | } |
| 7901 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7902 | HInstruction* GetInstruction() const { return instruction_; } |
| 7903 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7904 | private: |
| 7905 | Location source_; |
| 7906 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7907 | // The type this move is for. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7908 | DataType::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7909 | // The instruction this move is assocatied with. Null when this move is |
| 7910 | // for moving an input in the expected locations of user (including a phi user). |
| 7911 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 7912 | // in the same parallel move. |
| 7913 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7914 | }; |
| 7915 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7916 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 7917 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7918 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 7919 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7920 | class HParallelMove final : public HExpression<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7921 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7922 | explicit HParallelMove(ArenaAllocator* allocator, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7923 | : HExpression(kParallelMove, SideEffects::None(), dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7924 | moves_(allocator->Adapter(kArenaAllocMoveOperands)) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7925 | moves_.reserve(kDefaultNumberOfMoves); |
| 7926 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7927 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7928 | void AddMove(Location source, |
| 7929 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7930 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7931 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 7932 | DCHECK(source.IsValid()); |
| 7933 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7934 | if (kIsDebugBuild) { |
| 7935 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7936 | for (const MoveOperands& move : moves_) { |
| 7937 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7938 | // Special case the situation where the move is for the spill slot |
| 7939 | // of the instruction. |
| 7940 | if ((GetPrevious() == instruction) |
| 7941 | || ((GetPrevious() == nullptr) |
| 7942 | && instruction->IsPhi() |
| 7943 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7944 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7945 | << "Doing parallel moves for the same instruction."; |
| 7946 | } else { |
| 7947 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 7948 | } |
| 7949 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 7950 | } |
| 7951 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7952 | for (const MoveOperands& move : moves_) { |
| 7953 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7954 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7955 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7956 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7957 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7958 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7959 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7960 | } |
| 7961 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7962 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7963 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7964 | } |
| 7965 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7966 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7967 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 7968 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7969 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7970 | protected: |
| 7971 | DEFAULT_COPY_CONSTRUCTOR(ParallelMove); |
| 7972 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7973 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7974 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7975 | }; |
| 7976 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7977 | // This instruction computes an intermediate address pointing in the 'middle' of an object. The |
| 7978 | // result pointer cannot be handled by GC, so extra care is taken to make sure that this value is |
| 7979 | // never used across anything that can trigger GC. |
| 7980 | // The result of this instruction is not a pointer in the sense of `DataType::Type::kreference`. |
| 7981 | // So we represent it by the type `DataType::Type::kInt`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7982 | class HIntermediateAddress final : public HExpression<2> { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7983 | public: |
| 7984 | HIntermediateAddress(HInstruction* base_address, HInstruction* offset, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7985 | : HExpression(kIntermediateAddress, |
| 7986 | DataType::Type::kInt32, |
| 7987 | SideEffects::DependsOnGC(), |
| 7988 | dex_pc) { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7989 | DCHECK_EQ(DataType::Size(DataType::Type::kInt32), |
| 7990 | DataType::Size(DataType::Type::kReference)) |
| 7991 | << "kPrimInt and kPrimNot have different sizes."; |
| 7992 | SetRawInputAt(0, base_address); |
| 7993 | SetRawInputAt(1, offset); |
| 7994 | } |
| 7995 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7996 | bool IsClonable() const override { return true; } |
| 7997 | bool CanBeMoved() const override { return true; } |
| 7998 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7999 | return true; |
| 8000 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8001 | bool IsActualObject() const override { return false; } |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8002 | |
| 8003 | HInstruction* GetBaseAddress() const { return InputAt(0); } |
| 8004 | HInstruction* GetOffset() const { return InputAt(1); } |
| 8005 | |
| 8006 | DECLARE_INSTRUCTION(IntermediateAddress); |
| 8007 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8008 | protected: |
| 8009 | DEFAULT_COPY_CONSTRUCTOR(IntermediateAddress); |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8010 | }; |
| 8011 | |
| 8012 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8013 | } // namespace art |
| 8014 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 8015 | #include "nodes_vector.h" |
| 8016 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 8017 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 8018 | #include "nodes_shared.h" |
| 8019 | #endif |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 8020 | #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64) |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8021 | #include "nodes_x86.h" |
| 8022 | #endif |
| 8023 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 8024 | namespace art { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8025 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8026 | class OptimizingCompilerStats; |
| 8027 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8028 | class HGraphVisitor : public ValueObject { |
| 8029 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8030 | explicit HGraphVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 8031 | : stats_(stats), |
| 8032 | graph_(graph) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 8033 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8034 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8035 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8036 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 8037 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 8038 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8039 | void VisitInsertionOrder(); |
| 8040 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 8041 | // Visit the graph following dominator tree reverse post-order. |
| 8042 | void VisitReversePostOrder(); |
| 8043 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 8044 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8045 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8046 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8047 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8048 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 8049 | |
| 8050 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 8051 | |
| 8052 | #undef DECLARE_VISIT_INSTRUCTION |
| 8053 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8054 | protected: |
| 8055 | OptimizingCompilerStats* stats_; |
| 8056 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8057 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 8058 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8059 | |
| 8060 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 8061 | }; |
| 8062 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8063 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 8064 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8065 | explicit HGraphDelegateVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 8066 | : HGraphVisitor(graph, stats) {} |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8067 | virtual ~HGraphDelegateVisitor() {} |
| 8068 | |
| 8069 | // Visit functions that delegate to to super class. |
| 8070 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8071 | void Visit##name(H##name* instr) override { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8072 | |
| 8073 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 8074 | |
| 8075 | #undef DECLARE_VISIT_INSTRUCTION |
| 8076 | |
| 8077 | private: |
| 8078 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 8079 | }; |
| 8080 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8081 | // Create a clone of the instruction, insert it into the graph; replace the old one with a new |
| 8082 | // and remove the old instruction. |
| 8083 | HInstruction* ReplaceInstrOrPhiByClone(HInstruction* instr); |
| 8084 | |
| 8085 | // Create a clone for each clonable instructions/phis and replace the original with the clone. |
| 8086 | // |
| 8087 | // Used for testing individual instruction cloner. |
| 8088 | class CloneAndReplaceInstructionVisitor : public HGraphDelegateVisitor { |
| 8089 | public: |
| 8090 | explicit CloneAndReplaceInstructionVisitor(HGraph* graph) |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8091 | : HGraphDelegateVisitor(graph), instr_replaced_by_clones_count_(0) {} |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8092 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8093 | void VisitInstruction(HInstruction* instruction) override { |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8094 | if (instruction->IsClonable()) { |
| 8095 | ReplaceInstrOrPhiByClone(instruction); |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8096 | instr_replaced_by_clones_count_++; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8097 | } |
| 8098 | } |
| 8099 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8100 | size_t GetInstrReplacedByClonesCount() const { return instr_replaced_by_clones_count_; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8101 | |
| 8102 | private: |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8103 | size_t instr_replaced_by_clones_count_; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8104 | |
| 8105 | DISALLOW_COPY_AND_ASSIGN(CloneAndReplaceInstructionVisitor); |
| 8106 | }; |
| 8107 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8108 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 8109 | // of an inner loop. The order in which the blocks are iterated is on their |
| 8110 | // block id. |
| 8111 | class HBlocksInLoopIterator : public ValueObject { |
| 8112 | public: |
| 8113 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 8114 | : blocks_in_loop_(info.GetBlocks()), |
| 8115 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 8116 | index_(0) { |
| 8117 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 8118 | Advance(); |
| 8119 | } |
| 8120 | } |
| 8121 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8122 | bool Done() const { return index_ == blocks_.size(); } |
| 8123 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8124 | void Advance() { |
| 8125 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8126 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8127 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 8128 | break; |
| 8129 | } |
| 8130 | } |
| 8131 | } |
| 8132 | |
| 8133 | private: |
| 8134 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8135 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8136 | size_t index_; |
| 8137 | |
| 8138 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 8139 | }; |
| 8140 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8141 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 8142 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 8143 | // post order. |
| 8144 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 8145 | public: |
| 8146 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 8147 | : blocks_in_loop_(info.GetBlocks()), |
| 8148 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 8149 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8150 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8151 | Advance(); |
| 8152 | } |
| 8153 | } |
| 8154 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8155 | bool Done() const { return index_ == blocks_.size(); } |
| 8156 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8157 | void Advance() { |
| 8158 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8159 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 8160 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8161 | break; |
| 8162 | } |
| 8163 | } |
| 8164 | } |
| 8165 | |
| 8166 | private: |
| 8167 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8168 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8169 | size_t index_; |
| 8170 | |
| 8171 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 8172 | }; |
| 8173 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 8174 | // Returns int64_t value of a properly typed constant. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 8175 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 8176 | if (constant->IsIntConstant()) { |
| 8177 | return constant->AsIntConstant()->GetValue(); |
| 8178 | } else if (constant->IsLongConstant()) { |
| 8179 | return constant->AsLongConstant()->GetValue(); |
| 8180 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 8181 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 8182 | return 0; |
| 8183 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 8184 | } |
| 8185 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 8186 | // Returns true iff instruction is an integral constant (and sets value on success). |
| 8187 | inline bool IsInt64AndGet(HInstruction* instruction, /*out*/ int64_t* value) { |
| 8188 | if (instruction->IsIntConstant()) { |
| 8189 | *value = instruction->AsIntConstant()->GetValue(); |
| 8190 | return true; |
| 8191 | } else if (instruction->IsLongConstant()) { |
| 8192 | *value = instruction->AsLongConstant()->GetValue(); |
| 8193 | return true; |
| 8194 | } else if (instruction->IsNullConstant()) { |
| 8195 | *value = 0; |
| 8196 | return true; |
| 8197 | } |
| 8198 | return false; |
| 8199 | } |
| 8200 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 8201 | // Returns true iff instruction is the given integral constant. |
| 8202 | inline bool IsInt64Value(HInstruction* instruction, int64_t value) { |
| 8203 | int64_t val = 0; |
| 8204 | return IsInt64AndGet(instruction, &val) && val == value; |
| 8205 | } |
| 8206 | |
| 8207 | // Returns true iff instruction is a zero bit pattern. |
| 8208 | inline bool IsZeroBitPattern(HInstruction* instruction) { |
| 8209 | return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern(); |
| 8210 | } |
| 8211 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 8212 | // Implement HInstruction::Is##type() for concrete instructions. |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8213 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8214 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } |
| 8215 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 8216 | #undef INSTRUCTION_TYPE_CHECK |
| 8217 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 8218 | // Implement HInstruction::Is##type() for abstract instructions. |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8219 | #define INSTRUCTION_TYPE_CHECK_RESULT(type, super) \ |
| 8220 | std::is_base_of<BaseType, H##type>::value, |
| 8221 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 8222 | inline bool HInstruction::Is##type() const { \ |
| 8223 | DCHECK_LT(GetKind(), kLastInstructionKind); \ |
| 8224 | using BaseType = H##type; \ |
| 8225 | static constexpr bool results[] = { \ |
| 8226 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK_RESULT) \ |
| 8227 | }; \ |
| 8228 | return results[static_cast<size_t>(GetKind())]; \ |
| 8229 | } |
| 8230 | |
| 8231 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 8232 | #undef INSTRUCTION_TYPE_CHECK |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 8233 | #undef INSTRUCTION_TYPE_CHECK_RESULT |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8234 | |
| 8235 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8236 | inline const H##type* HInstruction::As##type() const { \ |
| 8237 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 8238 | } \ |
| 8239 | inline H##type* HInstruction::As##type() { \ |
| 8240 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 8241 | } |
| 8242 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8243 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 8244 | #undef INSTRUCTION_TYPE_CAST |
| 8245 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8246 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 8247 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 8248 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 8249 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 8250 | size_t number_of_new_blocks, |
| 8251 | size_t after) { |
| 8252 | DCHECK_LT(after, blocks->size()); |
| 8253 | size_t old_size = blocks->size(); |
| 8254 | size_t new_size = old_size + number_of_new_blocks; |
| 8255 | blocks->resize(new_size); |
| 8256 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 8257 | } |
| 8258 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8259 | /* |
| 8260 | * Hunt "under the hood" of array lengths (leading to array references), |
| 8261 | * null checks (also leading to array references), and new arrays |
| 8262 | * (leading to the actual length). This makes it more likely related |
| 8263 | * instructions become actually comparable. |
| 8264 | */ |
| 8265 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 8266 | while (instruction->IsArrayLength() || |
| 8267 | instruction->IsNullCheck() || |
| 8268 | instruction->IsNewArray()) { |
| 8269 | instruction = instruction->IsNewArray() |
| 8270 | ? instruction->AsNewArray()->GetLength() |
| 8271 | : instruction->InputAt(0); |
| 8272 | } |
| 8273 | return instruction; |
| 8274 | } |
| 8275 | |
Artem Serov | b47b978 | 2019-12-04 21:02:09 +0000 | [diff] [blame] | 8276 | inline bool IsAddOrSub(const HInstruction* instruction) { |
| 8277 | return instruction->IsAdd() || instruction->IsSub(); |
| 8278 | } |
| 8279 | |
Artem Serov | 21c7e6f | 2017-07-27 16:04:42 +0100 | [diff] [blame] | 8280 | void RemoveEnvironmentUses(HInstruction* instruction); |
| 8281 | bool HasEnvironmentUsedByOthers(HInstruction* instruction); |
| 8282 | void ResetEnvironmentInputRecords(HInstruction* instruction); |
| 8283 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 8284 | // Detects an instruction that is >= 0. As long as the value is carried by |
| 8285 | // a single instruction, arithmetic wrap-around cannot occur. |
| 8286 | bool IsGEZero(HInstruction* instruction); |
| 8287 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8288 | } // namespace art |
| 8289 | |
| 8290 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |