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 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 24 | #include "art_method.h" |
Alex Light | 86fe9b8 | 2020-11-16 16:54:01 +0000 | [diff] [blame] | 25 | #include "base/arena_allocator.h" |
Mathieu Chartier | e5d80f8 | 2015-10-15 17:47:48 -0700 | [diff] [blame] | 26 | #include "base/arena_bit_vector.h" |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 27 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 28 | #include "base/arena_object.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 29 | #include "base/array_ref.h" |
Vladimir Marko | 3fae129 | 2019-06-07 11:26:25 +0100 | [diff] [blame] | 30 | #include "base/intrusive_forward_list.h" |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 31 | #include "base/iteration_range.h" |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 32 | #include "base/macros.h" |
Andreas Gampe | 7fbc4a5 | 2018-11-28 08:26:47 -0800 | [diff] [blame] | 33 | #include "base/mutex.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 34 | #include "base/quasi_atomic.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 35 | #include "base/stl_util.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 36 | #include "base/transform_array_ref.h" |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 37 | #include "block_namer.h" |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 38 | #include "class_root.h" |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 39 | #include "compilation_kind.h" |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 40 | #include "data_type.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 41 | #include "deoptimization_kind.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 42 | #include "dex/dex_file.h" |
| 43 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 44 | #include "dex/invoke_type.h" |
David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 45 | #include "dex/method_reference.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 46 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 47 | #include "handle.h" |
| 48 | #include "handle_scope.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 49 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 50 | #include "locations.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 51 | #include "mirror/class.h" |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 52 | #include "mirror/method_type.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | #include "offsets.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 54 | |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 55 | namespace art HIDDEN { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 56 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 57 | class ArenaStack; |
Nicolas Geoffray | 22df3e0 | 2022-01-10 09:31:57 +0000 | [diff] [blame] | 58 | class CodeGenerator; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 59 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 60 | class HBasicBlock; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 61 | class HConstructorFence; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 62 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 63 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 64 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 65 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 66 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 67 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 68 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 69 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 70 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 71 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 72 | class HNullConstant; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 73 | class HParameterValue; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 74 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 75 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 76 | class HTryBoundary; |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 77 | class FieldInfo; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 78 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 79 | class LocationSummary; |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 80 | class ProfilingInfo; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 81 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 82 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 83 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 84 | namespace mirror { |
| 85 | class DexCache; |
| 86 | } // namespace mirror |
| 87 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 88 | static const int kDefaultNumberOfBlocks = 8; |
| 89 | static const int kDefaultNumberOfSuccessors = 2; |
| 90 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 91 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 92 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 93 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 94 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 95 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 96 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 97 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 98 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 99 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 100 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 101 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 102 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 103 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 104 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 105 | static constexpr uint32_t kNoDexPc = -1; |
| 106 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 107 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 108 | // For the purposes of the compiler, the dex files must actually be the same object |
| 109 | // if we want to safely treat them as the same. This is especially important for JIT |
| 110 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 111 | // times and provide different class resolution but no two class loaders should ever |
| 112 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 113 | // all sorts of weird failures. |
| 114 | return &lhs == &rhs; |
| 115 | } |
| 116 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 117 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 118 | // All types. |
| 119 | kCondEQ, // == |
| 120 | kCondNE, // != |
| 121 | // Signed integers and floating-point numbers. |
| 122 | kCondLT, // < |
| 123 | kCondLE, // <= |
| 124 | kCondGT, // > |
| 125 | kCondGE, // >= |
| 126 | // Unsigned integers. |
| 127 | kCondB, // < |
| 128 | kCondBE, // <= |
| 129 | kCondA, // > |
| 130 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 131 | // First and last aliases. |
| 132 | kCondFirst = kCondEQ, |
| 133 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 136 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 137 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 138 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 139 | kAnalysisFailThrowCatchLoop, |
| 140 | kAnalysisFailAmbiguousArrayOp, |
Nicolas Geoffray | 0846a8f | 2018-09-12 15:21:07 +0100 | [diff] [blame] | 141 | kAnalysisFailIrreducibleLoopAndStringInit, |
Nicolas Geoffray | 7cfc8f5 | 2019-08-07 10:41:09 +0100 | [diff] [blame] | 142 | kAnalysisFailPhiEquivalentInOsr, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 143 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 144 | }; |
| 145 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 146 | template <typename T> |
| 147 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 148 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 149 | } |
| 150 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 151 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 152 | public: |
| 153 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 154 | |
| 155 | void AddInstruction(HInstruction* instruction); |
| 156 | void RemoveInstruction(HInstruction* instruction); |
| 157 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 158 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 159 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 160 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 161 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 162 | // Return true if this list contains `instruction`. |
| 163 | bool Contains(HInstruction* instruction) const; |
| 164 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 165 | // Return true if `instruction1` is found before `instruction2` in |
| 166 | // this instruction list and false otherwise. Abort if none |
| 167 | // of these instructions is found. |
| 168 | bool FoundBefore(const HInstruction* instruction1, |
| 169 | const HInstruction* instruction2) const; |
| 170 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 171 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 172 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 173 | |
| 174 | // Update the block of all instructions to be `block`. |
| 175 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 176 | |
| 177 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 178 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 179 | void Add(const HInstructionList& instruction_list); |
| 180 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 181 | // Return the number of instructions in the list. This is an expensive operation. |
| 182 | size_t CountSize() const; |
| 183 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 184 | private: |
| 185 | HInstruction* first_instruction_; |
| 186 | HInstruction* last_instruction_; |
| 187 | |
| 188 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 189 | friend class HGraph; |
| 190 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 191 | friend class HInstructionIterator; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 192 | friend class HInstructionIteratorHandleChanges; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 193 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 194 | |
| 195 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 196 | }; |
| 197 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 198 | class ReferenceTypeInfo : ValueObject { |
| 199 | public: |
Vladimir Marko | 4f99071 | 2021-07-14 12:45:13 +0100 | [diff] [blame] | 200 | using TypeHandle = Handle<mirror::Class>; |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 201 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 202 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 203 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 204 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 205 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 206 | } |
| 207 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 208 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 209 | return ReferenceTypeInfo(type_handle, is_exact); |
| 210 | } |
| 211 | |
| 212 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 213 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 214 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 215 | return handle.GetReference() != nullptr; |
| 216 | } |
| 217 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 218 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 219 | return IsValidHandle(type_handle_); |
| 220 | } |
| 221 | |
| 222 | bool IsExact() const { return is_exact_; } |
| 223 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 224 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 225 | DCHECK(IsValid()); |
| 226 | return GetTypeHandle()->IsObjectClass(); |
| 227 | } |
| 228 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 229 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 230 | DCHECK(IsValid()); |
| 231 | return GetTypeHandle()->IsStringClass(); |
| 232 | } |
| 233 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 234 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 235 | DCHECK(IsValid()); |
| 236 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 237 | } |
| 238 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 239 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 240 | DCHECK(IsValid()); |
| 241 | return GetTypeHandle()->IsInterface(); |
| 242 | } |
| 243 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 244 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 245 | DCHECK(IsValid()); |
| 246 | return GetTypeHandle()->IsArrayClass(); |
| 247 | } |
| 248 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 249 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 250 | DCHECK(IsValid()); |
| 251 | return GetTypeHandle()->IsPrimitiveArray(); |
| 252 | } |
| 253 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 254 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 255 | DCHECK(IsValid()); |
| 256 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 257 | } |
| 258 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 259 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 260 | DCHECK(IsValid()); |
| 261 | if (!IsExact()) return false; |
| 262 | if (!IsArrayClass()) return false; |
| 263 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 264 | } |
| 265 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 266 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 267 | DCHECK(IsValid()); |
| 268 | if (!IsExact()) return false; |
| 269 | if (!IsArrayClass()) return false; |
| 270 | if (!rti.IsArrayClass()) return false; |
| 271 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 272 | rti.GetTypeHandle()->GetComponentType()); |
| 273 | } |
| 274 | |
| 275 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 276 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 277 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 278 | DCHECK(IsValid()); |
| 279 | DCHECK(rti.IsValid()); |
| 280 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 281 | } |
| 282 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 283 | // Returns true if the type information provide the same amount of details. |
| 284 | // Note that it does not mean that the instructions have the same actual type |
| 285 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 286 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 287 | if (!IsValid() && !rti.IsValid()) { |
| 288 | // Invalid types are equal. |
| 289 | return true; |
| 290 | } |
| 291 | if (!IsValid() || !rti.IsValid()) { |
| 292 | // One is valid, the other not. |
| 293 | return false; |
| 294 | } |
| 295 | return IsExact() == rti.IsExact() |
| 296 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 297 | } |
| 298 | |
| 299 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 300 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 301 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 302 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 303 | |
| 304 | // The class of the object. |
| 305 | TypeHandle type_handle_; |
| 306 | // Whether or not the type is exact or a superclass of the actual type. |
| 307 | // Whether or not we have any information about this type. |
| 308 | bool is_exact_; |
| 309 | }; |
| 310 | |
| 311 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 312 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 313 | class HandleCache { |
| 314 | public: |
| 315 | explicit HandleCache(VariableSizedHandleScope* handles) : handles_(handles) { } |
| 316 | |
| 317 | VariableSizedHandleScope* GetHandles() { return handles_; } |
| 318 | |
| 319 | template <typename T> |
| 320 | MutableHandle<T> NewHandle(T* object) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 321 | return handles_->NewHandle(object); |
| 322 | } |
| 323 | |
| 324 | template <typename T> |
| 325 | MutableHandle<T> NewHandle(ObjPtr<T> object) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 326 | return handles_->NewHandle(object); |
| 327 | } |
| 328 | |
| 329 | ReferenceTypeInfo::TypeHandle GetObjectClassHandle() { |
| 330 | return GetRootHandle(ClassRoot::kJavaLangObject, &object_class_handle_); |
| 331 | } |
| 332 | |
| 333 | ReferenceTypeInfo::TypeHandle GetClassClassHandle() { |
| 334 | return GetRootHandle(ClassRoot::kJavaLangClass, &class_class_handle_); |
| 335 | } |
| 336 | |
| 337 | ReferenceTypeInfo::TypeHandle GetMethodHandleClassHandle() { |
| 338 | return GetRootHandle(ClassRoot::kJavaLangInvokeMethodHandleImpl, &method_handle_class_handle_); |
| 339 | } |
| 340 | |
| 341 | ReferenceTypeInfo::TypeHandle GetMethodTypeClassHandle() { |
| 342 | return GetRootHandle(ClassRoot::kJavaLangInvokeMethodType, &method_type_class_handle_); |
| 343 | } |
| 344 | |
| 345 | ReferenceTypeInfo::TypeHandle GetStringClassHandle() { |
| 346 | return GetRootHandle(ClassRoot::kJavaLangString, &string_class_handle_); |
| 347 | } |
| 348 | |
| 349 | ReferenceTypeInfo::TypeHandle GetThrowableClassHandle() { |
| 350 | return GetRootHandle(ClassRoot::kJavaLangThrowable, &throwable_class_handle_); |
| 351 | } |
| 352 | |
| 353 | |
| 354 | private: |
| 355 | inline ReferenceTypeInfo::TypeHandle GetRootHandle(ClassRoot class_root, |
| 356 | ReferenceTypeInfo::TypeHandle* cache) { |
| 357 | if (UNLIKELY(!ReferenceTypeInfo::IsValidHandle(*cache))) { |
| 358 | *cache = CreateRootHandle(handles_, class_root); |
| 359 | } |
| 360 | return *cache; |
| 361 | } |
| 362 | |
| 363 | static ReferenceTypeInfo::TypeHandle CreateRootHandle(VariableSizedHandleScope* handles, |
| 364 | ClassRoot class_root); |
| 365 | |
| 366 | VariableSizedHandleScope* handles_; |
| 367 | |
| 368 | ReferenceTypeInfo::TypeHandle object_class_handle_; |
| 369 | ReferenceTypeInfo::TypeHandle class_class_handle_; |
| 370 | ReferenceTypeInfo::TypeHandle method_handle_class_handle_; |
| 371 | ReferenceTypeInfo::TypeHandle method_type_class_handle_; |
| 372 | ReferenceTypeInfo::TypeHandle string_class_handle_; |
| 373 | ReferenceTypeInfo::TypeHandle throwable_class_handle_; |
| 374 | }; |
| 375 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 376 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 377 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 378 | public: |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 379 | HGraph(ArenaAllocator* allocator, |
| 380 | ArenaStack* arena_stack, |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 381 | VariableSizedHandleScope* handles, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 382 | const DexFile& dex_file, |
| 383 | uint32_t method_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 384 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 385 | InvokeType invoke_type = kInvalidInvokeType, |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 386 | bool dead_reference_safe = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 387 | bool debuggable = false, |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 388 | CompilationKind compilation_kind = CompilationKind::kOptimized, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 389 | int start_instruction_id = 0) |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 390 | : allocator_(allocator), |
| 391 | arena_stack_(arena_stack), |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 392 | handle_cache_(handles), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 393 | blocks_(allocator->Adapter(kArenaAllocBlockList)), |
| 394 | reverse_post_order_(allocator->Adapter(kArenaAllocReversePostOrder)), |
| 395 | linear_order_(allocator->Adapter(kArenaAllocLinearOrder)), |
Alex Light | 86fe9b8 | 2020-11-16 16:54:01 +0000 | [diff] [blame] | 396 | reachability_graph_(allocator, 0, 0, true, kArenaAllocReachabilityGraph), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 397 | entry_block_(nullptr), |
| 398 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 399 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 400 | number_of_vregs_(0), |
| 401 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 402 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 403 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 404 | has_try_catch_(false), |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 405 | has_monitor_operations_(false), |
Artem Serov | 0b284aa | 2021-12-14 23:16:21 +0000 | [diff] [blame] | 406 | has_traditional_simd_(false), |
| 407 | has_predicated_simd_(false), |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 408 | has_loops_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 409 | has_irreducible_loops_(false), |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 410 | has_direct_critical_native_call_(false), |
Santiago Aboy Solanes | 78f3d3a | 2022-07-15 14:30:05 +0100 | [diff] [blame] | 411 | has_always_throwing_invokes_(false), |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 412 | dead_reference_safe_(dead_reference_safe), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 413 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 414 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 415 | dex_file_(dex_file), |
| 416 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 417 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 418 | in_ssa_form_(false), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 419 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 420 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 421 | cached_null_constant_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 422 | cached_int_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 423 | cached_float_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 424 | cached_long_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 425 | cached_double_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 426 | cached_current_method_(nullptr), |
Nicolas Geoffray | 53fec08 | 2017-03-27 12:56:16 +0100 | [diff] [blame] | 427 | art_method_(nullptr), |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 428 | compilation_kind_(compilation_kind), |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 429 | cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 430 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 431 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 432 | |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 433 | std::ostream& Dump(std::ostream& os, |
Nicolas Geoffray | 22df3e0 | 2022-01-10 09:31:57 +0000 | [diff] [blame] | 434 | CodeGenerator* codegen, |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 435 | std::optional<std::reference_wrapper<const BlockNamer>> namer = std::nullopt); |
| 436 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 437 | ArenaAllocator* GetAllocator() const { return allocator_; } |
| 438 | ArenaStack* GetArenaStack() const { return arena_stack_; } |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 439 | |
| 440 | HandleCache* GetHandleCache() { return &handle_cache_; } |
| 441 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 442 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 443 | |
Alex Light | 210a78d | 2020-11-30 16:58:05 -0800 | [diff] [blame] | 444 | // An iterator to only blocks that are still actually in the graph (when |
| 445 | // blocks are removed they are replaced with 'nullptr' in GetBlocks to |
| 446 | // simplify block-id assignment and avoid memmoves in the block-list). |
| 447 | IterationRange<FilterNull<ArenaVector<HBasicBlock*>::const_iterator>> GetActiveBlocks() const { |
| 448 | return FilterOutNull(MakeIterationRange(GetBlocks())); |
| 449 | } |
| 450 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 451 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 452 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 453 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 454 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 455 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 456 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 457 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 458 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 459 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 460 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 461 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 462 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 463 | void ComputeDominanceInformation(); |
| 464 | void ClearDominanceInformation(); |
Alex Light | 86fe9b8 | 2020-11-16 16:54:01 +0000 | [diff] [blame] | 465 | void ComputeReachabilityInformation(); |
| 466 | void ClearReachabilityInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 467 | void ClearLoopInformation(); |
| 468 | void FindBackEdges(ArenaBitVector* visited); |
| 469 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 470 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 471 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 472 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 473 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 474 | // 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] | 475 | // 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] | 476 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 477 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 478 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 479 | // order and loop information. |
| 480 | void ComputeTryBlockInformation(); |
| 481 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 482 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 483 | // Returns the instruction to replace the invoke expression or null if the |
| 484 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 485 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 486 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 487 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 488 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 489 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 490 | // should be the new back edge. |
Santiago Aboy Solanes | 8efb1a6 | 2022-06-24 11:16:35 +0100 | [diff] [blame] | 491 | // `has_more_specific_try_catch_info` will be set to true when inlining a try catch. |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 492 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 493 | HBasicBlock* reference, |
Santiago Aboy Solanes | 8efb1a6 | 2022-06-24 11:16:35 +0100 | [diff] [blame] | 494 | bool replace_if_back_edge, |
| 495 | bool has_more_specific_try_catch_info = false); |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 496 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 497 | // Need to add a couple of blocks to test if the loop body is entered and |
| 498 | // put deoptimization instructions, etc. |
| 499 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 500 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 501 | // Adds a new loop directly after the loop with the given header and exit. |
| 502 | // Returns the new preheader. |
| 503 | HBasicBlock* TransformLoopForVectorization(HBasicBlock* header, |
| 504 | HBasicBlock* body, |
| 505 | HBasicBlock* exit); |
| 506 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 507 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 508 | // other blocks and has no instructions or phis. |
| 509 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 510 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 511 | // Splits the edge between `block` and `successor` while preserving the |
| 512 | // indices in the predecessor/successor lists. If there are multiple edges |
| 513 | // between the blocks, the lowest indices are used. |
| 514 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 515 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 516 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 517 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
Santiago Aboy Solanes | 31242a9 | 2022-12-05 14:38:00 +0000 | [diff] [blame] | 518 | |
| 519 | // Splits the edge between `block` and `successor` and then updates the graph's RPO to keep |
| 520 | // consistency without recomputing the whole graph. |
| 521 | HBasicBlock* SplitEdgeAndUpdateRPO(HBasicBlock* block, HBasicBlock* successor); |
| 522 | |
Artem Serov | c73ee37 | 2017-07-31 15:08:40 +0100 | [diff] [blame] | 523 | void OrderLoopHeaderPredecessors(HBasicBlock* header); |
Artem Serov | 09faaea | 2017-12-07 14:36:01 +0000 | [diff] [blame] | 524 | |
| 525 | // Transform a loop into a format with a single preheader. |
| 526 | // |
| 527 | // Each phi in the header should be split: original one in the header should only hold |
| 528 | // inputs reachable from the back edges and a single input from the preheader. The newly created |
| 529 | // phi in the preheader should collate the inputs from the original multiple incoming blocks. |
| 530 | // |
| 531 | // Loops in the graph typically have a single preheader, so this method is used to "repair" loops |
| 532 | // that no longer have this property. |
| 533 | void TransformLoopToSinglePreheaderFormat(HBasicBlock* header); |
| 534 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 535 | void SimplifyLoop(HBasicBlock* header); |
| 536 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 537 | int32_t GetNextInstructionId() { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 538 | CHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 539 | return current_instruction_id_++; |
| 540 | } |
| 541 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 542 | int32_t GetCurrentInstructionId() const { |
| 543 | return current_instruction_id_; |
| 544 | } |
| 545 | |
| 546 | void SetCurrentInstructionId(int32_t id) { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 547 | CHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 548 | current_instruction_id_ = id; |
| 549 | } |
| 550 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 551 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 552 | return maximum_number_of_out_vregs_; |
| 553 | } |
| 554 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 555 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 556 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 557 | } |
| 558 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 559 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 560 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 561 | } |
| 562 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 563 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 564 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 565 | } |
| 566 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 567 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 568 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 569 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 570 | } |
| 571 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 572 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 573 | number_of_vregs_ = number_of_vregs; |
| 574 | } |
| 575 | |
| 576 | uint16_t GetNumberOfVRegs() const { |
| 577 | return number_of_vregs_; |
| 578 | } |
| 579 | |
| 580 | void SetNumberOfInVRegs(uint16_t value) { |
| 581 | number_of_in_vregs_ = value; |
| 582 | } |
| 583 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 584 | uint16_t GetNumberOfInVRegs() const { |
| 585 | return number_of_in_vregs_; |
| 586 | } |
| 587 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 588 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 589 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 590 | return number_of_vregs_ - number_of_in_vregs_; |
| 591 | } |
| 592 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 593 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 594 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 595 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 596 | |
Eric Holk | 1868de9 | 2020-02-12 09:10:21 -0800 | [diff] [blame] | 597 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() const { |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 598 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 599 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 600 | } |
| 601 | |
| 602 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 603 | return ReverseRange(GetReversePostOrder()); |
| 604 | } |
| 605 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 606 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 607 | return linear_order_; |
| 608 | } |
| 609 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 610 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 611 | return ReverseRange(GetLinearOrder()); |
| 612 | } |
| 613 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 614 | bool HasBoundsChecks() const { |
| 615 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 616 | } |
| 617 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 618 | void SetHasBoundsChecks(bool value) { |
| 619 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 620 | } |
| 621 | |
Alex Light | 86fe9b8 | 2020-11-16 16:54:01 +0000 | [diff] [blame] | 622 | // Returns true if dest is reachable from source, using either blocks or block-ids. |
| 623 | bool PathBetween(const HBasicBlock* source, const HBasicBlock* dest) const; |
| 624 | bool PathBetween(uint32_t source_id, uint32_t dest_id) const; |
| 625 | |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 626 | // Is the code known to be robust against eliminating dead references |
| 627 | // and the effects of early finalization? |
| 628 | bool IsDeadReferenceSafe() const { return dead_reference_safe_; } |
| 629 | |
| 630 | void MarkDeadReferenceUnsafe() { dead_reference_safe_ = false; } |
| 631 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 632 | bool IsDebuggable() const { return debuggable_; } |
| 633 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 634 | // 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] | 635 | // already, it is created and inserted into the graph. This method is only for |
| 636 | // integral types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 637 | 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] | 638 | |
| 639 | // TODO: This is problematic for the consistency of reference type propagation |
| 640 | // because it can be created anytime after the pass and thus it will be left |
| 641 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 642 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 643 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 644 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 645 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 646 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 647 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 648 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 649 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 650 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 651 | 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] | 652 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 653 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 654 | 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] | 655 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 656 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 657 | HCurrentMethod* GetCurrentMethod(); |
| 658 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 659 | const DexFile& GetDexFile() const { |
| 660 | return dex_file_; |
| 661 | } |
| 662 | |
| 663 | uint32_t GetMethodIdx() const { |
| 664 | return method_idx_; |
| 665 | } |
| 666 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 667 | // Get the method name (without the signature), e.g. "<init>" |
| 668 | const char* GetMethodName() const; |
| 669 | |
| 670 | // Get the pretty method name (class + name + optionally signature). |
| 671 | std::string PrettyMethod(bool with_signature = true) const; |
| 672 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 673 | InvokeType GetInvokeType() const { |
| 674 | return invoke_type_; |
| 675 | } |
| 676 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 677 | InstructionSet GetInstructionSet() const { |
| 678 | return instruction_set_; |
| 679 | } |
| 680 | |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 681 | bool IsCompilingOsr() const { return compilation_kind_ == CompilationKind::kOsr; } |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 682 | |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 683 | bool IsCompilingBaseline() const { return compilation_kind_ == CompilationKind::kBaseline; } |
| 684 | |
| 685 | CompilationKind GetCompilationKind() const { return compilation_kind_; } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 686 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 687 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 688 | return cha_single_implementation_list_; |
| 689 | } |
| 690 | |
Stelios Ioannou | c54cc7c | 2021-07-09 17:06:03 +0100 | [diff] [blame] | 691 | // In case of OSR we intend to use SuspendChecks as an entry point to the |
| 692 | // function; for debuggable graphs we might deoptimize to interpreter from |
| 693 | // SuspendChecks. In these cases we should always generate code for them. |
| 694 | bool SuspendChecksAreAllowedToNoOp() const { |
| 695 | return !IsDebuggable() && !IsCompilingOsr(); |
| 696 | } |
| 697 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 698 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 699 | cha_single_implementation_list_.insert(method); |
| 700 | } |
| 701 | |
| 702 | bool HasShouldDeoptimizeFlag() const { |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 703 | return number_of_cha_guards_ != 0 || debuggable_; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 704 | } |
| 705 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 706 | bool HasTryCatch() const { return has_try_catch_; } |
| 707 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 708 | |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 709 | bool HasMonitorOperations() const { return has_monitor_operations_; } |
| 710 | void SetHasMonitorOperations(bool value) { has_monitor_operations_ = value; } |
| 711 | |
Artem Serov | 0b284aa | 2021-12-14 23:16:21 +0000 | [diff] [blame] | 712 | bool HasTraditionalSIMD() { return has_traditional_simd_; } |
| 713 | void SetHasTraditionalSIMD(bool value) { has_traditional_simd_ = value; } |
| 714 | |
| 715 | bool HasPredicatedSIMD() { return has_predicated_simd_; } |
| 716 | void SetHasPredicatedSIMD(bool value) { has_predicated_simd_ = value; } |
| 717 | |
| 718 | bool HasSIMD() const { return has_traditional_simd_ || has_predicated_simd_; } |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 719 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 720 | bool HasLoops() const { return has_loops_; } |
| 721 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 722 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 723 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 724 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 725 | |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 726 | bool HasDirectCriticalNativeCall() const { return has_direct_critical_native_call_; } |
| 727 | void SetHasDirectCriticalNativeCall(bool value) { has_direct_critical_native_call_ = value; } |
| 728 | |
Santiago Aboy Solanes | 78f3d3a | 2022-07-15 14:30:05 +0100 | [diff] [blame] | 729 | bool HasAlwaysThrowingInvokes() const { return has_always_throwing_invokes_; } |
| 730 | void SetHasAlwaysThrowingInvokes(bool value) { has_always_throwing_invokes_ = value; } |
| 731 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 732 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 733 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 734 | |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 735 | void SetProfilingInfo(ProfilingInfo* info) { profiling_info_ = info; } |
| 736 | ProfilingInfo* GetProfilingInfo() const { return profiling_info_; } |
| 737 | |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 738 | // Returns an instruction with the opposite Boolean value from 'cond'. |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 739 | // The instruction has been inserted into the graph, either as a constant, or |
| 740 | // before cursor. |
| 741 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 742 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 743 | ReferenceTypeInfo GetInexactObjectRti() { |
| 744 | return ReferenceTypeInfo::Create(handle_cache_.GetObjectClassHandle(), /* is_exact= */ false); |
| 745 | } |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 746 | |
Stelios Ioannou | c54cc7c | 2021-07-09 17:06:03 +0100 | [diff] [blame] | 747 | uint32_t GetNumberOfCHAGuards() const { return number_of_cha_guards_; } |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 748 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 749 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 750 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 751 | private: |
Santiago Aboy Solanes | 65fd6a3 | 2022-08-22 13:12:46 +0100 | [diff] [blame] | 752 | void RemoveDeadBlocksInstructionsAsUsersAndDisconnect(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 753 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 754 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 755 | template <class InstructionType, typename ValueType> |
| 756 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 757 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 758 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 759 | // Try to find an existing constant of the given value. |
| 760 | InstructionType* constant = nullptr; |
| 761 | auto cached_constant = cache->find(value); |
| 762 | if (cached_constant != cache->end()) { |
| 763 | constant = cached_constant->second; |
| 764 | } |
| 765 | |
| 766 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 767 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 768 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 769 | constant = new (allocator_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 770 | cache->Overwrite(value, constant); |
| 771 | InsertConstant(constant); |
| 772 | } |
| 773 | return constant; |
| 774 | } |
| 775 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 776 | void InsertConstant(HConstant* instruction); |
| 777 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 778 | // Cache a float constant into the graph. This method should only be |
| 779 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 780 | void CacheFloatConstant(HFloatConstant* constant); |
| 781 | |
| 782 | // See CacheFloatConstant comment. |
| 783 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 784 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 785 | ArenaAllocator* const allocator_; |
| 786 | ArenaStack* const arena_stack_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 787 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 788 | HandleCache handle_cache_; |
| 789 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 790 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 791 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 792 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 793 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 794 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 795 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 796 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 797 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 798 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 799 | |
Alex Light | 86fe9b8 | 2020-11-16 16:54:01 +0000 | [diff] [blame] | 800 | // Reachability graph for checking connectedness between nodes. Acts as a partitioned vector where |
| 801 | // each RoundUp(blocks_.size(), BitVector::kWordBits) is the reachability of each node. |
| 802 | ArenaBitVectorArray reachability_graph_; |
| 803 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 804 | HBasicBlock* entry_block_; |
| 805 | HBasicBlock* exit_block_; |
| 806 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 807 | // 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] | 808 | uint16_t maximum_number_of_out_vregs_; |
| 809 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 810 | // The number of virtual registers in this method. Contains the parameters. |
| 811 | uint16_t number_of_vregs_; |
| 812 | |
| 813 | // The number of virtual registers used by parameters of this method. |
| 814 | uint16_t number_of_in_vregs_; |
| 815 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 816 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 817 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 818 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 819 | // Flag whether there are bounds checks in the graph. We can skip |
Santiago Aboy Solanes | 74da668 | 2022-12-16 19:28:47 +0000 | [diff] [blame] | 820 | // BCE if it's false. |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 821 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 822 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 823 | // Flag whether there are try/catch blocks in the graph. We will skip |
Santiago Aboy Solanes | 74da668 | 2022-12-16 19:28:47 +0000 | [diff] [blame] | 824 | // try/catch-related passes if it's false. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 825 | bool has_try_catch_; |
| 826 | |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 827 | // Flag whether there are any HMonitorOperation in the graph. If yes this will mandate |
| 828 | // DexRegisterMap to be present to allow deadlock analysis for non-debuggable code. |
| 829 | bool has_monitor_operations_; |
| 830 | |
Artem Serov | 0b284aa | 2021-12-14 23:16:21 +0000 | [diff] [blame] | 831 | // Flags whether SIMD (traditional or predicated) instructions appear in the graph. |
| 832 | // If either is true, the code generators may have to be more careful spilling the wider |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 833 | // contents of SIMD registers. |
Artem Serov | 0b284aa | 2021-12-14 23:16:21 +0000 | [diff] [blame] | 834 | bool has_traditional_simd_; |
| 835 | bool has_predicated_simd_; |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 836 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 837 | // Flag whether there are any loops in the graph. We can skip loop |
Santiago Aboy Solanes | 74da668 | 2022-12-16 19:28:47 +0000 | [diff] [blame] | 838 | // optimization if it's false. |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 839 | bool has_loops_; |
| 840 | |
Santiago Aboy Solanes | 74da668 | 2022-12-16 19:28:47 +0000 | [diff] [blame] | 841 | // Flag whether there are any irreducible loops in the graph. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 842 | bool has_irreducible_loops_; |
| 843 | |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 844 | // Flag whether there are any direct calls to native code registered |
| 845 | // for @CriticalNative methods. |
| 846 | bool has_direct_critical_native_call_; |
| 847 | |
Santiago Aboy Solanes | 78f3d3a | 2022-07-15 14:30:05 +0100 | [diff] [blame] | 848 | // Flag whether the graph contains invokes that always throw. |
| 849 | bool has_always_throwing_invokes_; |
| 850 | |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 851 | // Is the code known to be robust against eliminating dead references |
| 852 | // and the effects of early finalization? If false, dead reference variables |
| 853 | // are kept if they might be visible to the garbage collector. |
| 854 | // Currently this means that the class was declared to be dead-reference-safe, |
| 855 | // the method accesses no reachability-sensitive fields or data, and the same |
| 856 | // is true for any methods that were inlined into the current one. |
| 857 | bool dead_reference_safe_; |
| 858 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 859 | // Indicates whether the graph should be compiled in a way that |
| 860 | // ensures full debuggability. If false, we can apply more |
| 861 | // aggressive optimizations that may limit the level of debugging. |
| 862 | const bool debuggable_; |
| 863 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 864 | // 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] | 865 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 866 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 867 | // The dex file from which the method is from. |
| 868 | const DexFile& dex_file_; |
| 869 | |
| 870 | // The method index in the dex file. |
| 871 | const uint32_t method_idx_; |
| 872 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 873 | // If inlined, this encodes how the callee is being invoked. |
| 874 | const InvokeType invoke_type_; |
| 875 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 876 | // Whether the graph has been transformed to SSA form. Only used |
| 877 | // in debug mode to ensure we are not using properties only valid |
| 878 | // for non-SSA form (like the number of temporaries). |
| 879 | bool in_ssa_form_; |
| 880 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 881 | // Number of CHA guards in the graph. Used to short-circuit the |
| 882 | // CHA guard optimization pass when there is no CHA guard left. |
| 883 | uint32_t number_of_cha_guards_; |
| 884 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 885 | const InstructionSet instruction_set_; |
| 886 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 887 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 888 | HNullConstant* cached_null_constant_; |
| 889 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 890 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 891 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 892 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 893 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 894 | HCurrentMethod* cached_current_method_; |
| 895 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 896 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 897 | // for example for methods whose declaring class could not be resolved |
| 898 | // (such as when the superclass could not be found). |
| 899 | ArtMethod* art_method_; |
| 900 | |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 901 | // The `ProfilingInfo` associated with the method being compiled. |
| 902 | ProfilingInfo* profiling_info_; |
| 903 | |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 904 | // How we are compiling the graph: either optimized, osr, or baseline. |
| 905 | // For osr, we will make all loops seen as irreducible and emit special |
| 906 | // stack maps to mark compiled code entries which the interpreter can |
| 907 | // directly jump to. |
| 908 | const CompilationKind compilation_kind_; |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 909 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 910 | // List of methods that are assumed to have single implementation. |
| 911 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 912 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 913 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 914 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 915 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 916 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 917 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 918 | }; |
| 919 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 920 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 921 | public: |
| 922 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 923 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 924 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 925 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 926 | contains_irreducible_loop_(false), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 927 | back_edges_(graph->GetAllocator()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 928 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 929 | blocks_(graph->GetAllocator(), |
| 930 | graph->GetBlocks().size(), |
| 931 | true, |
| 932 | kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 933 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 934 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 935 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 936 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 937 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 938 | |
| 939 | void Dump(std::ostream& os); |
| 940 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 941 | HBasicBlock* GetHeader() const { |
| 942 | return header_; |
| 943 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 944 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 945 | void SetHeader(HBasicBlock* block) { |
| 946 | header_ = block; |
| 947 | } |
| 948 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 949 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 950 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 951 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 952 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 953 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 954 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 957 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 958 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 959 | } |
| 960 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 961 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 962 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 963 | } |
| 964 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 965 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 966 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 967 | } |
| 968 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 969 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 970 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 971 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 972 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 973 | } |
| 974 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 975 | // Returns the lifetime position of the back edge that has the |
| 976 | // greatest lifetime position. |
| 977 | size_t GetLifetimeEnd() const; |
| 978 | |
| 979 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 980 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 981 | } |
| 982 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 983 | // Finds blocks that are part of this loop. |
| 984 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 985 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 986 | // Updates blocks population of the loop and all of its outer' ones recursively after the |
| 987 | // population of the inner loop is updated. |
| 988 | void PopulateInnerLoopUpwards(HLoopInformation* inner_loop); |
| 989 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 990 | // Returns whether this loop information contains `block`. |
| 991 | // Note that this loop information *must* be populated before entering this function. |
| 992 | bool Contains(const HBasicBlock& block) const; |
| 993 | |
| 994 | // Returns whether this loop information is an inner loop of `other`. |
| 995 | // Note that `other` *must* be populated before entering this function. |
| 996 | bool IsIn(const HLoopInformation& other) const; |
| 997 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 998 | // Returns true if instruction is not defined within this loop. |
| 999 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 1000 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1001 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 1002 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1003 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1004 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1005 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 1006 | void ClearAllBlocks() { |
| 1007 | blocks_.ClearAllBits(); |
| 1008 | } |
| 1009 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 1010 | bool HasBackEdgeNotDominatedByHeader() const; |
| 1011 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 1012 | bool IsPopulated() const { |
| 1013 | return blocks_.GetHighestBitSet() != -1; |
| 1014 | } |
| 1015 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 1016 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 1017 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 1018 | bool HasExitEdge() const; |
| 1019 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 1020 | // Resets back edge and blocks-in-loop data. |
| 1021 | void ResetBasicBlockData() { |
| 1022 | back_edges_.clear(); |
| 1023 | ClearAllBlocks(); |
| 1024 | } |
| 1025 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1026 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1027 | // Internal recursive implementation of `Populate`. |
| 1028 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 1029 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1030 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1031 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1032 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1033 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 1034 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1035 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1036 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1037 | |
| 1038 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 1039 | }; |
| 1040 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1041 | // Stores try/catch information for basic blocks. |
| 1042 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 1043 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1044 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1045 | public: |
| 1046 | // Try block information constructor. |
| 1047 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 1048 | : try_entry_(&try_entry), |
| 1049 | catch_dex_file_(nullptr), |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1050 | catch_type_index_(dex::TypeIndex::Invalid()) { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1051 | DCHECK(try_entry_ != nullptr); |
| 1052 | } |
| 1053 | |
| 1054 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1055 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1056 | : try_entry_(nullptr), |
| 1057 | catch_dex_file_(&dex_file), |
| 1058 | catch_type_index_(catch_type_index) {} |
| 1059 | |
| 1060 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 1061 | |
| 1062 | const HTryBoundary& GetTryEntry() const { |
| 1063 | DCHECK(IsTryBlock()); |
| 1064 | return *try_entry_; |
| 1065 | } |
| 1066 | |
| 1067 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 1068 | |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1069 | bool IsValidTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1070 | DCHECK(IsCatchBlock()); |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1071 | return catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1072 | } |
| 1073 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1074 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1075 | DCHECK(IsCatchBlock()); |
| 1076 | return catch_type_index_; |
| 1077 | } |
| 1078 | |
| 1079 | const DexFile& GetCatchDexFile() const { |
| 1080 | DCHECK(IsCatchBlock()); |
| 1081 | return *catch_dex_file_; |
| 1082 | } |
| 1083 | |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1084 | void SetInvalidTypeIndex() { |
| 1085 | catch_type_index_ = dex::TypeIndex::Invalid(); |
| 1086 | } |
| 1087 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1088 | private: |
| 1089 | // One of possibly several TryBoundary instructions entering the block's try. |
| 1090 | // Only set for try blocks. |
| 1091 | const HTryBoundary* try_entry_; |
| 1092 | |
| 1093 | // Exception type information. Only set for catch blocks. |
| 1094 | const DexFile* catch_dex_file_; |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1095 | dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1096 | }; |
| 1097 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1098 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1099 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1100 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1101 | // A block in a method. Contains the list of instructions represented |
| 1102 | // as a double linked list. Each block knows its predecessors and |
| 1103 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1104 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1105 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1106 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 1107 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1108 | : graph_(graph), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1109 | predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), |
| 1110 | successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1111 | loop_information_(nullptr), |
| 1112 | dominator_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1113 | dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1114 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1115 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1116 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1117 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1118 | try_catch_information_(nullptr) { |
| 1119 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 1120 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 1121 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 1122 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1123 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1124 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1125 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 1128 | size_t GetNumberOfPredecessors() const { |
| 1129 | return GetPredecessors().size(); |
| 1130 | } |
| 1131 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1132 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1133 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 1136 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 1137 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 1138 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1139 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 1140 | return ContainsElement(successors_, block, start_from); |
| 1141 | } |
| 1142 | |
| 1143 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1144 | return dominated_blocks_; |
| 1145 | } |
| 1146 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1147 | bool IsEntryBlock() const { |
| 1148 | return graph_->GetEntryBlock() == this; |
| 1149 | } |
| 1150 | |
| 1151 | bool IsExitBlock() const { |
| 1152 | return graph_->GetExitBlock() == this; |
| 1153 | } |
| 1154 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1155 | bool IsSingleGoto() const; |
Mads Ager | 16e5289 | 2017-07-14 13:11:37 +0200 | [diff] [blame] | 1156 | bool IsSingleReturn() const; |
Mingyao Yang | 46721ef | 2017-10-05 14:45:17 -0700 | [diff] [blame] | 1157 | bool IsSingleReturnOrReturnVoidAllowingPhis() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1158 | bool IsSingleTryBoundary() const; |
| 1159 | |
| 1160 | // Returns true if this block emits nothing but a jump. |
| 1161 | bool IsSingleJump() const { |
| 1162 | HLoopInformation* loop_info = GetLoopInformation(); |
| 1163 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 1164 | // Back edges generate a suspend check. |
| 1165 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 1166 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1167 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1168 | void AddBackEdge(HBasicBlock* back_edge) { |
| 1169 | if (loop_information_ == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1170 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1171 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1172 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1173 | loop_information_->AddBackEdge(back_edge); |
| 1174 | } |
| 1175 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 1176 | // Registers a back edge; if the block was not a loop header before the call associates a newly |
| 1177 | // created loop info with it. |
| 1178 | // |
| 1179 | // Used in SuperblockCloner to preserve LoopInformation object instead of reseting loop |
| 1180 | // info for all blocks during back edges recalculation. |
| 1181 | void AddBackEdgeWhileUpdating(HBasicBlock* back_edge) { |
| 1182 | if (loop_information_ == nullptr || loop_information_->GetHeader() != this) { |
| 1183 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
| 1184 | } |
| 1185 | loop_information_->AddBackEdge(back_edge); |
| 1186 | } |
| 1187 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1188 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1189 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1190 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1191 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1192 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1193 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1194 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1195 | HBasicBlock* GetDominator() const { return dominator_; } |
| 1196 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1197 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 1198 | |
| 1199 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 1200 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 1201 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1202 | |
| 1203 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1204 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 1205 | } |
| 1206 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1207 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1208 | |
| 1209 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1210 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1213 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1214 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1215 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1216 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1217 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1218 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1219 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1220 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1221 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1222 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1223 | successors_.push_back(block); |
| 1224 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1227 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1228 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1229 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1230 | new_block->predecessors_.push_back(this); |
| 1231 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1234 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1235 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1236 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1237 | new_block->successors_.push_back(this); |
| 1238 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1241 | // Insert `this` between `predecessor` and `successor. This method |
Alex Light | 1e52a07 | 2019-06-25 09:12:04 -0700 | [diff] [blame] | 1242 | // preserves the indices, and will update the first edge found between |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1243 | // `predecessor` and `successor`. |
| 1244 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1245 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1246 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1247 | successor->predecessors_[predecessor_index] = this; |
| 1248 | predecessor->successors_[successor_index] = this; |
| 1249 | successors_.push_back(successor); |
| 1250 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1251 | } |
| 1252 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1253 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1254 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1255 | } |
| 1256 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1257 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1258 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1261 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1262 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1266 | predecessors_.push_back(block); |
| 1267 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1268 | } |
| 1269 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1270 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1271 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1272 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1273 | } |
| 1274 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1275 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1276 | DCHECK_EQ(successors_.size(), 2u); |
| 1277 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1278 | } |
| 1279 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1280 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1281 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1282 | } |
| 1283 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1284 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1285 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1286 | } |
| 1287 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1288 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1289 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1290 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1294 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1295 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1299 | // predecessors is at index `idx`. |
| 1300 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1301 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1302 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1303 | } |
| 1304 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1305 | // Create a new block between this block and its predecessors. The new block |
| 1306 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1307 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1308 | // loop and try/catch information are not updated. |
| 1309 | HBasicBlock* CreateImmediateDominator(); |
| 1310 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1311 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1312 | // created, latter block. Note that this method will add the block to the |
| 1313 | // graph, create a Goto at the end of the former block and will create an edge |
| 1314 | // 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] | 1315 | // loop and try/catch information. |
Santiago Aboy Solanes | 78f3d3a | 2022-07-15 14:30:05 +0100 | [diff] [blame] | 1316 | HBasicBlock* SplitBefore(HInstruction* cursor, bool require_graph_not_in_ssa_form = true); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1317 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1318 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1319 | // created block. Note that this method just updates raw block information, |
| 1320 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1321 | // update the graph, reverse post order, loop information, nor make sure the |
| 1322 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1323 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1324 | |
| 1325 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1326 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1327 | |
| 1328 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1329 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1330 | // that this method does not update the graph, reverse post order, loop |
| 1331 | // information, nor make sure the blocks are consistent (for example ending |
| 1332 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1333 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1334 | |
| 1335 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1336 | // of `this` are moved to `other`. |
| 1337 | // Note that this method does not update the graph, reverse post order, loop |
| 1338 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1339 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1340 | void ReplaceWith(HBasicBlock* other); |
| 1341 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1342 | // Merges the instructions of `other` at the end of `this`. |
| 1343 | void MergeInstructionsWith(HBasicBlock* other); |
| 1344 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1345 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1346 | // order, links to predecessors, successors, dominators and deletes the block |
| 1347 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1348 | // predecessor of `other` and vice versa. |
| 1349 | void MergeWith(HBasicBlock* other); |
| 1350 | |
| 1351 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1352 | // removes it from all loops it is included in and eventually from the graph. |
| 1353 | // The block must not dominate any other block. Predecessors and successors |
| 1354 | // are safely updated. |
| 1355 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1356 | |
Santiago Aboy Solanes | d48da35 | 2022-07-28 17:58:53 +0100 | [diff] [blame] | 1357 | // Disconnects `this` from all its successors and updates their phis, if the successors have them. |
| 1358 | // If `visited` is provided, it will use the information to know if a successor is reachable and |
| 1359 | // skip updating those phis. |
| 1360 | void DisconnectFromSuccessors(const ArenaBitVector* visited = nullptr); |
| 1361 | |
Santiago Aboy Solanes | 7023bf8 | 2022-08-19 10:28:11 +0100 | [diff] [blame] | 1362 | // Removes the catch phi uses of the instructions in `this`, and then remove the instruction |
| 1363 | // itself. If `building_dominator_tree` is true, it will not remove the instruction as user, since |
| 1364 | // we do it in a previous step. This is a special case for building up the dominator tree: we want |
| 1365 | // to eliminate uses before inputs but we don't have domination information, so we remove all |
| 1366 | // connections from input/uses first before removing any instruction. |
| 1367 | // This method assumes the instructions have been removed from all users with the exception of |
| 1368 | // catch phis because of missing exceptional edges in the graph. |
| 1369 | void RemoveCatchPhiUsesAndInstruction(bool building_dominator_tree); |
Santiago Aboy Solanes | d48da35 | 2022-07-28 17:58:53 +0100 | [diff] [blame] | 1370 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1371 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1372 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1373 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1374 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1375 | // Replace phi `initial` with `replacement` within this block. |
| 1376 | void ReplaceAndRemovePhiWith(HPhi* initial, HPhi* replacement); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1377 | // Replace instruction `initial` with `replacement` within this block. |
| 1378 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1379 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1380 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1381 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1382 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1383 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1384 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1385 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1386 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1387 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1388 | |
| 1389 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1390 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1391 | } |
| 1392 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1393 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1394 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1395 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1398 | bool IsFirstPredecessorBackEdge() const { |
| 1399 | DCHECK(IsLoopHeader()); |
| 1400 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1401 | } |
| 1402 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1403 | HLoopInformation* GetLoopInformation() const { |
| 1404 | return loop_information_; |
| 1405 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1406 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1407 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1408 | // 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] | 1409 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1410 | void SetInLoop(HLoopInformation* info) { |
| 1411 | if (IsLoopHeader()) { |
| 1412 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1413 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1414 | loop_information_ = info; |
| 1415 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1416 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1417 | // Note that a non loop header having a loop information means this loop information |
| 1418 | // has already been populated |
| 1419 | loop_information_ = info; |
| 1420 | } else { |
| 1421 | // Block is part of an inner loop. Do not update the loop information. |
| 1422 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1423 | // at this point, because this method is being called while populating `info`. |
| 1424 | } |
| 1425 | } |
| 1426 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1427 | // Raw update of the loop information. |
| 1428 | void SetLoopInformation(HLoopInformation* info) { |
| 1429 | loop_information_ = info; |
| 1430 | } |
| 1431 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1432 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1433 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1434 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1435 | |
| 1436 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1437 | try_catch_information_ = try_catch_information; |
| 1438 | } |
| 1439 | |
| 1440 | bool IsTryBlock() const { |
| 1441 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1442 | } |
| 1443 | |
| 1444 | bool IsCatchBlock() const { |
| 1445 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1446 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1447 | |
| 1448 | // Returns the try entry that this block's successors should have. They will |
| 1449 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1450 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1451 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1452 | |
Aart Bik | 75ff2c9 | 2018-04-21 01:28:11 +0000 | [diff] [blame] | 1453 | bool HasThrowingInstructions() const; |
| 1454 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1455 | // Returns whether this block dominates the blocked passed as parameter. |
Vladimir Marko | 8d100ba | 2022-03-04 10:13:10 +0000 | [diff] [blame] | 1456 | bool Dominates(const HBasicBlock* block) const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1457 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1458 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1459 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1460 | |
| 1461 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1462 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1463 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1464 | bool EndsWithControlFlowInstruction() const; |
Aart Bik | 4dc09e7 | 2018-05-11 14:40:31 -0700 | [diff] [blame] | 1465 | bool EndsWithReturn() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1466 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1467 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1468 | bool HasSinglePhi() const; |
| 1469 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1470 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1471 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1472 | ArenaVector<HBasicBlock*> predecessors_; |
| 1473 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1474 | HInstructionList instructions_; |
| 1475 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1476 | HLoopInformation* loop_information_; |
| 1477 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1478 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1479 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1480 | // The dex program counter of the first instruction of this block. |
| 1481 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1482 | size_t lifetime_start_; |
| 1483 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1484 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1485 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1486 | friend class HGraph; |
| 1487 | friend class HInstruction; |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 1488 | // Allow manual control of the ordering of predecessors/successors |
| 1489 | friend class OptimizingUnitTestHelper; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1490 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1491 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1492 | }; |
| 1493 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1494 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1495 | // from the innermost to the outermost. |
| 1496 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1497 | public: |
| 1498 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1499 | : current_(block.GetLoopInformation()) {} |
| 1500 | |
| 1501 | bool Done() const { return current_ == nullptr; } |
| 1502 | |
| 1503 | void Advance() { |
| 1504 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1505 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | HLoopInformation* Current() const { |
| 1509 | DCHECK(!Done()); |
| 1510 | return current_; |
| 1511 | } |
| 1512 | |
| 1513 | private: |
| 1514 | HLoopInformation* current_; |
| 1515 | |
| 1516 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1517 | }; |
| 1518 | |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1519 | #define FOR_EACH_CONCRETE_INSTRUCTION_SCALAR_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1520 | M(Above, Condition) \ |
| 1521 | M(AboveOrEqual, Condition) \ |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 1522 | M(Abs, UnaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1523 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1524 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1525 | M(ArrayGet, Instruction) \ |
| 1526 | M(ArrayLength, Instruction) \ |
| 1527 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1528 | M(Below, Condition) \ |
| 1529 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1530 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1531 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1532 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1533 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1534 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1535 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1536 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1537 | M(Compare, BinaryOperation) \ |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1538 | M(ConstructorFence, Instruction) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1539 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1540 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1541 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1542 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1543 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1544 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1545 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1546 | M(Exit, Instruction) \ |
| 1547 | M(FloatConstant, Constant) \ |
| 1548 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1549 | M(GreaterThan, Condition) \ |
| 1550 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1551 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1552 | M(InstanceFieldGet, Instruction) \ |
| 1553 | M(InstanceFieldSet, Instruction) \ |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 1554 | M(PredicatedInstanceFieldGet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1555 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1556 | M(IntConstant, Constant) \ |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 1557 | M(IntermediateAddress, Instruction) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1558 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1559 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1560 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1561 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1562 | M(InvokePolymorphic, Invoke) \ |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1563 | M(InvokeCustom, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1564 | M(LessThan, Condition) \ |
| 1565 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1566 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1567 | M(LoadException, Instruction) \ |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 1568 | M(LoadMethodHandle, Instruction) \ |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 1569 | M(LoadMethodType, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1570 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1571 | M(LongConstant, Constant) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1572 | M(Max, Instruction) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1573 | M(MemoryBarrier, Instruction) \ |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1574 | M(MethodEntryHook, Instruction) \ |
| 1575 | M(MethodExitHook, Instruction) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1576 | M(Min, BinaryOperation) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1577 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1578 | M(Mul, BinaryOperation) \ |
| 1579 | M(Neg, UnaryOperation) \ |
| 1580 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1581 | M(NewInstance, Instruction) \ |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 1582 | M(Nop, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1583 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1584 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1585 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1586 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1587 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1588 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1589 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1590 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1591 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1592 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1593 | M(Return, Instruction) \ |
| 1594 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1595 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1596 | M(Shl, BinaryOperation) \ |
| 1597 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1598 | M(StaticFieldGet, Instruction) \ |
| 1599 | M(StaticFieldSet, Instruction) \ |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 1600 | M(StringBuilderAppend, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1601 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1602 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1603 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1604 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1605 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1606 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1607 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1608 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1609 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1610 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1611 | M(UShr, BinaryOperation) \ |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1612 | M(Xor, BinaryOperation) |
| 1613 | |
| 1614 | #define FOR_EACH_CONCRETE_INSTRUCTION_VECTOR_COMMON(M) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1615 | M(VecReplicateScalar, VecUnaryOperation) \ |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1616 | M(VecExtractScalar, VecUnaryOperation) \ |
| 1617 | M(VecReduce, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1618 | M(VecCnv, VecUnaryOperation) \ |
| 1619 | M(VecNeg, VecUnaryOperation) \ |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1620 | M(VecAbs, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1621 | M(VecNot, VecUnaryOperation) \ |
| 1622 | M(VecAdd, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1623 | M(VecHalvingAdd, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1624 | M(VecSub, VecBinaryOperation) \ |
| 1625 | M(VecMul, VecBinaryOperation) \ |
| 1626 | M(VecDiv, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1627 | M(VecMin, VecBinaryOperation) \ |
| 1628 | M(VecMax, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1629 | M(VecAnd, VecBinaryOperation) \ |
| 1630 | M(VecAndNot, VecBinaryOperation) \ |
| 1631 | M(VecOr, VecBinaryOperation) \ |
| 1632 | M(VecXor, VecBinaryOperation) \ |
Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1633 | M(VecSaturationAdd, VecBinaryOperation) \ |
| 1634 | M(VecSaturationSub, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1635 | M(VecShl, VecBinaryOperation) \ |
| 1636 | M(VecShr, VecBinaryOperation) \ |
| 1637 | M(VecUShr, VecBinaryOperation) \ |
Aart Bik | 8de5916 | 2017-04-21 09:42:01 -0700 | [diff] [blame] | 1638 | M(VecSetScalars, VecOperation) \ |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1639 | M(VecMultiplyAccumulate, VecOperation) \ |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1640 | M(VecSADAccumulate, VecOperation) \ |
Artem Serov | aaac0e3 | 2018-08-07 00:52:22 +0100 | [diff] [blame] | 1641 | M(VecDotProd, VecOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1642 | M(VecLoad, VecMemoryOperation) \ |
| 1643 | M(VecStore, VecMemoryOperation) \ |
Artem Serov | 0771884 | 2020-02-24 18:51:42 +0000 | [diff] [blame] | 1644 | M(VecPredSetAll, VecPredSetOperation) \ |
| 1645 | M(VecPredWhile, VecPredSetOperation) \ |
Artem Serov | 0b284aa | 2021-12-14 23:16:21 +0000 | [diff] [blame] | 1646 | M(VecPredToBoolean, VecOperation) \ |
| 1647 | M(VecCondition, VecPredSetOperation) \ |
| 1648 | M(VecPredNot, VecPredSetOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1649 | |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1650 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1651 | FOR_EACH_CONCRETE_INSTRUCTION_SCALAR_COMMON(M) \ |
| 1652 | FOR_EACH_CONCRETE_INSTRUCTION_VECTOR_COMMON(M) |
| 1653 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1654 | /* |
| 1655 | * Instructions, shared across several (not all) architectures. |
| 1656 | */ |
| 1657 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1658 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1659 | #else |
| 1660 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1661 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1662 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1663 | M(MultiplyAccumulate, Instruction) \ |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 1664 | M(IntermediateAddressIndex, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1665 | #endif |
| 1666 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1667 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1668 | |
| 1669 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1670 | |
Lifang Xia | 12e1aff | 2023-06-08 20:36:52 +0800 | [diff] [blame] | 1671 | #define FOR_EACH_CONCRETE_INSTRUCTION_RISCV64(M) |
| 1672 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1673 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1674 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1675 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1676 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1677 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1678 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1679 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1680 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1681 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1682 | |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 1683 | #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64) |
| 1684 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) \ |
Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 1685 | M(X86AndNot, Instruction) \ |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 1686 | M(X86MaskOrResetLeastSetBit, Instruction) |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 1687 | #else |
| 1688 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) |
| 1689 | #endif |
| 1690 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1691 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1692 | |
| 1693 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1694 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1695 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1696 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1697 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
| 1698 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 1699 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) \ |
| 1700 | FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1701 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1702 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1703 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1704 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1705 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1706 | M(BinaryOperation, Instruction) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1707 | M(Invoke, Instruction) \ |
| 1708 | M(VecOperation, Instruction) \ |
| 1709 | M(VecUnaryOperation, VecOperation) \ |
| 1710 | M(VecBinaryOperation, VecOperation) \ |
Artem Serov | 0771884 | 2020-02-24 18:51:42 +0000 | [diff] [blame] | 1711 | M(VecMemoryOperation, VecOperation) \ |
| 1712 | M(VecPredSetOperation, VecOperation) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1713 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1714 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1715 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1716 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1717 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1718 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1719 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1720 | #undef FORWARD_DECLARATION |
| 1721 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1722 | #define DECLARE_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1723 | private: \ |
| 1724 | H##type& operator=(const H##type&) = delete; \ |
| 1725 | public: \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1726 | const char* DebugName() const override { return #type; } \ |
| 1727 | HInstruction* Clone(ArenaAllocator* arena) const override { \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1728 | DCHECK(IsClonable()); \ |
Vladimir Marko | 5150dbe | 2023-04-26 09:13:59 +0000 | [diff] [blame] | 1729 | return new (arena) H##type(*this); \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1730 | } \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1731 | void Accept(HGraphVisitor* visitor) override |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1732 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1733 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1734 | private: \ |
| 1735 | H##type& operator=(const H##type&) = delete; \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 1736 | public: |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1737 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 1738 | #define DEFAULT_COPY_CONSTRUCTOR(type) H##type(const H##type& other) = default; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1739 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1740 | template <typename T> |
Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 1741 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode>, |
| 1742 | public IntrusiveForwardListNode<HUseListNode<T>> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1743 | public: |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1744 | // Get the instruction which has this use as one of the inputs. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1745 | T GetUser() const { return user_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1746 | // Get the position of the input record that this use corresponds to. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1747 | size_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1748 | // Set the position of the input record that this use corresponds to. |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1749 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1750 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1751 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1752 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1753 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1754 | |
| 1755 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1756 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1757 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1758 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1759 | |
| 1760 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1761 | }; |
| 1762 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1763 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1764 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1765 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1766 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1767 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1768 | // by the used instructions. |
| 1769 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1770 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1771 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1772 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1773 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1774 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1775 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1776 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1777 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1778 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1779 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1783 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1784 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1785 | |
| 1786 | private: |
| 1787 | // Instruction used by the user. |
| 1788 | HInstruction* instruction_; |
| 1789 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1790 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1791 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1792 | }; |
| 1793 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1794 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1795 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1796 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1797 | struct HInputExtractor { |
| 1798 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1799 | return record.GetInstruction(); |
| 1800 | } |
| 1801 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1802 | return record.GetInstruction(); |
| 1803 | } |
| 1804 | }; |
| 1805 | |
| 1806 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1807 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1808 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1809 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1810 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1811 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1812 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1813 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1814 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1815 | * modify the value of a reference field read [although it may modify the |
| 1816 | * reference fetch prior to reading the field, which is represented by its own |
| 1817 | * write/read dependence]). The analysis makes conservative points-to |
| 1818 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1819 | * the same, and any reference read depends on any reference read without |
| 1820 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1821 | * |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1822 | * kDependsOnGCBit is defined in the following way: instructions with kDependsOnGCBit must not be |
| 1823 | * alive across the point where garbage collection might happen. |
| 1824 | * |
| 1825 | * Note: Instructions with kCanTriggerGCBit do not depend on each other. |
| 1826 | * |
| 1827 | * kCanTriggerGCBit must be used for instructions for which GC might happen on the path across |
| 1828 | * those instructions from the compiler perspective (between this instruction and the next one |
| 1829 | * in the IR). |
| 1830 | * |
| 1831 | * Note: Instructions which can cause GC only on a fatal slow path do not need |
| 1832 | * kCanTriggerGCBit as the execution never returns to the instruction next to the exceptional |
| 1833 | * one. However the execution may return to compiled code if there is a catch block in the |
| 1834 | * current method; for this purpose the TryBoundary exit instruction has kCanTriggerGCBit |
| 1835 | * set. |
| 1836 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1837 | * The internal representation uses 38-bit and is described in the table below. |
| 1838 | * The first line indicates the side effect, and for field/array accesses the |
| 1839 | * 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] | 1840 | * DataType::Type enum). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1841 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1842 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1843 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1844 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1845 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1846 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1847 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1848 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1849 | * |
| 1850 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1851 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1852 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1853 | class SideEffects : public ValueObject { |
| 1854 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1855 | SideEffects() : flags_(0) {} |
| 1856 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1857 | static SideEffects None() { |
| 1858 | return SideEffects(0); |
| 1859 | } |
| 1860 | |
| 1861 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1862 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1863 | } |
| 1864 | |
| 1865 | static SideEffects AllChanges() { |
| 1866 | return SideEffects(kAllChangeBits); |
| 1867 | } |
| 1868 | |
| 1869 | static SideEffects AllDependencies() { |
| 1870 | return SideEffects(kAllDependOnBits); |
| 1871 | } |
| 1872 | |
| 1873 | static SideEffects AllExceptGCDependency() { |
| 1874 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1875 | } |
| 1876 | |
| 1877 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1878 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1879 | } |
| 1880 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1881 | static SideEffects AllWrites() { |
| 1882 | return SideEffects(kAllWrites); |
| 1883 | } |
| 1884 | |
| 1885 | static SideEffects AllReads() { |
| 1886 | return SideEffects(kAllReads); |
| 1887 | } |
| 1888 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1889 | static SideEffects FieldWriteOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1890 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1891 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1892 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1893 | } |
| 1894 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1895 | static SideEffects ArrayWriteOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1896 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1897 | } |
| 1898 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1899 | static SideEffects FieldReadOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1900 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1901 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1902 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1905 | static SideEffects ArrayReadOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1906 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1909 | // Returns whether GC might happen across this instruction from the compiler perspective so |
| 1910 | // the next instruction in the IR would see that. |
| 1911 | // |
| 1912 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1913 | static SideEffects CanTriggerGC() { |
| 1914 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1915 | } |
| 1916 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1917 | // Returns whether the instruction must not be alive across a GC point. |
| 1918 | // |
| 1919 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1920 | static SideEffects DependsOnGC() { |
| 1921 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1922 | } |
| 1923 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1924 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1925 | SideEffects Union(SideEffects other) const { |
| 1926 | return SideEffects(flags_ | other.flags_); |
| 1927 | } |
| 1928 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1929 | SideEffects Exclusion(SideEffects other) const { |
| 1930 | return SideEffects(flags_ & ~other.flags_); |
| 1931 | } |
| 1932 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1933 | void Add(SideEffects other) { |
| 1934 | flags_ |= other.flags_; |
| 1935 | } |
| 1936 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1937 | bool Includes(SideEffects other) const { |
| 1938 | return (other.flags_ & flags_) == other.flags_; |
| 1939 | } |
| 1940 | |
| 1941 | bool HasSideEffects() const { |
| 1942 | return (flags_ & kAllChangeBits); |
| 1943 | } |
| 1944 | |
| 1945 | bool HasDependencies() const { |
| 1946 | return (flags_ & kAllDependOnBits); |
| 1947 | } |
| 1948 | |
| 1949 | // Returns true if there are no side effects or dependencies. |
| 1950 | bool DoesNothing() const { |
| 1951 | return flags_ == 0; |
| 1952 | } |
| 1953 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1954 | // Returns true if something is written. |
| 1955 | bool DoesAnyWrite() const { |
| 1956 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1957 | } |
| 1958 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1959 | // Returns true if something is read. |
| 1960 | bool DoesAnyRead() const { |
| 1961 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1962 | } |
| 1963 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1964 | // Returns true if potentially everything is written and read |
| 1965 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1966 | bool DoesAllReadWrite() const { |
| 1967 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1968 | } |
| 1969 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1970 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1971 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1974 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1975 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1976 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1977 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1981 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1982 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1983 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1984 | for (int s = kLastBit; s >= 0; s--) { |
| 1985 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1986 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1987 | // This is a bit for the GC side effect. |
| 1988 | if (current_bit_is_set) { |
| 1989 | flags += "GC"; |
| 1990 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1991 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1992 | } else { |
| 1993 | // This is a bit for the array/field analysis. |
| 1994 | // The underscore character stands for the 'can trigger GC' bit. |
| 1995 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1996 | if (current_bit_is_set) { |
| 1997 | flags += kDebug[s]; |
| 1998 | } |
| 1999 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 2000 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 2001 | flags += "|"; |
| 2002 | } |
| 2003 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2004 | } |
| 2005 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2006 | } |
| 2007 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2008 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2009 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2010 | private: |
| 2011 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 2012 | |
| 2013 | static constexpr int kFieldWriteOffset = 0; |
| 2014 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 2015 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 2016 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 2017 | |
| 2018 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 2019 | |
| 2020 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 2021 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 2022 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 2023 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 2024 | |
| 2025 | static constexpr int kLastBit = kDependsOnGCBit; |
| 2026 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 2027 | |
| 2028 | // Aliases. |
| 2029 | |
| 2030 | static_assert(kChangeBits == kDependOnBits, |
| 2031 | "the 'change' bits should match the 'depend on' bits."); |
| 2032 | |
| 2033 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 2034 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 2035 | static constexpr uint64_t kAllWrites = |
| 2036 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 2037 | static constexpr uint64_t kAllReads = |
| 2038 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2039 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2040 | // 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] | 2041 | static uint64_t TypeFlag(DataType::Type type, int offset) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2042 | int shift; |
| 2043 | switch (type) { |
| 2044 | case DataType::Type::kReference: shift = 0; break; |
| 2045 | case DataType::Type::kBool: shift = 1; break; |
| 2046 | case DataType::Type::kInt8: shift = 2; break; |
| 2047 | case DataType::Type::kUint16: shift = 3; break; |
| 2048 | case DataType::Type::kInt16: shift = 4; break; |
| 2049 | case DataType::Type::kInt32: shift = 5; break; |
| 2050 | case DataType::Type::kInt64: shift = 6; break; |
| 2051 | case DataType::Type::kFloat32: shift = 7; break; |
| 2052 | case DataType::Type::kFloat64: shift = 8; break; |
| 2053 | default: |
| 2054 | LOG(FATAL) << "Unexpected data type " << type; |
| 2055 | UNREACHABLE(); |
| 2056 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2057 | DCHECK_LE(kFieldWriteOffset, shift); |
| 2058 | DCHECK_LT(shift, kArrayWriteOffset); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2059 | return UINT64_C(1) << (shift + offset); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | // Private constructor on direct flags value. |
| 2063 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 2064 | |
| 2065 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2066 | }; |
| 2067 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2068 | // 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] | 2069 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2070 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2071 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 2072 | size_t number_of_vregs, |
| 2073 | ArtMethod* method, |
| 2074 | uint32_t dex_pc, |
| 2075 | HInstruction* holder) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2076 | : vregs_(number_of_vregs, allocator->Adapter(kArenaAllocEnvironmentVRegs)), |
| 2077 | locations_(allocator->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2078 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2079 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2080 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2081 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2082 | } |
| 2083 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2084 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
| 2085 | const HEnvironment& to_copy, |
| 2086 | HInstruction* holder) |
| 2087 | : HEnvironment(allocator, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2088 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2089 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2090 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2091 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2092 | |
Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 2093 | void AllocateLocations() { |
| 2094 | DCHECK(locations_.empty()); |
| 2095 | locations_.resize(vregs_.size()); |
| 2096 | } |
| 2097 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2098 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2099 | if (parent_ != nullptr) { |
| 2100 | parent_->SetAndCopyParentChain(allocator, parent); |
| 2101 | } else { |
| 2102 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 2103 | parent_->CopyFrom(parent); |
| 2104 | if (parent->GetParent() != nullptr) { |
| 2105 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 2106 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2107 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 2110 | void CopyFrom(ArrayRef<HInstruction* const> locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 2111 | void CopyFrom(HEnvironment* environment); |
| 2112 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2113 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 2114 | // input to the loop phi instead. This is for inserting instructions that |
| 2115 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 2116 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2117 | |
| 2118 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2119 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2123 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2126 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2127 | |
Artem Serov | ca210e3 | 2017-12-15 13:43:20 +0000 | [diff] [blame] | 2128 | // Replaces the input at the position 'index' with the replacement; the replacement and old |
| 2129 | // input instructions' env_uses_ lists are adjusted. The function works similar to |
| 2130 | // HInstruction::ReplaceInput. |
| 2131 | void ReplaceInput(HInstruction* replacement, size_t index); |
| 2132 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2133 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2134 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2135 | HEnvironment* GetParent() const { return parent_; } |
| 2136 | |
| 2137 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2138 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2142 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | uint32_t GetDexPc() const { |
| 2146 | return dex_pc_; |
| 2147 | } |
| 2148 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2149 | ArtMethod* GetMethod() const { |
| 2150 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2151 | } |
| 2152 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2153 | HInstruction* GetHolder() const { |
| 2154 | return holder_; |
| 2155 | } |
| 2156 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 2157 | |
| 2158 | bool IsFromInlinedInvoke() const { |
| 2159 | return GetParent() != nullptr; |
| 2160 | } |
| 2161 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2162 | class EnvInputSelector { |
| 2163 | public: |
| 2164 | explicit EnvInputSelector(const HEnvironment* e) : env_(e) {} |
| 2165 | HInstruction* operator()(size_t s) const { |
| 2166 | return env_->GetInstructionAt(s); |
| 2167 | } |
| 2168 | private: |
| 2169 | const HEnvironment* env_; |
| 2170 | }; |
| 2171 | |
| 2172 | using HConstEnvInputRef = TransformIterator<CountIter, EnvInputSelector>; |
| 2173 | IterationRange<HConstEnvInputRef> GetEnvInputs() const { |
| 2174 | IterationRange<CountIter> range(Range(Size())); |
| 2175 | return MakeIterationRange(MakeTransformIterator(range.begin(), EnvInputSelector(this)), |
| 2176 | MakeTransformIterator(range.end(), EnvInputSelector(this))); |
| 2177 | } |
| 2178 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2179 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2180 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 2181 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2182 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2183 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2184 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2185 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 2186 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2187 | HInstruction* const holder_; |
| 2188 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 2189 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2190 | |
| 2191 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 2192 | }; |
| 2193 | |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 2194 | std::ostream& operator<<(std::ostream& os, const HInstruction& rhs); |
| 2195 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2196 | // Iterates over the Environments |
| 2197 | class HEnvironmentIterator : public ValueObject, |
| 2198 | public std::iterator<std::forward_iterator_tag, HEnvironment*> { |
| 2199 | public: |
| 2200 | explicit HEnvironmentIterator(HEnvironment* cur) : cur_(cur) {} |
| 2201 | |
| 2202 | HEnvironment* operator*() const { |
| 2203 | return cur_; |
| 2204 | } |
| 2205 | |
| 2206 | HEnvironmentIterator& operator++() { |
| 2207 | DCHECK(cur_ != nullptr); |
| 2208 | cur_ = cur_->GetParent(); |
| 2209 | return *this; |
| 2210 | } |
| 2211 | |
| 2212 | HEnvironmentIterator operator++(int) { |
| 2213 | HEnvironmentIterator prev(*this); |
| 2214 | ++(*this); |
| 2215 | return prev; |
| 2216 | } |
| 2217 | |
| 2218 | bool operator==(const HEnvironmentIterator& other) const { |
| 2219 | return other.cur_ == cur_; |
| 2220 | } |
| 2221 | |
| 2222 | bool operator!=(const HEnvironmentIterator& other) const { |
| 2223 | return !(*this == other); |
| 2224 | } |
| 2225 | |
| 2226 | private: |
| 2227 | HEnvironment* cur_; |
| 2228 | }; |
| 2229 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2230 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2231 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2232 | #define DECLARE_KIND(type, super) k##type, |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 2233 | enum InstructionKind { // private marker to avoid generate-operator-out.py from processing. |
Vladimir Marko | e394622 | 2018-05-04 14:18:47 +0100 | [diff] [blame] | 2234 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_KIND) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2235 | kLastInstructionKind |
| 2236 | }; |
| 2237 | #undef DECLARE_KIND |
| 2238 | |
| 2239 | HInstruction(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2240 | : HInstruction(kind, DataType::Type::kVoid, side_effects, dex_pc) {} |
| 2241 | |
| 2242 | 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] | 2243 | : previous_(nullptr), |
| 2244 | next_(nullptr), |
| 2245 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2246 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2247 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2248 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2249 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2250 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2251 | locations_(nullptr), |
| 2252 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2253 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 2254 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2255 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2256 | SetPackedField<InstructionKindField>(kind); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2257 | SetPackedField<TypeField>(type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2258 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 2259 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2260 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2261 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2262 | |
Vladimir Marko | c9fcfd0 | 2021-01-05 16:57:30 +0000 | [diff] [blame] | 2263 | std::ostream& Dump(std::ostream& os, bool dump_args = false); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2264 | |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 2265 | // Helper for dumping without argument information using operator<< |
| 2266 | struct NoArgsDump { |
| 2267 | const HInstruction* ins; |
| 2268 | }; |
| 2269 | NoArgsDump DumpWithoutArgs() const { |
| 2270 | return NoArgsDump{this}; |
| 2271 | } |
| 2272 | // Helper for dumping with argument information using operator<< |
| 2273 | struct ArgsDump { |
| 2274 | const HInstruction* ins; |
| 2275 | }; |
| 2276 | ArgsDump DumpWithArgs() const { |
| 2277 | return ArgsDump{this}; |
| 2278 | } |
| 2279 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2280 | HInstruction* GetNext() const { return next_; } |
| 2281 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2282 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2283 | HInstruction* GetNextDisregardingMoves() const; |
| 2284 | HInstruction* GetPreviousDisregardingMoves() const; |
| 2285 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2286 | HBasicBlock* GetBlock() const { return block_; } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2287 | ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2288 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 2289 | bool IsInBlock() const { return block_ != nullptr; } |
| 2290 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 2291 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 2292 | bool IsIrreducibleLoopHeaderPhi() const { |
| 2293 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 2294 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2295 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2296 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 2297 | |
| 2298 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 2299 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 2300 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 2301 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 2302 | } |
| 2303 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2304 | HInputsRef GetInputs() { |
| 2305 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2306 | } |
| 2307 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2308 | HConstInputsRef GetInputs() const { |
| 2309 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2313 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2314 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 2315 | bool HasInput(HInstruction* input) const { |
| 2316 | for (const HInstruction* i : GetInputs()) { |
| 2317 | if (i == input) { |
| 2318 | return true; |
| 2319 | } |
| 2320 | } |
| 2321 | return false; |
| 2322 | } |
| 2323 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2324 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 2325 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 2326 | } |
| 2327 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2328 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 2329 | virtual const char* DebugName() const = 0; |
| 2330 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2331 | DataType::Type GetType() const { |
| 2332 | return TypeField::Decode(GetPackedFields()); |
| 2333 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2334 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2335 | virtual bool NeedsEnvironment() const { return false; } |
Santiago Aboy Solanes | e43aa3f | 2021-11-01 09:02:09 +0000 | [diff] [blame] | 2336 | virtual bool NeedsBss() const { |
| 2337 | return false; |
| 2338 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2339 | |
| 2340 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2341 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2342 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2343 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2344 | // Can the instruction throw? |
| 2345 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 2346 | // 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] | 2347 | virtual bool CanThrow() const { return false; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2348 | |
| 2349 | // Does the instruction always throw an exception unconditionally? |
| 2350 | virtual bool AlwaysThrows() const { return false; } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2351 | // Will this instruction only cause async exceptions if it causes any at all? |
| 2352 | virtual bool OnlyThrowsAsyncExceptions() const { |
| 2353 | return false; |
| 2354 | } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2355 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2356 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2357 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2358 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2359 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2360 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2361 | // Does not apply for all instructions, but having this at top level greatly |
| 2362 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 2363 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2364 | virtual bool CanBeNull() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2365 | DCHECK_EQ(GetType(), DataType::Type::kReference) << "CanBeNull only applies to reference types"; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2366 | return true; |
| 2367 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2368 | |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 2369 | virtual bool CanDoImplicitNullCheckOn([[maybe_unused]] HInstruction* obj) const { return false; } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2370 | |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 2371 | // If this instruction will do an implicit null check, return the `HNullCheck` associated |
| 2372 | // with it. Otherwise return null. |
| 2373 | HNullCheck* GetImplicitNullCheck() const { |
Vladimir Marko | ee1f126 | 2019-06-26 14:37:17 +0100 | [diff] [blame] | 2374 | // Go over previous non-move instructions that are emitted at use site. |
| 2375 | HInstruction* prev_not_move = GetPreviousDisregardingMoves(); |
| 2376 | while (prev_not_move != nullptr && prev_not_move->IsEmittedAtUseSite()) { |
| 2377 | if (prev_not_move->IsNullCheck()) { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 2378 | return prev_not_move->AsNullCheck(); |
Vladimir Marko | ee1f126 | 2019-06-26 14:37:17 +0100 | [diff] [blame] | 2379 | } |
| 2380 | prev_not_move = prev_not_move->GetPreviousDisregardingMoves(); |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 2381 | } |
| 2382 | return nullptr; |
| 2383 | } |
| 2384 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2385 | virtual bool IsActualObject() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2386 | return GetType() == DataType::Type::kReference; |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
Santiago Aboy Solanes | e05bc3e | 2023-02-20 14:26:23 +0000 | [diff] [blame] | 2389 | // Sets the ReferenceTypeInfo. The RTI must be valid. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 2390 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Santiago Aboy Solanes | e05bc3e | 2023-02-20 14:26:23 +0000 | [diff] [blame] | 2391 | // Same as above, but we only set it if it's valid. Otherwise, we don't change the current RTI. |
| 2392 | void SetReferenceTypeInfoIfValid(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2393 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2394 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2395 | DCHECK_EQ(GetType(), DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2396 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 2397 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2398 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2399 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2400 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2401 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2402 | // Note: fixup_end remains valid across push_front(). |
| 2403 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
Vladimir Marko | 3224f38 | 2020-06-23 14:19:53 +0100 | [diff] [blame] | 2404 | ArenaAllocator* allocator = user->GetBlock()->GetGraph()->GetAllocator(); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2405 | HUseListNode<HInstruction*>* new_node = |
Vladimir Marko | 3224f38 | 2020-06-23 14:19:53 +0100 | [diff] [blame] | 2406 | new (allocator) HUseListNode<HInstruction*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2407 | uses_.push_front(*new_node); |
| 2408 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2409 | } |
| 2410 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2411 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2412 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2413 | // Note: env_fixup_end remains valid across push_front(). |
| 2414 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2415 | HUseListNode<HEnvironment*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2416 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HEnvironment*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2417 | env_uses_.push_front(*new_node); |
| 2418 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2419 | } |
| 2420 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2421 | void RemoveAsUserOfInput(size_t input) { |
| 2422 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2423 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2424 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2425 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2426 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2427 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2428 | void RemoveAsUserOfAllInputs() { |
| 2429 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2430 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2431 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2432 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2433 | } |
| 2434 | } |
| 2435 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2436 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2437 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2438 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2439 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2440 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2441 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2442 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2443 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2444 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2445 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2446 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2447 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2448 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2449 | !CanThrow() && |
| 2450 | !IsSuspendCheck() && |
| 2451 | !IsControlFlow() && |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 2452 | !IsNop() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2453 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2454 | // If we added an explicit barrier then we should keep it. |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2455 | !IsMemoryBarrier() && |
| 2456 | !IsConstructorFence(); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2459 | bool IsDeadAndRemovable() const { |
| 2460 | return IsRemovable() && !HasUses(); |
| 2461 | } |
| 2462 | |
Santiago Aboy Solanes | 8c3b58a | 2022-08-15 13:21:59 +0000 | [diff] [blame] | 2463 | // Does this instruction dominate `other_instruction`? |
| 2464 | // Aborts if this instruction and `other_instruction` are different phis. |
| 2465 | bool Dominates(HInstruction* other_instruction) const; |
| 2466 | |
| 2467 | // Same but with `strictly dominates` i.e. returns false if this instruction and |
| 2468 | // `other_instruction` are the same. |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2469 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2470 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2471 | int GetId() const { return id_; } |
| 2472 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2473 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2474 | int GetSsaIndex() const { return ssa_index_; } |
| 2475 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2476 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2477 | |
| 2478 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2479 | HEnvironment* GetEnvironment() const { return environment_; } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2480 | IterationRange<HEnvironmentIterator> GetAllEnvironments() const { |
| 2481 | return MakeIterationRange(HEnvironmentIterator(GetEnvironment()), |
| 2482 | HEnvironmentIterator(nullptr)); |
| 2483 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2484 | // Set the `environment_` field. Raw because this method does not |
| 2485 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2486 | void SetRawEnvironment(HEnvironment* environment) { |
| 2487 | DCHECK(environment_ == nullptr); |
| 2488 | DCHECK_EQ(environment->GetHolder(), this); |
| 2489 | environment_ = environment; |
| 2490 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2491 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2492 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2493 | DCHECK(environment_ != nullptr); |
| 2494 | DCHECK_EQ(environment->GetHolder(), this); |
| 2495 | DCHECK(environment->GetParent() == nullptr); |
| 2496 | environment->parent_ = environment_; |
| 2497 | environment_ = environment; |
| 2498 | } |
| 2499 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2500 | void RemoveEnvironment(); |
| 2501 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2502 | // Set the environment of this instruction, copying it from `environment`. While |
| 2503 | // copying, the uses lists are being updated. |
| 2504 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2505 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2506 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2507 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2508 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2509 | if (environment->GetParent() != nullptr) { |
| 2510 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2511 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2512 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2513 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2514 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2515 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2516 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2517 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2518 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2519 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2520 | if (environment->GetParent() != nullptr) { |
| 2521 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2522 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2525 | // Returns the number of entries in the environment. Typically, that is the |
| 2526 | // number of dex registers in a method. It could be more in case of inlining. |
| 2527 | size_t EnvironmentSize() const; |
| 2528 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2529 | LocationSummary* GetLocations() const { return locations_; } |
| 2530 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2531 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2532 | void ReplaceWith(HInstruction* instruction); |
Santiago Aboy Solanes | 8c3b58a | 2022-08-15 13:21:59 +0000 | [diff] [blame] | 2533 | void ReplaceUsesDominatedBy(HInstruction* dominator, |
| 2534 | HInstruction* replacement, |
| 2535 | bool strictly_dominated = true); |
Nicolas Geoffray | 8a62a4c | 2018-07-03 09:39:07 +0100 | [diff] [blame] | 2536 | void ReplaceEnvUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2537 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2538 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2539 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2540 | // uses of this instruction by `other` are *not* updated. |
| 2541 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2542 | ReplaceWith(other); |
| 2543 | other->ReplaceInput(this, use_index); |
| 2544 | } |
| 2545 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2546 | // Move `this` instruction before `cursor` |
| 2547 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2548 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2549 | // Move `this` before its first user and out of any loops. If there is no |
| 2550 | // out-of-loop user that dominates all other users, move the instruction |
| 2551 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2552 | // |
| 2553 | // This can be used only on non-throwing instructions with no side effects that |
| 2554 | // have at least one use but no environment uses. |
| 2555 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2556 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2557 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2558 | bool Is##type() const; |
| 2559 | |
| 2560 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2561 | #undef INSTRUCTION_TYPE_CHECK |
| 2562 | |
| 2563 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 2564 | const H##type* As##type() const; \ |
| 2565 | H##type* As##type(); \ |
Vladimir Marko | 79dc217 | 2023-04-05 10:33:07 +0000 | [diff] [blame] | 2566 | const H##type* As##type##OrNull() const; \ |
| 2567 | H##type* As##type##OrNull(); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2568 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2569 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 2570 | #undef INSTRUCTION_TYPE_CAST |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2571 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2572 | // Return a clone of the instruction if it is clonable (shallow copy by default, custom copy |
| 2573 | // if a custom copy-constructor is provided for a particular type). If IsClonable() is false for |
| 2574 | // the instruction then the behaviour of this function is undefined. |
| 2575 | // |
| 2576 | // Note: It is semantically valid to create a clone of the instruction only until |
| 2577 | // prepare_for_register_allocator phase as lifetime, intervals and codegen info are not |
| 2578 | // copied. |
| 2579 | // |
| 2580 | // Note: HEnvironment and some other fields are not copied and are set to default values, see |
| 2581 | // 'explicit HInstruction(const HInstruction& other)' for details. |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 2582 | virtual HInstruction* Clone([[maybe_unused]] ArenaAllocator* arena) const { |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2583 | LOG(FATAL) << "Cloning is not implemented for the instruction " << |
| 2584 | DebugName() << " " << GetId(); |
| 2585 | UNREACHABLE(); |
| 2586 | } |
| 2587 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2588 | virtual bool IsFieldAccess() const { |
| 2589 | return false; |
| 2590 | } |
| 2591 | |
| 2592 | virtual const FieldInfo& GetFieldInfo() const { |
| 2593 | CHECK(IsFieldAccess()) << "Only callable on field accessors not " << DebugName() << " " |
| 2594 | << *this; |
| 2595 | LOG(FATAL) << "Must be overridden by field accessors. Not implemented by " << *this; |
| 2596 | UNREACHABLE(); |
| 2597 | } |
| 2598 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2599 | // Return whether instruction can be cloned (copied). |
| 2600 | virtual bool IsClonable() const { return false; } |
| 2601 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2602 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2603 | // TODO: this method is used by LICM and GVN with possibly different |
| 2604 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2605 | virtual bool CanBeMoved() const { return false; } |
| 2606 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2607 | // Returns whether any data encoded in the two instructions is equal. |
| 2608 | // This method does not look at the inputs. Both instructions must be |
| 2609 | // of the same type, otherwise the method has undefined behavior. |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 2610 | virtual bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2611 | return false; |
| 2612 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2613 | |
| 2614 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2615 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2616 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2617 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2618 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2619 | InstructionKind GetKind() const { return GetPackedField<InstructionKindField>(); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2620 | |
| 2621 | virtual size_t ComputeHashCode() const { |
| 2622 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2623 | for (const HInstruction* input : GetInputs()) { |
| 2624 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2625 | } |
| 2626 | return result; |
| 2627 | } |
| 2628 | |
| 2629 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2630 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2631 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2632 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2633 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2634 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2635 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2636 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2637 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2638 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2639 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2640 | |
| 2641 | // Returns whether the code generation of the instruction will require to have access |
| 2642 | // to the current method. Such instructions are: |
| 2643 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2644 | // 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] | 2645 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2646 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2647 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2648 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2651 | // Does this instruction have any use in an environment before |
| 2652 | // control flow hits 'other'? |
| 2653 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2654 | |
| 2655 | // Remove all references to environment uses of this instruction. |
| 2656 | // The caller must ensure that this is safe to do. |
| 2657 | void RemoveEnvironmentUsers(); |
| 2658 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2659 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2660 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2661 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2662 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2663 | // If set, the machine code for this instruction is assumed to be generated by |
| 2664 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2665 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2666 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2667 | static constexpr size_t kFieldInstructionKind = kFlagReferenceTypeIsExact + 1; |
| 2668 | static constexpr size_t kFieldInstructionKindSize = |
| 2669 | MinimumBitsToStore(static_cast<size_t>(InstructionKind::kLastInstructionKind - 1)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2670 | static constexpr size_t kFieldType = |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2671 | kFieldInstructionKind + kFieldInstructionKindSize; |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2672 | static constexpr size_t kFieldTypeSize = |
| 2673 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
| 2674 | static constexpr size_t kNumberOfGenericPackedBits = kFieldType + kFieldTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2675 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2676 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2677 | static_assert(kNumberOfGenericPackedBits <= kMaxNumberOfPackedBits, |
| 2678 | "Too many generic packed fields"); |
| 2679 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2680 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
| 2681 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2682 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2683 | return GetInputRecords()[i]; |
| 2684 | } |
| 2685 | |
| 2686 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2687 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2688 | input_records[index] = input; |
| 2689 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2690 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2691 | uint32_t GetPackedFields() const { |
| 2692 | return packed_fields_; |
| 2693 | } |
| 2694 | |
| 2695 | template <size_t flag> |
| 2696 | bool GetPackedFlag() const { |
| 2697 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2698 | } |
| 2699 | |
| 2700 | template <size_t flag> |
| 2701 | void SetPackedFlag(bool value = true) { |
| 2702 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2703 | } |
| 2704 | |
| 2705 | template <typename BitFieldType> |
| 2706 | typename BitFieldType::value_type GetPackedField() const { |
| 2707 | return BitFieldType::Decode(packed_fields_); |
| 2708 | } |
| 2709 | |
| 2710 | template <typename BitFieldType> |
| 2711 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2712 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2713 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2714 | } |
| 2715 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2716 | // Copy construction for the instruction (used for Clone function). |
| 2717 | // |
| 2718 | // Fields (e.g. lifetime, intervals and codegen info) associated with phases starting from |
| 2719 | // prepare_for_register_allocator are not copied (set to default values). |
| 2720 | // |
| 2721 | // Copy constructors must be provided for every HInstruction type; default copy constructor is |
| 2722 | // fine for most of them. However for some of the instructions a custom copy constructor must be |
| 2723 | // specified (when instruction has non-trivially copyable fields and must have a special behaviour |
| 2724 | // for copying them). |
| 2725 | explicit HInstruction(const HInstruction& other) |
| 2726 | : previous_(nullptr), |
| 2727 | next_(nullptr), |
| 2728 | block_(nullptr), |
| 2729 | dex_pc_(other.dex_pc_), |
| 2730 | id_(-1), |
| 2731 | ssa_index_(-1), |
| 2732 | packed_fields_(other.packed_fields_), |
| 2733 | environment_(nullptr), |
| 2734 | locations_(nullptr), |
| 2735 | live_interval_(nullptr), |
| 2736 | lifetime_position_(kNoLifetime), |
| 2737 | side_effects_(other.side_effects_), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2738 | reference_type_handle_(other.reference_type_handle_) { |
| 2739 | } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2740 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2741 | private: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2742 | using InstructionKindField = |
| 2743 | BitField<InstructionKind, kFieldInstructionKind, kFieldInstructionKindSize>; |
| 2744 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2745 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2746 | auto before_use_node = uses_.before_begin(); |
| 2747 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2748 | HInstruction* user = use_node->GetUser(); |
| 2749 | size_t input_index = use_node->GetIndex(); |
| 2750 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2751 | before_use_node = use_node; |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2756 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2757 | if (next != uses_.end()) { |
| 2758 | HInstruction* next_user = next->GetUser(); |
| 2759 | size_t next_index = next->GetIndex(); |
| 2760 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2761 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2762 | } |
| 2763 | } |
| 2764 | |
| 2765 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2766 | auto before_env_use_node = env_uses_.before_begin(); |
| 2767 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2768 | HEnvironment* user = env_use_node->GetUser(); |
| 2769 | size_t input_index = env_use_node->GetIndex(); |
| 2770 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2771 | before_env_use_node = env_use_node; |
| 2772 | } |
| 2773 | } |
| 2774 | |
| 2775 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2776 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2777 | if (next != env_uses_.end()) { |
| 2778 | HEnvironment* next_user = next->GetUser(); |
| 2779 | size_t next_index = next->GetIndex(); |
| 2780 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2781 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2782 | } |
| 2783 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2784 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2785 | HInstruction* previous_; |
| 2786 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2787 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2788 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2789 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2790 | // An instruction gets an id when it is added to the graph. |
| 2791 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2792 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2793 | int id_; |
| 2794 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2795 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2796 | int ssa_index_; |
| 2797 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2798 | // Packed fields. |
| 2799 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2800 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2801 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2802 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2803 | |
| 2804 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2805 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2806 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2807 | // The environment associated with this instruction. Not null if the instruction |
| 2808 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2809 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2810 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2811 | // Set by the code generator. |
| 2812 | LocationSummary* locations_; |
| 2813 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2814 | // Set by the liveness analysis. |
| 2815 | LiveInterval* live_interval_; |
| 2816 | |
| 2817 | // Set by the liveness analysis, this is the position in a linear |
| 2818 | // order of blocks where this instruction's live interval start. |
| 2819 | size_t lifetime_position_; |
| 2820 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2821 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2822 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2823 | // The reference handle part of the reference type info. |
| 2824 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2825 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2826 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2827 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2828 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2829 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2830 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2831 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2832 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2833 | }; |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2834 | |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 2835 | std::ostream& operator<<(std::ostream& os, HInstruction::InstructionKind rhs); |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 2836 | std::ostream& operator<<(std::ostream& os, const HInstruction::NoArgsDump rhs); |
| 2837 | std::ostream& operator<<(std::ostream& os, const HInstruction::ArgsDump rhs); |
| 2838 | std::ostream& operator<<(std::ostream& os, const HUseList<HInstruction*>& lst); |
| 2839 | std::ostream& operator<<(std::ostream& os, const HUseList<HEnvironment*>& lst); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2840 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2841 | // Forward declarations for friends |
| 2842 | template <typename InnerIter> struct HSTLInstructionIterator; |
| 2843 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2844 | // Iterates over the instructions, while preserving the next instruction |
| 2845 | // in case the current instruction gets removed from the list by the user |
| 2846 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2847 | class HInstructionIterator : public ValueObject { |
| 2848 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2849 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2850 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2851 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2852 | } |
| 2853 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2854 | bool Done() const { return instruction_ == nullptr; } |
| 2855 | HInstruction* Current() const { return instruction_; } |
| 2856 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2857 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2858 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | private: |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2862 | HInstructionIterator() : instruction_(nullptr), next_(nullptr) {} |
| 2863 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2864 | HInstruction* instruction_; |
| 2865 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2866 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2867 | friend struct HSTLInstructionIterator<HInstructionIterator>; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2868 | }; |
| 2869 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2870 | // Iterates over the instructions without saving the next instruction, |
| 2871 | // therefore handling changes in the graph potentially made by the user |
| 2872 | // of this iterator. |
| 2873 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2874 | public: |
| 2875 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2876 | : instruction_(instructions.first_instruction_) { |
| 2877 | } |
| 2878 | |
| 2879 | bool Done() const { return instruction_ == nullptr; } |
| 2880 | HInstruction* Current() const { return instruction_; } |
| 2881 | void Advance() { |
| 2882 | instruction_ = instruction_->GetNext(); |
| 2883 | } |
| 2884 | |
| 2885 | private: |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2886 | HInstructionIteratorHandleChanges() : instruction_(nullptr) {} |
| 2887 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2888 | HInstruction* instruction_; |
| 2889 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2890 | friend struct HSTLInstructionIterator<HInstructionIteratorHandleChanges>; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2891 | }; |
| 2892 | |
| 2893 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2894 | class HBackwardInstructionIterator : public ValueObject { |
| 2895 | public: |
| 2896 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2897 | : instruction_(instructions.last_instruction_) { |
| 2898 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2899 | } |
| 2900 | |
| 2901 | bool Done() const { return instruction_ == nullptr; } |
| 2902 | HInstruction* Current() const { return instruction_; } |
| 2903 | void Advance() { |
| 2904 | instruction_ = next_; |
| 2905 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2906 | } |
| 2907 | |
| 2908 | private: |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2909 | HBackwardInstructionIterator() : instruction_(nullptr), next_(nullptr) {} |
| 2910 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2911 | HInstruction* instruction_; |
| 2912 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2913 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2914 | friend struct HSTLInstructionIterator<HBackwardInstructionIterator>; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2915 | }; |
| 2916 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2917 | template <typename InnerIter> |
| 2918 | struct HSTLInstructionIterator : public ValueObject, |
| 2919 | public std::iterator<std::forward_iterator_tag, HInstruction*> { |
| 2920 | public: |
| 2921 | static_assert(std::is_same_v<InnerIter, HBackwardInstructionIterator> || |
| 2922 | std::is_same_v<InnerIter, HInstructionIterator> || |
| 2923 | std::is_same_v<InnerIter, HInstructionIteratorHandleChanges>, |
| 2924 | "Unknown wrapped iterator!"); |
| 2925 | |
| 2926 | explicit HSTLInstructionIterator(InnerIter inner) : inner_(inner) {} |
| 2927 | HInstruction* operator*() const { |
| 2928 | DCHECK(inner_.Current() != nullptr); |
| 2929 | return inner_.Current(); |
| 2930 | } |
| 2931 | |
| 2932 | HSTLInstructionIterator<InnerIter>& operator++() { |
| 2933 | DCHECK(*this != HSTLInstructionIterator<InnerIter>::EndIter()); |
| 2934 | inner_.Advance(); |
| 2935 | return *this; |
| 2936 | } |
| 2937 | |
| 2938 | HSTLInstructionIterator<InnerIter> operator++(int) { |
| 2939 | HSTLInstructionIterator<InnerIter> prev(*this); |
| 2940 | ++(*this); |
| 2941 | return prev; |
| 2942 | } |
| 2943 | |
| 2944 | bool operator==(const HSTLInstructionIterator<InnerIter>& other) const { |
| 2945 | return inner_.Current() == other.inner_.Current(); |
| 2946 | } |
| 2947 | |
| 2948 | bool operator!=(const HSTLInstructionIterator<InnerIter>& other) const { |
| 2949 | return !(*this == other); |
| 2950 | } |
| 2951 | |
| 2952 | static HSTLInstructionIterator<InnerIter> EndIter() { |
| 2953 | return HSTLInstructionIterator<InnerIter>(InnerIter()); |
| 2954 | } |
| 2955 | |
| 2956 | private: |
| 2957 | InnerIter inner_; |
| 2958 | }; |
| 2959 | |
| 2960 | template <typename InnerIter> |
| 2961 | IterationRange<HSTLInstructionIterator<InnerIter>> MakeSTLInstructionIteratorRange(InnerIter iter) { |
| 2962 | return MakeIterationRange(HSTLInstructionIterator<InnerIter>(iter), |
| 2963 | HSTLInstructionIterator<InnerIter>::EndIter()); |
| 2964 | } |
| 2965 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2966 | class HVariableInputSizeInstruction : public HInstruction { |
| 2967 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2968 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2969 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2970 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2971 | } |
| 2972 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2973 | void AddInput(HInstruction* input); |
| 2974 | void InsertInputAt(size_t index, HInstruction* input); |
| 2975 | void RemoveInputAt(size_t index); |
| 2976 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2977 | // Removes all the inputs. |
| 2978 | // Also removes this instructions from each input's use list |
| 2979 | // (for non-environment uses only). |
| 2980 | void RemoveAllInputs(); |
| 2981 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2982 | protected: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2983 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2984 | SideEffects side_effects, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2985 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2986 | ArenaAllocator* allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2987 | size_t number_of_inputs, |
| 2988 | ArenaAllocKind kind) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2989 | : HInstruction(inst_kind, side_effects, dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2990 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2991 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2992 | DataType::Type type, |
| 2993 | SideEffects side_effects, |
| 2994 | uint32_t dex_pc, |
| 2995 | ArenaAllocator* allocator, |
| 2996 | size_t number_of_inputs, |
| 2997 | ArenaAllocKind kind) |
| 2998 | : HInstruction(inst_kind, type, side_effects, dex_pc), |
| 2999 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3000 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3001 | DEFAULT_COPY_CONSTRUCTOR(VariableInputSizeInstruction); |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3002 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3003 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3004 | }; |
| 3005 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 3006 | template<size_t N> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3007 | class HExpression : public HInstruction { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3008 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3009 | HExpression<N>(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3010 | : HInstruction(kind, side_effects, dex_pc), inputs_() {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3011 | HExpression<N>(InstructionKind kind, |
| 3012 | DataType::Type type, |
| 3013 | SideEffects side_effects, |
| 3014 | uint32_t dex_pc) |
| 3015 | : HInstruction(kind, type, side_effects, dex_pc), inputs_() {} |
| 3016 | virtual ~HExpression() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3017 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3018 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 3019 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3020 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3021 | } |
| 3022 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3023 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3024 | DEFAULT_COPY_CONSTRUCTOR(Expression<N>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3025 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3026 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 3027 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3028 | |
| 3029 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3030 | }; |
| 3031 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3032 | // HExpression specialization for N=0. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 3033 | template<> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3034 | class HExpression<0> : public HInstruction { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 3035 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3036 | using HInstruction::HInstruction; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3037 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3038 | virtual ~HExpression() {} |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 3039 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3040 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 3041 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3042 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 3043 | } |
| 3044 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3045 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3046 | DEFAULT_COPY_CONSTRUCTOR(Expression<0>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3047 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 3048 | private: |
| 3049 | friend class SsaBuilder; |
| 3050 | }; |
| 3051 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 3052 | class HMethodEntryHook : public HExpression<0> { |
| 3053 | public: |
| 3054 | explicit HMethodEntryHook(uint32_t dex_pc) |
| 3055 | : HExpression(kMethodEntryHook, SideEffects::All(), dex_pc) {} |
| 3056 | |
| 3057 | bool NeedsEnvironment() const override { |
| 3058 | return true; |
| 3059 | } |
| 3060 | |
Mythri Alle | 9c970b9 | 2021-12-02 15:26:31 +0000 | [diff] [blame] | 3061 | bool CanThrow() const override { return true; } |
| 3062 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 3063 | DECLARE_INSTRUCTION(MethodEntryHook); |
| 3064 | |
| 3065 | protected: |
| 3066 | DEFAULT_COPY_CONSTRUCTOR(MethodEntryHook); |
| 3067 | }; |
| 3068 | |
| 3069 | class HMethodExitHook : public HExpression<1> { |
| 3070 | public: |
| 3071 | HMethodExitHook(HInstruction* value, uint32_t dex_pc) |
| 3072 | : HExpression(kMethodExitHook, SideEffects::All(), dex_pc) { |
| 3073 | SetRawInputAt(0, value); |
| 3074 | } |
| 3075 | |
| 3076 | bool NeedsEnvironment() const override { |
| 3077 | return true; |
| 3078 | } |
| 3079 | |
Mythri Alle | 9c970b9 | 2021-12-02 15:26:31 +0000 | [diff] [blame] | 3080 | bool CanThrow() const override { return true; } |
| 3081 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 3082 | DECLARE_INSTRUCTION(MethodExitHook); |
| 3083 | |
| 3084 | protected: |
| 3085 | DEFAULT_COPY_CONSTRUCTOR(MethodExitHook); |
| 3086 | }; |
| 3087 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3088 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 3089 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3090 | class HReturnVoid final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3091 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3092 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3093 | : HExpression(kReturnVoid, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3094 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 3095 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3096 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3097 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3098 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3099 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3100 | protected: |
| 3101 | DEFAULT_COPY_CONSTRUCTOR(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3102 | }; |
| 3103 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3104 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 3105 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3106 | class HReturn final : public HExpression<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3107 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3108 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3109 | : HExpression(kReturn, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3110 | SetRawInputAt(0, value); |
| 3111 | } |
| 3112 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3113 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 3114 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3115 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3116 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3117 | protected: |
| 3118 | DEFAULT_COPY_CONSTRUCTOR(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3119 | }; |
| 3120 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3121 | class HPhi final : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3122 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3123 | HPhi(ArenaAllocator* allocator, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3124 | uint32_t reg_number, |
| 3125 | size_t number_of_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3126 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3127 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3128 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3129 | kPhi, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3130 | ToPhiType(type), |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3131 | SideEffects::None(), |
| 3132 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3133 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3134 | number_of_inputs, |
| 3135 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3136 | reg_number_(reg_number) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3137 | DCHECK_NE(GetType(), DataType::Type::kVoid); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3138 | // Phis are constructed live and marked dead if conflicting or unused. |
| 3139 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 3140 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 3141 | SetPackedFlag<kFlagIsLive>(true); |
| 3142 | SetPackedFlag<kFlagCanBeNull>(true); |
| 3143 | } |
| 3144 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3145 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3146 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3147 | // 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] | 3148 | static DataType::Type ToPhiType(DataType::Type type) { |
| 3149 | return DataType::Kind(type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 3153 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3154 | void SetType(DataType::Type new_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3155 | // Make sure that only valid type changes occur. The following are allowed: |
| 3156 | // (1) int -> float/ref (primitive type propagation), |
| 3157 | // (2) long -> double (primitive type propagation). |
| 3158 | DCHECK(GetType() == new_type || |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3159 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kFloat32) || |
| 3160 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kReference) || |
| 3161 | (GetType() == DataType::Type::kInt64 && new_type == DataType::Type::kFloat64)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3162 | SetPackedField<TypeField>(new_type); |
| 3163 | } |
| 3164 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3165 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3166 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 3167 | |
| 3168 | uint32_t GetRegNumber() const { return reg_number_; } |
| 3169 | |
| 3170 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 3171 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 3172 | bool IsDead() const { return !IsLive(); } |
| 3173 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 3174 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 3175 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3176 | return other != nullptr |
| 3177 | && other->IsPhi() |
Vladimir Marko | 5150dbe | 2023-04-26 09:13:59 +0000 | [diff] [blame] | 3178 | && other->GetBlock() == GetBlock() |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 3179 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3180 | } |
| 3181 | |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 3182 | bool HasEquivalentPhi() const { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 3183 | if (GetPrevious() != nullptr && GetPrevious()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 3184 | return true; |
| 3185 | } |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 3186 | if (GetNext() != nullptr && GetNext()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 3187 | return true; |
| 3188 | } |
| 3189 | return false; |
| 3190 | } |
| 3191 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3192 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 3193 | // An equivalent phi is a phi having the same dex register and type. |
| 3194 | // It assumes that phis with the same dex register are adjacent. |
| 3195 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 3196 | HInstruction* next = GetNext(); |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 3197 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3198 | if (next->GetType() == GetType()) { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 3199 | return next->AsPhi(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3200 | } |
| 3201 | next = next->GetNext(); |
| 3202 | } |
| 3203 | return nullptr; |
| 3204 | } |
| 3205 | |
| 3206 | DECLARE_INSTRUCTION(Phi); |
| 3207 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3208 | protected: |
| 3209 | DEFAULT_COPY_CONSTRUCTOR(Phi); |
| 3210 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3211 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3212 | static constexpr size_t kFlagIsLive = HInstruction::kNumberOfGenericPackedBits; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3213 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 3214 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 3215 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3216 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3217 | const uint32_t reg_number_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3218 | }; |
| 3219 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3220 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3221 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3222 | // exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3223 | class HExit final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3224 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3225 | explicit HExit(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3226 | : HExpression(kExit, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3227 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 3228 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3229 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3230 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3231 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3232 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3233 | protected: |
| 3234 | DEFAULT_COPY_CONSTRUCTOR(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3235 | }; |
| 3236 | |
| 3237 | // Jumps from one block to another. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3238 | class HGoto final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3239 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3240 | explicit HGoto(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3241 | : HExpression(kGoto, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3242 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3243 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3244 | bool IsClonable() const override { return true; } |
| 3245 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3246 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3247 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3248 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3251 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3252 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3253 | protected: |
| 3254 | DEFAULT_COPY_CONSTRUCTOR(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3255 | }; |
| 3256 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3257 | class HConstant : public HExpression<0> { |
| 3258 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3259 | explicit HConstant(InstructionKind kind, DataType::Type type, uint32_t dex_pc = kNoDexPc) |
| 3260 | : HExpression(kind, type, SideEffects::None(), dex_pc) { |
| 3261 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3262 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3263 | bool CanBeMoved() const override { return true; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3264 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3265 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3266 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3267 | // Is this constant 0 in the arithmetic sense? |
| 3268 | virtual bool IsArithmeticZero() const { return false; } |
| 3269 | // Is this constant a 0-bit pattern? |
| 3270 | virtual bool IsZeroBitPattern() const { return false; } |
| 3271 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3272 | virtual bool IsOne() const { return false; } |
| 3273 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3274 | virtual uint64_t GetValueAsUint64() const = 0; |
| 3275 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3276 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3277 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3278 | protected: |
| 3279 | DEFAULT_COPY_CONSTRUCTOR(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3280 | }; |
| 3281 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3282 | class HNullConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3283 | public: |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 3284 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3285 | return true; |
| 3286 | } |
| 3287 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3288 | uint64_t GetValueAsUint64() const override { return 0; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3289 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3290 | size_t ComputeHashCode() const override { return 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3291 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3292 | // The null constant representation is a 0-bit pattern. |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame] | 3293 | bool IsZeroBitPattern() const override { return true; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3294 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3295 | DECLARE_INSTRUCTION(NullConstant); |
| 3296 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3297 | protected: |
| 3298 | DEFAULT_COPY_CONSTRUCTOR(NullConstant); |
| 3299 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3300 | private: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3301 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3302 | : HConstant(kNullConstant, DataType::Type::kReference, dex_pc) { |
| 3303 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3304 | |
| 3305 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3306 | }; |
| 3307 | |
| 3308 | // Constants of the type int. Those can be from Dex instructions, or |
| 3309 | // synthesized (for example with the if-eqz instruction). |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3310 | class HIntConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3311 | public: |
| 3312 | int32_t GetValue() const { return value_; } |
| 3313 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3314 | uint64_t GetValueAsUint64() const override { |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 3315 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 3316 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3317 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3318 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3319 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 3320 | return other->AsIntConstant()->value_ == value_; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3321 | } |
| 3322 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3323 | size_t ComputeHashCode() const override { return GetValue(); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3324 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3325 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 3326 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 3327 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 3328 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3329 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3330 | // Integer constants are used to encode Boolean values as well, |
| 3331 | // where 1 means true and 0 means false. |
| 3332 | bool IsTrue() const { return GetValue() == 1; } |
| 3333 | bool IsFalse() const { return GetValue() == 0; } |
| 3334 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3335 | DECLARE_INSTRUCTION(IntConstant); |
| 3336 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3337 | protected: |
| 3338 | DEFAULT_COPY_CONSTRUCTOR(IntConstant); |
| 3339 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3340 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3341 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3342 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), value_(value) { |
| 3343 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3344 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3345 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), |
| 3346 | value_(value ? 1 : 0) { |
| 3347 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3348 | |
| 3349 | const int32_t value_; |
| 3350 | |
| 3351 | friend class HGraph; |
| 3352 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 3353 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3354 | }; |
| 3355 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3356 | class HLongConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3357 | public: |
| 3358 | int64_t GetValue() const { return value_; } |
| 3359 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3360 | uint64_t GetValueAsUint64() const override { return value_; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3361 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3362 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3363 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 3364 | return other->AsLongConstant()->value_ == value_; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3365 | } |
| 3366 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3367 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3368 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3369 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 3370 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 3371 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 3372 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3373 | |
| 3374 | DECLARE_INSTRUCTION(LongConstant); |
| 3375 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3376 | protected: |
| 3377 | DEFAULT_COPY_CONSTRUCTOR(LongConstant); |
| 3378 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3379 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3380 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3381 | : HConstant(kLongConstant, DataType::Type::kInt64, dex_pc), |
| 3382 | value_(value) { |
| 3383 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3384 | |
| 3385 | const int64_t value_; |
| 3386 | |
| 3387 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3388 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3389 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3390 | class HFloatConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3391 | public: |
| 3392 | float GetValue() const { return value_; } |
| 3393 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3394 | uint64_t GetValueAsUint64() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3395 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3396 | } |
| 3397 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3398 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3399 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 3400 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3401 | } |
| 3402 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3403 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3404 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3405 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3406 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 3407 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3408 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3409 | return std::fpclassify(value_) == FP_ZERO; |
| 3410 | } |
| 3411 | bool IsArithmeticPositiveZero() const { |
| 3412 | return IsArithmeticZero() && !std::signbit(value_); |
| 3413 | } |
| 3414 | bool IsArithmeticNegativeZero() const { |
| 3415 | return IsArithmeticZero() && std::signbit(value_); |
| 3416 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3417 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3418 | 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] | 3419 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3420 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3421 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3422 | } |
| 3423 | bool IsNaN() const { |
| 3424 | return std::isnan(value_); |
| 3425 | } |
| 3426 | |
| 3427 | DECLARE_INSTRUCTION(FloatConstant); |
| 3428 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3429 | protected: |
| 3430 | DEFAULT_COPY_CONSTRUCTOR(FloatConstant); |
| 3431 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3432 | private: |
| 3433 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3434 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3435 | value_(value) { |
| 3436 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3437 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3438 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3439 | value_(bit_cast<float, int32_t>(value)) { |
| 3440 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3441 | |
| 3442 | const float value_; |
| 3443 | |
| 3444 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3445 | friend class SsaBuilder; |
| 3446 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3447 | }; |
| 3448 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3449 | class HDoubleConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3450 | public: |
| 3451 | double GetValue() const { return value_; } |
| 3452 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3453 | uint64_t GetValueAsUint64() const override { return bit_cast<uint64_t, double>(value_); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3454 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3455 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3456 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 3457 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3458 | } |
| 3459 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3460 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3461 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3462 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3463 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 3464 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3465 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3466 | return std::fpclassify(value_) == FP_ZERO; |
| 3467 | } |
| 3468 | bool IsArithmeticPositiveZero() const { |
| 3469 | return IsArithmeticZero() && !std::signbit(value_); |
| 3470 | } |
| 3471 | bool IsArithmeticNegativeZero() const { |
| 3472 | return IsArithmeticZero() && std::signbit(value_); |
| 3473 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3474 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3475 | 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] | 3476 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3477 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3478 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3479 | } |
| 3480 | bool IsNaN() const { |
| 3481 | return std::isnan(value_); |
| 3482 | } |
| 3483 | |
| 3484 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3485 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3486 | protected: |
| 3487 | DEFAULT_COPY_CONSTRUCTOR(DoubleConstant); |
| 3488 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3489 | private: |
| 3490 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3491 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3492 | value_(value) { |
| 3493 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3494 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3495 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3496 | value_(bit_cast<double, int64_t>(value)) { |
| 3497 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3498 | |
| 3499 | const double value_; |
| 3500 | |
| 3501 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3502 | friend class SsaBuilder; |
| 3503 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3504 | }; |
| 3505 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3506 | // Conditional branch. A block ending with an HIf instruction must have |
| 3507 | // two successors. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3508 | class HIf final : public HExpression<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3509 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3510 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3511 | : HExpression(kIf, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3512 | SetRawInputAt(0, input); |
| 3513 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3514 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3515 | bool IsClonable() const override { return true; } |
| 3516 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3517 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3518 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3519 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3523 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3524 | } |
| 3525 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3526 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3527 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3528 | protected: |
| 3529 | DEFAULT_COPY_CONSTRUCTOR(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3530 | }; |
| 3531 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3532 | |
| 3533 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 3534 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 3535 | // non-exceptional control flow. |
| 3536 | // Normal-flow successor is stored at index zero, exception handlers under |
| 3537 | // higher indices in no particular order. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3538 | class HTryBoundary final : public HExpression<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3539 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3540 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3541 | kEntry, |
| 3542 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3543 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3544 | }; |
| 3545 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3546 | // SideEffects::CanTriggerGC prevents instructions with SideEffects::DependOnGC to be alive |
| 3547 | // across the catch block entering edges as GC might happen during throwing an exception. |
| 3548 | // TryBoundary with BoundaryKind::kExit is conservatively used for that as there is no |
| 3549 | // HInstruction which a catch block must start from. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3550 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3551 | : HExpression(kTryBoundary, |
| 3552 | (kind == BoundaryKind::kExit) ? SideEffects::CanTriggerGC() |
| 3553 | : SideEffects::None(), |
| 3554 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3555 | SetPackedField<BoundaryKindField>(kind); |
| 3556 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3557 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3558 | bool IsControlFlow() const override { return true; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3559 | |
| 3560 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3561 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3562 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 3563 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 3564 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 3565 | } |
| 3566 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3567 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 3568 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3569 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 3570 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 3571 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3572 | } |
| 3573 | |
| 3574 | // If not present already, adds `handler` to its block's list of exception |
| 3575 | // handlers. |
| 3576 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3577 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3578 | GetBlock()->AddSuccessor(handler); |
| 3579 | } |
| 3580 | } |
| 3581 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3582 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 3583 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3584 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3585 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 3586 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3587 | DECLARE_INSTRUCTION(TryBoundary); |
| 3588 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3589 | protected: |
| 3590 | DEFAULT_COPY_CONSTRUCTOR(TryBoundary); |
| 3591 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3592 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3593 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 3594 | static constexpr size_t kFieldBoundaryKindSize = |
| 3595 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 3596 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 3597 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 3598 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 3599 | "Too many packed fields."); |
| 3600 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3601 | }; |
| 3602 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3603 | // Deoptimize to interpreter, upon checking a condition. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3604 | class HDeoptimize final : public HVariableInputSizeInstruction { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3605 | public: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3606 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 3607 | // across. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3608 | HDeoptimize(ArenaAllocator* allocator, |
| 3609 | HInstruction* cond, |
| 3610 | DeoptimizationKind kind, |
| 3611 | uint32_t dex_pc) |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3612 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3613 | kDeoptimize, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3614 | SideEffects::All(), |
| 3615 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3616 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3617 | /* number_of_inputs= */ 1, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3618 | kArenaAllocMisc) { |
| 3619 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 3620 | SetPackedField<DeoptimizeKindField>(kind); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3621 | SetRawInputAt(0, cond); |
| 3622 | } |
| 3623 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3624 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3625 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3626 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3627 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3628 | // instead of `guard`. |
| 3629 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3630 | // at the point of the `HDeoptimize`. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3631 | HDeoptimize(ArenaAllocator* allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3632 | HInstruction* cond, |
| 3633 | HInstruction* guard, |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3634 | DeoptimizationKind kind, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3635 | uint32_t dex_pc) |
| 3636 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3637 | kDeoptimize, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3638 | guard->GetType(), |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3639 | SideEffects::CanTriggerGC(), |
| 3640 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3641 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3642 | /* number_of_inputs= */ 2, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3643 | kArenaAllocMisc) { |
| 3644 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3645 | SetPackedField<DeoptimizeKindField>(kind); |
| 3646 | SetRawInputAt(0, cond); |
| 3647 | SetRawInputAt(1, guard); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3648 | } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3649 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3650 | bool CanBeMoved() const override { return GetPackedFlag<kFieldCanBeMoved>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3651 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3652 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 9dd046d | 2023-04-25 15:45:29 +0000 | [diff] [blame] | 3653 | return (other->CanBeMoved() == CanBeMoved()) && |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 3654 | (other->AsDeoptimize()->GetDeoptimizationKind() == GetDeoptimizationKind()); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3655 | } |
| 3656 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3657 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3658 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3659 | bool CanThrow() const override { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3660 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3661 | DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3662 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3663 | bool GuardsAnInput() const { |
| 3664 | return InputCount() == 2; |
| 3665 | } |
| 3666 | |
| 3667 | HInstruction* GuardedInput() const { |
| 3668 | DCHECK(GuardsAnInput()); |
| 3669 | return InputAt(1); |
| 3670 | } |
| 3671 | |
| 3672 | void RemoveGuard() { |
| 3673 | RemoveInputAt(1); |
| 3674 | } |
| 3675 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3676 | DECLARE_INSTRUCTION(Deoptimize); |
| 3677 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3678 | protected: |
| 3679 | DEFAULT_COPY_CONSTRUCTOR(Deoptimize); |
| 3680 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3681 | private: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3682 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3683 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3684 | static constexpr size_t kFieldDeoptimizeKindSize = |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3685 | MinimumBitsToStore(static_cast<size_t>(DeoptimizationKind::kLast)); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3686 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3687 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3688 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3689 | "Too many packed fields."); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3690 | using DeoptimizeKindField = |
| 3691 | BitField<DeoptimizationKind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3692 | }; |
| 3693 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3694 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3695 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3696 | // if it's true, starts to do deoptimization. |
| 3697 | // It has a 4-byte slot on stack. |
| 3698 | // TODO: allocate a register for this flag. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3699 | class HShouldDeoptimizeFlag final : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3700 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3701 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3702 | // with regard to other passes. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3703 | HShouldDeoptimizeFlag(ArenaAllocator* allocator, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3704 | : HVariableInputSizeInstruction(kShouldDeoptimizeFlag, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3705 | DataType::Type::kInt32, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3706 | SideEffects::None(), |
| 3707 | dex_pc, |
| 3708 | allocator, |
| 3709 | 0, |
| 3710 | kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3711 | } |
| 3712 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3713 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3714 | // further guard elimination/motion since a guard might have been used for justification |
| 3715 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3716 | // to avoid other optimizations trying to move it. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3717 | bool CanBeMoved() const override { return false; } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3718 | |
| 3719 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3720 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3721 | protected: |
| 3722 | DEFAULT_COPY_CONSTRUCTOR(ShouldDeoptimizeFlag); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3723 | }; |
| 3724 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3725 | // Represents the ArtMethod that was passed as a first argument to |
| 3726 | // the method. It is used by instructions that depend on it, like |
| 3727 | // instructions that work with the dex cache. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3728 | class HCurrentMethod final : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3729 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3730 | explicit HCurrentMethod(DataType::Type type, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3731 | : HExpression(kCurrentMethod, type, SideEffects::None(), dex_pc) { |
| 3732 | } |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3733 | |
| 3734 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3735 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3736 | protected: |
| 3737 | DEFAULT_COPY_CONSTRUCTOR(CurrentMethod); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3738 | }; |
| 3739 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3740 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3741 | // of a class. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3742 | class HClassTableGet final : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3743 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3744 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3745 | kVTable, |
| 3746 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3747 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3748 | }; |
| 3749 | HClassTableGet(HInstruction* cls, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3750 | DataType::Type type, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3751 | TableKind kind, |
| 3752 | size_t index, |
| 3753 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3754 | : HExpression(kClassTableGet, type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3755 | index_(index) { |
| 3756 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3757 | SetRawInputAt(0, cls); |
| 3758 | } |
| 3759 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3760 | bool IsClonable() const override { return true; } |
| 3761 | bool CanBeMoved() const override { return true; } |
| 3762 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 3763 | return other->AsClassTableGet()->GetIndex() == index_ && |
| 3764 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3765 | } |
| 3766 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3767 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3768 | size_t GetIndex() const { return index_; } |
| 3769 | |
| 3770 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3771 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3772 | protected: |
| 3773 | DEFAULT_COPY_CONSTRUCTOR(ClassTableGet); |
| 3774 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3775 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3776 | static constexpr size_t kFieldTableKind = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3777 | static constexpr size_t kFieldTableKindSize = |
| 3778 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3779 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3780 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3781 | "Too many packed fields."); |
Vladimir Marko | 1adb0de | 2023-03-03 09:16:24 +0000 | [diff] [blame] | 3782 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3783 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3784 | // The index of the ArtMethod in the table. |
| 3785 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3786 | }; |
| 3787 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3788 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3789 | // have one successor for each entry in the switch table, and the final successor |
| 3790 | // will be the block containing the next Dex opcode. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3791 | class HPackedSwitch final : public HExpression<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3792 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3793 | HPackedSwitch(int32_t start_value, |
| 3794 | uint32_t num_entries, |
| 3795 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3796 | uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3797 | : HExpression(kPackedSwitch, SideEffects::None(), dex_pc), |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3798 | start_value_(start_value), |
| 3799 | num_entries_(num_entries) { |
| 3800 | SetRawInputAt(0, input); |
| 3801 | } |
| 3802 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3803 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3804 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3805 | bool IsControlFlow() const override { return true; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3806 | |
| 3807 | int32_t GetStartValue() const { return start_value_; } |
| 3808 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3809 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3810 | |
| 3811 | HBasicBlock* GetDefaultBlock() const { |
| 3812 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3813 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3814 | } |
| 3815 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3816 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3817 | protected: |
| 3818 | DEFAULT_COPY_CONSTRUCTOR(PackedSwitch); |
| 3819 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3820 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3821 | const int32_t start_value_; |
| 3822 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3823 | }; |
| 3824 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3825 | class HUnaryOperation : public HExpression<1> { |
| 3826 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3827 | HUnaryOperation(InstructionKind kind, |
| 3828 | DataType::Type result_type, |
| 3829 | HInstruction* input, |
| 3830 | uint32_t dex_pc = kNoDexPc) |
| 3831 | : HExpression(kind, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3832 | SetRawInputAt(0, input); |
| 3833 | } |
| 3834 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3835 | // All of the UnaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3836 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3837 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3838 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3839 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3840 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3841 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 3842 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3843 | return true; |
| 3844 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3845 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3846 | // Try to statically evaluate `this` and return a HConstant |
| 3847 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3848 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3849 | HConstant* TryStaticEvaluation() const; |
| 3850 | |
| 3851 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3852 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3853 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3854 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3855 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3856 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3857 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3858 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3859 | protected: |
| 3860 | DEFAULT_COPY_CONSTRUCTOR(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3861 | }; |
| 3862 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3863 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3864 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3865 | HBinaryOperation(InstructionKind kind, |
| 3866 | DataType::Type result_type, |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3867 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3868 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3869 | SideEffects side_effects = SideEffects::None(), |
| 3870 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3871 | : HExpression(kind, result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3872 | SetRawInputAt(0, left); |
| 3873 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3876 | // All of the BinaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3877 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3878 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3879 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3880 | HInstruction* GetRight() const { return InputAt(1); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3881 | DataType::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3882 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3883 | virtual bool IsCommutative() const { return false; } |
| 3884 | |
| 3885 | // Put constant on the right. |
| 3886 | // Returns whether order is changed. |
| 3887 | bool OrderInputsWithConstantOnTheRight() { |
| 3888 | HInstruction* left = InputAt(0); |
| 3889 | HInstruction* right = InputAt(1); |
| 3890 | if (left->IsConstant() && !right->IsConstant()) { |
| 3891 | ReplaceInput(right, 0); |
| 3892 | ReplaceInput(left, 1); |
| 3893 | return true; |
| 3894 | } |
| 3895 | return false; |
| 3896 | } |
| 3897 | |
| 3898 | // Order inputs by instruction id, but favor constant on the right side. |
| 3899 | // This helps GVN for commutative ops. |
| 3900 | void OrderInputs() { |
| 3901 | DCHECK(IsCommutative()); |
| 3902 | HInstruction* left = InputAt(0); |
| 3903 | HInstruction* right = InputAt(1); |
| 3904 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3905 | return; |
| 3906 | } |
| 3907 | if (OrderInputsWithConstantOnTheRight()) { |
| 3908 | return; |
| 3909 | } |
| 3910 | // Order according to instruction id. |
| 3911 | if (left->GetId() > right->GetId()) { |
| 3912 | ReplaceInput(right, 0); |
| 3913 | ReplaceInput(left, 1); |
| 3914 | } |
| 3915 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3916 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3917 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 3918 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3919 | return true; |
| 3920 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3921 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3922 | // Try to statically evaluate `this` and return a HConstant |
| 3923 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3924 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3925 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3926 | |
| 3927 | // Apply this operation to `x` and `y`. |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 3928 | virtual HConstant* Evaluate([[maybe_unused]] HNullConstant* x, |
| 3929 | [[maybe_unused]] HNullConstant* y) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3930 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3931 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3932 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3933 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3934 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 3935 | virtual HConstant* Evaluate([[maybe_unused]] HLongConstant* x, |
| 3936 | [[maybe_unused]] HIntConstant* y) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3937 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3938 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3939 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3940 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3941 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3942 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3943 | // 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] | 3944 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3945 | HConstant* GetConstantRight() const; |
| 3946 | |
| 3947 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3948 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3949 | HInstruction* GetLeastConstantLeft() const; |
| 3950 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3951 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3952 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3953 | protected: |
| 3954 | DEFAULT_COPY_CONSTRUCTOR(BinaryOperation); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3955 | }; |
| 3956 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3957 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3958 | // comparisons are treated: |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 3959 | 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] | 3960 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3961 | kGtBias, // return 1 for NaN comparisons |
| 3962 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3963 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3964 | }; |
| 3965 | |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 3966 | std::ostream& operator<<(std::ostream& os, ComparisonBias rhs); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3967 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3968 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3969 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3970 | HCondition(InstructionKind kind, |
| 3971 | HInstruction* first, |
| 3972 | HInstruction* second, |
| 3973 | uint32_t dex_pc = kNoDexPc) |
| 3974 | : HBinaryOperation(kind, |
| 3975 | DataType::Type::kBool, |
| 3976 | first, |
| 3977 | second, |
| 3978 | SideEffects::None(), |
| 3979 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3980 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3981 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3982 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3983 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3984 | // `instruction`, and disregard moves in between. |
| 3985 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3986 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3987 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3988 | |
| 3989 | virtual IfCondition GetCondition() const = 0; |
| 3990 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3991 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3992 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3993 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3994 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3995 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3996 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3997 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3998 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3999 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 4000 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4001 | } |
| 4002 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4003 | bool IsFPConditionTrueIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4004 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4005 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 4006 | if (if_cond == kCondNE) { |
| 4007 | return true; |
| 4008 | } else if (if_cond == kCondEQ) { |
| 4009 | return false; |
| 4010 | } |
| 4011 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | bool IsFPConditionFalseIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4015 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4016 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 4017 | if (if_cond == kCondEQ) { |
| 4018 | return true; |
| 4019 | } else if (if_cond == kCondNE) { |
| 4020 | return false; |
| 4021 | } |
| 4022 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4023 | } |
| 4024 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4025 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4026 | // Needed if we merge a HCompare into a HCondition. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4027 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4028 | static constexpr size_t kFieldComparisonBiasSize = |
| 4029 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 4030 | static constexpr size_t kNumberOfConditionPackedBits = |
| 4031 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 4032 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4033 | using ComparisonBiasField = |
| 4034 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 4035 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4036 | template <typename T> |
| 4037 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 4038 | |
| 4039 | template <typename T> |
| 4040 | int32_t CompareFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4041 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4042 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 4043 | // Handle the bias. |
| 4044 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 4045 | } |
| 4046 | |
| 4047 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 4048 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 4049 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 4050 | } |
| 4051 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4052 | DEFAULT_COPY_CONSTRUCTOR(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4053 | }; |
| 4054 | |
| 4055 | // Instruction to check if two inputs are equal to each other. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4056 | class HEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4057 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4058 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4059 | : HCondition(kEqual, first, second, dex_pc) { |
| 4060 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4061 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4062 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4063 | |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 4064 | HConstant* Evaluate([[maybe_unused]] HNullConstant* x, |
| 4065 | [[maybe_unused]] HNullConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4066 | return MakeConstantCondition(true, GetDexPc()); |
| 4067 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4068 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4069 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4070 | } |
| 4071 | // In the following Evaluate methods, a HCompare instruction has |
| 4072 | // been merged into this HEqual instruction; evaluate it as |
| 4073 | // `Compare(x, y) == 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4074 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4075 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 4076 | GetDexPc()); |
| 4077 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4078 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4079 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4080 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4081 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4082 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 4083 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4084 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4085 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 4086 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4087 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4088 | return kCondEQ; |
| 4089 | } |
| 4090 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4091 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4092 | return kCondNE; |
| 4093 | } |
| 4094 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4095 | protected: |
| 4096 | DEFAULT_COPY_CONSTRUCTOR(Equal); |
| 4097 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 4098 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4099 | 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] | 4100 | }; |
| 4101 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4102 | class HNotEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4103 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4104 | HNotEqual(HInstruction* first, HInstruction* second, |
| 4105 | uint32_t dex_pc = kNoDexPc) |
| 4106 | : HCondition(kNotEqual, first, second, dex_pc) { |
| 4107 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4108 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4109 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4110 | |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 4111 | HConstant* Evaluate([[maybe_unused]] HNullConstant* x, |
| 4112 | [[maybe_unused]] HNullConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4113 | return MakeConstantCondition(false, GetDexPc()); |
| 4114 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4115 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4116 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4117 | } |
| 4118 | // In the following Evaluate methods, a HCompare instruction has |
| 4119 | // been merged into this HNotEqual instruction; evaluate it as |
| 4120 | // `Compare(x, y) != 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4121 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4122 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4123 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4124 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4125 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4126 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4127 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4128 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 4129 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4130 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4131 | DECLARE_INSTRUCTION(NotEqual); |
| 4132 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4133 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4134 | return kCondNE; |
| 4135 | } |
| 4136 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4137 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4138 | return kCondEQ; |
| 4139 | } |
| 4140 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4141 | protected: |
| 4142 | DEFAULT_COPY_CONSTRUCTOR(NotEqual); |
| 4143 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4144 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4145 | 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] | 4146 | }; |
| 4147 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4148 | class HLessThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4149 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4150 | HLessThan(HInstruction* first, HInstruction* second, |
| 4151 | uint32_t dex_pc = kNoDexPc) |
| 4152 | : HCondition(kLessThan, first, second, dex_pc) { |
| 4153 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4154 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4155 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4156 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4157 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4158 | // In the following Evaluate methods, a HCompare instruction has |
| 4159 | // been merged into this HLessThan instruction; evaluate it as |
| 4160 | // `Compare(x, y) < 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4161 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4162 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4163 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4164 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4165 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4166 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4167 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4168 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4169 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4170 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4171 | DECLARE_INSTRUCTION(LessThan); |
| 4172 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4173 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4174 | return kCondLT; |
| 4175 | } |
| 4176 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4177 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4178 | return kCondGE; |
| 4179 | } |
| 4180 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4181 | protected: |
| 4182 | DEFAULT_COPY_CONSTRUCTOR(LessThan); |
| 4183 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4184 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4185 | 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] | 4186 | }; |
| 4187 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4188 | class HLessThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4189 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4190 | HLessThanOrEqual(HInstruction* first, HInstruction* second, |
| 4191 | uint32_t dex_pc = kNoDexPc) |
| 4192 | : HCondition(kLessThanOrEqual, first, second, dex_pc) { |
| 4193 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4194 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4195 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4196 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4197 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4198 | // In the following Evaluate methods, a HCompare instruction has |
| 4199 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 4200 | // `Compare(x, y) <= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4201 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4202 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4203 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4204 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4205 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4206 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4207 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4208 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4209 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4210 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4211 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 4212 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4213 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4214 | return kCondLE; |
| 4215 | } |
| 4216 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4217 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4218 | return kCondGT; |
| 4219 | } |
| 4220 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4221 | protected: |
| 4222 | DEFAULT_COPY_CONSTRUCTOR(LessThanOrEqual); |
| 4223 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4224 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4225 | 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] | 4226 | }; |
| 4227 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4228 | class HGreaterThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4229 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4230 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4231 | : HCondition(kGreaterThan, first, second, dex_pc) { |
| 4232 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4233 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4234 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4235 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4236 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4237 | // In the following Evaluate methods, a HCompare instruction has |
| 4238 | // been merged into this HGreaterThan instruction; evaluate it as |
| 4239 | // `Compare(x, y) > 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4240 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4241 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4242 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4243 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4244 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4245 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4246 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4247 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4248 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4249 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4250 | DECLARE_INSTRUCTION(GreaterThan); |
| 4251 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4252 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4253 | return kCondGT; |
| 4254 | } |
| 4255 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4256 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4257 | return kCondLE; |
| 4258 | } |
| 4259 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4260 | protected: |
| 4261 | DEFAULT_COPY_CONSTRUCTOR(GreaterThan); |
| 4262 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4263 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4264 | 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] | 4265 | }; |
| 4266 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4267 | class HGreaterThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4268 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4269 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4270 | : HCondition(kGreaterThanOrEqual, first, second, dex_pc) { |
| 4271 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4272 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4273 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4274 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4275 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4276 | // In the following Evaluate methods, a HCompare instruction has |
| 4277 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 4278 | // `Compare(x, y) >= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4279 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4280 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4281 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4282 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4283 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4284 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4285 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4286 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4287 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4288 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4289 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 4290 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4291 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4292 | return kCondGE; |
| 4293 | } |
| 4294 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4295 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4296 | return kCondLT; |
| 4297 | } |
| 4298 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4299 | protected: |
| 4300 | DEFAULT_COPY_CONSTRUCTOR(GreaterThanOrEqual); |
| 4301 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4302 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4303 | 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] | 4304 | }; |
| 4305 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4306 | class HBelow final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4307 | public: |
| 4308 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4309 | : HCondition(kBelow, first, second, dex_pc) { |
| 4310 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4311 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4312 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4313 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4314 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4315 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4316 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4317 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 4318 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* x, |
| 4319 | [[maybe_unused]] HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4320 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4321 | UNREACHABLE(); |
| 4322 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 4323 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* x, |
| 4324 | [[maybe_unused]] HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4325 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4326 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4327 | } |
| 4328 | |
| 4329 | DECLARE_INSTRUCTION(Below); |
| 4330 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4331 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4332 | return kCondB; |
| 4333 | } |
| 4334 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4335 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4336 | return kCondAE; |
| 4337 | } |
| 4338 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4339 | protected: |
| 4340 | DEFAULT_COPY_CONSTRUCTOR(Below); |
| 4341 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4342 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4343 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4344 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 4345 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4346 | }; |
| 4347 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4348 | class HBelowOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4349 | public: |
| 4350 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4351 | : HCondition(kBelowOrEqual, first, second, dex_pc) { |
| 4352 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4353 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4354 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4355 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4356 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4357 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4358 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4359 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 4360 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* x, |
| 4361 | [[maybe_unused]] HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4362 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4363 | UNREACHABLE(); |
| 4364 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 4365 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* x, |
| 4366 | [[maybe_unused]] HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4367 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4368 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 4372 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4373 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4374 | return kCondBE; |
| 4375 | } |
| 4376 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4377 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4378 | return kCondA; |
| 4379 | } |
| 4380 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4381 | protected: |
| 4382 | DEFAULT_COPY_CONSTRUCTOR(BelowOrEqual); |
| 4383 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4384 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4385 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4386 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 4387 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4388 | }; |
| 4389 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4390 | class HAbove final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4391 | public: |
| 4392 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4393 | : HCondition(kAbove, first, second, dex_pc) { |
| 4394 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4395 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4396 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4397 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4398 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4399 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4400 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4401 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 4402 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* x, |
| 4403 | [[maybe_unused]] HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4404 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4405 | UNREACHABLE(); |
| 4406 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 4407 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* x, |
| 4408 | [[maybe_unused]] HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4409 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4410 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | DECLARE_INSTRUCTION(Above); |
| 4414 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4415 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4416 | return kCondA; |
| 4417 | } |
| 4418 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4419 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4420 | return kCondBE; |
| 4421 | } |
| 4422 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4423 | protected: |
| 4424 | DEFAULT_COPY_CONSTRUCTOR(Above); |
| 4425 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4426 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4427 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4428 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 4429 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4430 | }; |
| 4431 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4432 | class HAboveOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4433 | public: |
| 4434 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4435 | : HCondition(kAboveOrEqual, first, second, dex_pc) { |
| 4436 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4437 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4438 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4439 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4440 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4441 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4442 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4443 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 4444 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* x, |
| 4445 | [[maybe_unused]] HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4446 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4447 | UNREACHABLE(); |
| 4448 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 4449 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* x, |
| 4450 | [[maybe_unused]] HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4451 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4452 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4453 | } |
| 4454 | |
| 4455 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 4456 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4457 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4458 | return kCondAE; |
| 4459 | } |
| 4460 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4461 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4462 | return kCondB; |
| 4463 | } |
| 4464 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4465 | protected: |
| 4466 | DEFAULT_COPY_CONSTRUCTOR(AboveOrEqual); |
| 4467 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4468 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4469 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4470 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 4471 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4472 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4473 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4474 | // Instruction to check how two inputs compare to each other. |
| 4475 | // 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] | 4476 | class HCompare final : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4477 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4478 | // Note that `comparison_type` is the type of comparison performed |
| 4479 | // between the comparison's inputs, not the type of the instantiated |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4480 | // HCompare instruction (which is always DataType::Type::kInt). |
| 4481 | HCompare(DataType::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4482 | HInstruction* first, |
| 4483 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4484 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4485 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4486 | : HBinaryOperation(kCompare, |
| 4487 | DataType::Type::kInt32, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4488 | first, |
| 4489 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4490 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4491 | dex_pc) { |
| 4492 | SetPackedField<ComparisonBiasField>(bias); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4493 | } |
| 4494 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4495 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4496 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 4497 | |
| 4498 | template <typename T> |
| 4499 | int32_t ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4500 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4501 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 4502 | // Handle the bias. |
| 4503 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 4504 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4505 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4506 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4507 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 4508 | // reach this code path when processing a freshly built HIR |
| 4509 | // graph. However HCompare integer instructions can be synthesized |
| 4510 | // by the instruction simplifier to implement IntegerCompare and |
| 4511 | // IntegerSignum intrinsics, so we have to handle this case. |
| 4512 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4513 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4514 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4515 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4516 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4517 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4518 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4519 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4520 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4521 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4522 | } |
| 4523 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4524 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 4525 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4526 | } |
| 4527 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4528 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4529 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4530 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4531 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4532 | bool IsGtBias() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4533 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4534 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4535 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4536 | |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 4537 | static SideEffects SideEffectsForArchRuntimeCalls([[maybe_unused]] DataType::Type type) { |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 4538 | // Comparisons do not require a runtime call in any back end. |
| 4539 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4540 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4541 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4542 | DECLARE_INSTRUCTION(Compare); |
| 4543 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4544 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4545 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4546 | static constexpr size_t kFieldComparisonBiasSize = |
| 4547 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 4548 | static constexpr size_t kNumberOfComparePackedBits = |
| 4549 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 4550 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4551 | using ComparisonBiasField = |
| 4552 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 4553 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4554 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 4555 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 4556 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 4557 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 4558 | } |
| 4559 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4560 | DEFAULT_COPY_CONSTRUCTOR(Compare); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4561 | }; |
| 4562 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4563 | class HNewInstance final : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4564 | public: |
| 4565 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4566 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4567 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4568 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4569 | bool finalizable, |
| 4570 | QuickEntrypointEnum entrypoint) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4571 | : HExpression(kNewInstance, |
| 4572 | DataType::Type::kReference, |
| 4573 | SideEffects::CanTriggerGC(), |
| 4574 | dex_pc), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4575 | type_index_(type_index), |
| 4576 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4577 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4578 | SetPackedFlag<kFlagFinalizable>(finalizable); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4579 | SetPackedFlag<kFlagPartialMaterialization>(false); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4580 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4583 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4584 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4585 | void SetPartialMaterialization() { |
| 4586 | SetPackedFlag<kFlagPartialMaterialization>(true); |
| 4587 | } |
| 4588 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4589 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4590 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4591 | |
| 4592 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4593 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4594 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4595 | // 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] | 4596 | bool CanThrow() const override { return true; } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4597 | bool OnlyThrowsAsyncExceptions() const override { |
| 4598 | return !IsFinalizable() && !NeedsChecks(); |
| 4599 | } |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4600 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4601 | bool NeedsChecks() const { |
| 4602 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 4603 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4604 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4605 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4606 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4607 | bool CanBeNull() const override { return false; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4608 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4609 | bool IsPartialMaterialization() const { |
| 4610 | return GetPackedFlag<kFlagPartialMaterialization>(); |
| 4611 | } |
| 4612 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4613 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4614 | |
| 4615 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 4616 | entrypoint_ = entrypoint; |
| 4617 | } |
| 4618 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4619 | HLoadClass* GetLoadClass() const { |
| 4620 | HInstruction* input = InputAt(0); |
| 4621 | if (input->IsClinitCheck()) { |
| 4622 | input = input->InputAt(0); |
| 4623 | } |
| 4624 | DCHECK(input->IsLoadClass()); |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 4625 | return input->AsLoadClass(); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4626 | } |
| 4627 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4628 | bool IsStringAlloc() const; |
| 4629 | |
| 4630 | DECLARE_INSTRUCTION(NewInstance); |
| 4631 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4632 | protected: |
| 4633 | DEFAULT_COPY_CONSTRUCTOR(NewInstance); |
| 4634 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4635 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4636 | static constexpr size_t kFlagFinalizable = kNumberOfGenericPackedBits; |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4637 | static constexpr size_t kFlagPartialMaterialization = kFlagFinalizable + 1; |
| 4638 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagPartialMaterialization + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4639 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 4640 | "Too many packed fields."); |
| 4641 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4642 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4643 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4644 | QuickEntrypointEnum entrypoint_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4645 | }; |
| 4646 | |
Nicolas Geoffray | 8f2eb25 | 2020-11-06 13:39:54 +0000 | [diff] [blame] | 4647 | enum IntrinsicNeedsEnvironment { |
| 4648 | kNoEnvironment, // Intrinsic does not require an environment. |
| 4649 | kNeedsEnvironment // Intrinsic requires an environment. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4650 | }; |
| 4651 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4652 | enum IntrinsicSideEffects { |
| 4653 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 4654 | kReadSideEffects, // Intrinsic may read heap memory. |
| 4655 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 4656 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 4657 | }; |
| 4658 | |
| 4659 | enum IntrinsicExceptions { |
| 4660 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 4661 | kCanThrow // Intrinsic may throw exceptions. |
| 4662 | }; |
| 4663 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4664 | // Determines how to load an ArtMethod*. |
| 4665 | enum class MethodLoadKind { |
| 4666 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4667 | kStringInit, |
| 4668 | |
| 4669 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4670 | kRecursive, |
| 4671 | |
| 4672 | // Use PC-relative boot image ArtMethod* address that will be known at link time. |
| 4673 | // Used for boot image methods referenced by boot image code. |
| 4674 | kBootImageLinkTimePcRelative, |
| 4675 | |
| 4676 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| 4677 | // Used for app->boot calls with relocatable image. |
| 4678 | kBootImageRelRo, |
| 4679 | |
| 4680 | // Load from an entry in the .bss section using a PC-relative load. |
| 4681 | // Used for methods outside boot image referenced by AOT-compiled app and boot image code. |
| 4682 | kBssEntry, |
| 4683 | |
| 4684 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4685 | // Used for for JIT-compiled calls. |
| 4686 | kJitDirectAddress, |
| 4687 | |
| 4688 | // Make a runtime call to resolve and call the method. This is the last-resort-kind |
| 4689 | // used when other kinds are unimplemented on a particular architecture. |
| 4690 | kRuntimeCall, |
| 4691 | }; |
| 4692 | |
| 4693 | // Determines the location of the code pointer of an invoke. |
| 4694 | enum class CodePtrLocation { |
| 4695 | // Recursive call, use local PC-relative call instruction. |
| 4696 | kCallSelf, |
| 4697 | |
| 4698 | // Use native pointer from the Artmethod*. |
| 4699 | // Used for @CriticalNative to avoid going through the compiled stub. This call goes through |
| 4700 | // a special resolution stub if the class is not initialized or no native code is registered. |
| 4701 | kCallCriticalNative, |
| 4702 | |
| 4703 | // Use code pointer from the ArtMethod*. |
| 4704 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4705 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4706 | kCallArtMethod, |
| 4707 | }; |
| 4708 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4709 | static inline bool IsPcRelativeMethodLoadKind(MethodLoadKind load_kind) { |
| 4710 | return load_kind == MethodLoadKind::kBootImageLinkTimePcRelative || |
| 4711 | load_kind == MethodLoadKind::kBootImageRelRo || |
| 4712 | load_kind == MethodLoadKind::kBssEntry; |
| 4713 | } |
| 4714 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4715 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4716 | public: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4717 | bool NeedsEnvironment() const override; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4718 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 4719 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4720 | SetRawInputAt(index, argument); |
| 4721 | } |
| 4722 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4723 | // Return the number of arguments. This number can be lower than |
| 4724 | // the number of inputs returned by InputCount(), as some invoke |
| 4725 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 4726 | // inputs at the end of their list of inputs. |
| 4727 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 4728 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4729 | InvokeType GetInvokeType() const { |
| 4730 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4731 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4732 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 4733 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4734 | return intrinsic_; |
| 4735 | } |
| 4736 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4737 | void SetIntrinsic(Intrinsics intrinsic, |
Nicolas Geoffray | 8f2eb25 | 2020-11-06 13:39:54 +0000 | [diff] [blame] | 4738 | IntrinsicNeedsEnvironment needs_env, |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4739 | IntrinsicSideEffects side_effects, |
| 4740 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4741 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4742 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4743 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4744 | } |
| 4745 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4746 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4747 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4748 | bool CanThrow() const override { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4749 | |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4750 | void SetAlwaysThrows(bool always_throws) { SetPackedFlag<kFlagAlwaysThrows>(always_throws); } |
| 4751 | |
Santiago Aboy Solanes | a3bd09c | 2022-07-29 14:09:28 +0100 | [diff] [blame] | 4752 | bool AlwaysThrows() const override final { return GetPackedFlag<kFlagAlwaysThrows>(); } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4753 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4754 | bool CanBeMoved() const override { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4755 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4756 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 4757 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4758 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4759 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4760 | uint32_t* GetIntrinsicOptimizations() { |
| 4761 | return &intrinsic_optimizations_; |
| 4762 | } |
| 4763 | |
| 4764 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4765 | return &intrinsic_optimizations_; |
| 4766 | } |
| 4767 | |
| 4768 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4769 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4770 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 4771 | void SetResolvedMethod(ArtMethod* method, bool enable_intrinsic_opt); |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4772 | |
| 4773 | MethodReference GetMethodReference() const { return method_reference_; } |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4774 | |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4775 | const MethodReference GetResolvedMethodReference() const { |
| 4776 | return resolved_method_reference_; |
| 4777 | } |
| 4778 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4779 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4780 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4781 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4782 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4783 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4784 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4785 | static constexpr size_t kFlagCanThrow = kFieldInvokeType + kFieldInvokeTypeSize; |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4786 | static constexpr size_t kFlagAlwaysThrows = kFlagCanThrow + 1; |
| 4787 | static constexpr size_t kNumberOfInvokePackedBits = kFlagAlwaysThrows + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4788 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4789 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4790 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4791 | HInvoke(InstructionKind kind, |
| 4792 | ArenaAllocator* allocator, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4793 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4794 | uint32_t number_of_other_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4795 | DataType::Type return_type, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4796 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4797 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4798 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4799 | MethodReference resolved_method_reference, |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 4800 | InvokeType invoke_type, |
| 4801 | bool enable_intrinsic_opt) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4802 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4803 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4804 | return_type, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4805 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4806 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4807 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4808 | number_of_arguments + number_of_other_inputs, |
| 4809 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4810 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4811 | method_reference_(method_reference), |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4812 | resolved_method_reference_(resolved_method_reference), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4813 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4814 | intrinsic_optimizations_(0) { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4815 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4816 | SetPackedFlag<kFlagCanThrow>(true); |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 4817 | SetResolvedMethod(resolved_method, enable_intrinsic_opt); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4818 | } |
| 4819 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4820 | DEFAULT_COPY_CONSTRUCTOR(Invoke); |
| 4821 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4822 | uint32_t number_of_arguments_; |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4823 | ArtMethod* resolved_method_; |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4824 | const MethodReference method_reference_; |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4825 | // Cached values of the resolved method, to avoid needing the mutator lock. |
| 4826 | const MethodReference resolved_method_reference_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4827 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4828 | |
| 4829 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4830 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4831 | }; |
| 4832 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4833 | class HInvokeUnresolved final : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4834 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4835 | HInvokeUnresolved(ArenaAllocator* allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4836 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4837 | DataType::Type return_type, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4838 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4839 | MethodReference method_reference, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4840 | InvokeType invoke_type) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4841 | : HInvoke(kInvokeUnresolved, |
| 4842 | allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4843 | number_of_arguments, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4844 | /* number_of_other_inputs= */ 0u, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4845 | return_type, |
| 4846 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4847 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4848 | nullptr, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4849 | MethodReference(nullptr, 0u), |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 4850 | invoke_type, |
| 4851 | /* enable_intrinsic_opt= */ false) { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4852 | } |
| 4853 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4854 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4855 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4856 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4857 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4858 | protected: |
| 4859 | DEFAULT_COPY_CONSTRUCTOR(InvokeUnresolved); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4860 | }; |
| 4861 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4862 | class HInvokePolymorphic final : public HInvoke { |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4863 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4864 | HInvokePolymorphic(ArenaAllocator* allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4865 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4866 | DataType::Type return_type, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4867 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4868 | MethodReference method_reference, |
Andra Danciu | b931b8c | 2020-07-27 13:16:37 +0000 | [diff] [blame] | 4869 | // resolved_method is the ArtMethod object corresponding to the polymorphic |
| 4870 | // method (e.g. VarHandle.get), resolved using the class linker. It is needed |
| 4871 | // to pass intrinsic information to the HInvokePolymorphic node. |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4872 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4873 | MethodReference resolved_method_reference, |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 4874 | dex::ProtoIndex proto_idx, |
| 4875 | bool enable_intrinsic_opt) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4876 | : HInvoke(kInvokePolymorphic, |
| 4877 | allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4878 | number_of_arguments, |
Andra Danciu | 49a19f3 | 2020-08-27 12:44:25 +0000 | [diff] [blame] | 4879 | /* number_of_other_inputs= */ 0u, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4880 | return_type, |
| 4881 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4882 | method_reference, |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4883 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4884 | resolved_method_reference, |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 4885 | kPolymorphic, |
| 4886 | enable_intrinsic_opt), |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4887 | proto_idx_(proto_idx) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4888 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4889 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4890 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4891 | |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4892 | dex::ProtoIndex GetProtoIndex() { return proto_idx_; } |
| 4893 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4894 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4895 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4896 | protected: |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4897 | dex::ProtoIndex proto_idx_; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4898 | DEFAULT_COPY_CONSTRUCTOR(InvokePolymorphic); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4899 | }; |
| 4900 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4901 | class HInvokeCustom final : public HInvoke { |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4902 | public: |
| 4903 | HInvokeCustom(ArenaAllocator* allocator, |
| 4904 | uint32_t number_of_arguments, |
| 4905 | uint32_t call_site_index, |
| 4906 | DataType::Type return_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4907 | uint32_t dex_pc, |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 4908 | MethodReference method_reference, |
| 4909 | bool enable_intrinsic_opt) |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4910 | : HInvoke(kInvokeCustom, |
| 4911 | allocator, |
| 4912 | number_of_arguments, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4913 | /* number_of_other_inputs= */ 0u, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4914 | return_type, |
| 4915 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4916 | method_reference, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4917 | /* resolved_method= */ nullptr, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4918 | MethodReference(nullptr, 0u), |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 4919 | kStatic, |
| 4920 | enable_intrinsic_opt), |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4921 | call_site_index_(call_site_index) { |
| 4922 | } |
| 4923 | |
| 4924 | uint32_t GetCallSiteIndex() const { return call_site_index_; } |
| 4925 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4926 | bool IsClonable() const override { return true; } |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4927 | |
| 4928 | DECLARE_INSTRUCTION(InvokeCustom); |
| 4929 | |
| 4930 | protected: |
| 4931 | DEFAULT_COPY_CONSTRUCTOR(InvokeCustom); |
| 4932 | |
| 4933 | private: |
| 4934 | uint32_t call_site_index_; |
| 4935 | }; |
| 4936 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4937 | class HInvokeStaticOrDirect final : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4938 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4939 | // Requirements of this method call regarding the class |
| 4940 | // initialization (clinit) check of its declaring class. |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 4941 | 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] | 4942 | kNone, // Class already initialized. |
| 4943 | kExplicit, // Static call having explicit clinit check as last input. |
| 4944 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4945 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4946 | }; |
| 4947 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4948 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4949 | MethodLoadKind method_load_kind; |
| 4950 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4951 | // The method load data holds |
| 4952 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4953 | // Note that there are multiple string init methods, each having its own offset. |
| 4954 | // - the method address for kDirectAddress |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4955 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4956 | }; |
| 4957 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4958 | HInvokeStaticOrDirect(ArenaAllocator* allocator, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4959 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4960 | DataType::Type return_type, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4961 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4962 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4963 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4964 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4965 | InvokeType invoke_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4966 | MethodReference resolved_method_reference, |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 4967 | ClinitCheckRequirement clinit_check_requirement, |
| 4968 | bool enable_intrinsic_opt) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4969 | : HInvoke(kInvokeStaticOrDirect, |
| 4970 | allocator, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4971 | number_of_arguments, |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4972 | // There is potentially one extra argument for the HCurrentMethod input, |
| 4973 | // and one other if the clinit check is explicit. These can be removed later. |
| 4974 | (NeedsCurrentMethodInput(dispatch_info) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4975 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4976 | return_type, |
| 4977 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4978 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4979 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4980 | resolved_method_reference, |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 4981 | invoke_type, |
| 4982 | enable_intrinsic_opt), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4983 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4984 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4985 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4986 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4987 | bool IsClonable() const override { return true; } |
Santiago Aboy Solanes | e43aa3f | 2021-11-01 09:02:09 +0000 | [diff] [blame] | 4988 | bool NeedsBss() const override { |
| 4989 | return GetMethodLoadKind() == MethodLoadKind::kBssEntry; |
| 4990 | } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4991 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4992 | void SetDispatchInfo(DispatchInfo dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4993 | bool had_current_method_input = HasCurrentMethodInput(); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4994 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4995 | |
| 4996 | // Using the current method is the default and once we find a better |
| 4997 | // method load kind, we should not go back to using the current method. |
| 4998 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4999 | |
| 5000 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5001 | DCHECK_EQ(InputAt(GetCurrentMethodIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 5002 | RemoveInputAt(GetCurrentMethodIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 5003 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5004 | dispatch_info_ = dispatch_info; |
| 5005 | } |
| 5006 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 5007 | DispatchInfo GetDispatchInfo() const { |
| 5008 | return dispatch_info_; |
| 5009 | } |
| 5010 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5011 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5012 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5013 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 5014 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 5015 | DCHECK(!input_records.empty()); |
| 5016 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 5017 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 5018 | // Note: `last_input` may be null during arguments setup. |
| 5019 | if (last_input != nullptr) { |
| 5020 | // `last_input` is the last input of a static invoke marked as having |
| 5021 | // an explicit clinit check. It must either be: |
| 5022 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 5023 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 5024 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 5025 | } |
| 5026 | } |
| 5027 | return input_records; |
| 5028 | } |
| 5029 | |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5030 | bool CanDoImplicitNullCheckOn([[maybe_unused]] HInstruction* obj) const override { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5031 | // 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] | 5032 | // TODO: for intrinsics we can generate implicit null checks. |
| 5033 | return false; |
| 5034 | } |
| 5035 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5036 | bool CanBeNull() const override { |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5037 | return GetType() == DataType::Type::kReference && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 5038 | } |
| 5039 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5040 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
Nicolas Geoffray | 282795c | 2021-09-24 18:16:41 +0100 | [diff] [blame] | 5041 | CodePtrLocation GetCodePtrLocation() const { |
| 5042 | // We do CHA analysis after sharpening. When a method has CHA inlining, it |
| 5043 | // cannot call itself, as if the CHA optmization is invalid we want to make |
| 5044 | // sure the method is never executed again. So, while sharpening can return |
| 5045 | // kCallSelf, we bypass it here if there is a CHA optimization. |
| 5046 | if (dispatch_info_.code_ptr_location == CodePtrLocation::kCallSelf && |
| 5047 | GetBlock()->GetGraph()->HasShouldDeoptimizeFlag()) { |
| 5048 | return CodePtrLocation::kCallArtMethod; |
| 5049 | } else { |
| 5050 | return dispatch_info_.code_ptr_location; |
| 5051 | } |
| 5052 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5053 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5054 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5055 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kJitDirectAddress; } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5056 | bool HasPcRelativeMethodLoadKind() const { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5057 | return IsPcRelativeMethodLoadKind(GetMethodLoadKind()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5058 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5059 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5060 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5061 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5062 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | uint64_t GetMethodAddress() const { |
| 5066 | DCHECK(HasMethodAddress()); |
| 5067 | return dispatch_info_.method_load_data; |
| 5068 | } |
| 5069 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 5070 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 5071 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5072 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 5073 | return GetPackedField<ClinitCheckRequirementField>(); |
| 5074 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 5075 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5076 | // Is this instruction a call to a static method? |
| 5077 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5078 | return GetInvokeType() == kStatic; |
| 5079 | } |
| 5080 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5081 | // Does this method load kind need the current method as an input? |
| 5082 | static bool NeedsCurrentMethodInput(DispatchInfo dispatch_info) { |
| 5083 | return dispatch_info.method_load_kind == MethodLoadKind::kRecursive || |
| 5084 | dispatch_info.method_load_kind == MethodLoadKind::kRuntimeCall || |
| 5085 | dispatch_info.code_ptr_location == CodePtrLocation::kCallCriticalNative; |
| 5086 | } |
| 5087 | |
| 5088 | // Get the index of the current method input. |
| 5089 | size_t GetCurrentMethodIndex() const { |
| 5090 | DCHECK(HasCurrentMethodInput()); |
| 5091 | return GetCurrentMethodIndexUnchecked(); |
| 5092 | } |
| 5093 | size_t GetCurrentMethodIndexUnchecked() const { |
| 5094 | return GetNumberOfArguments(); |
| 5095 | } |
| 5096 | |
| 5097 | // Check if the method has a current method input. |
| 5098 | bool HasCurrentMethodInput() const { |
| 5099 | if (NeedsCurrentMethodInput(GetDispatchInfo())) { |
| 5100 | DCHECK(InputAt(GetCurrentMethodIndexUnchecked()) == nullptr || // During argument setup. |
| 5101 | InputAt(GetCurrentMethodIndexUnchecked())->IsCurrentMethod()); |
| 5102 | return true; |
| 5103 | } else { |
| 5104 | DCHECK(InputCount() == GetCurrentMethodIndexUnchecked() || |
| 5105 | InputAt(GetCurrentMethodIndexUnchecked()) == nullptr || // During argument setup. |
| 5106 | !InputAt(GetCurrentMethodIndexUnchecked())->IsCurrentMethod()); |
| 5107 | return false; |
| 5108 | } |
| 5109 | } |
| 5110 | |
| 5111 | // Get the index of the special input. |
| 5112 | size_t GetSpecialInputIndex() const { |
| 5113 | DCHECK(HasSpecialInput()); |
| 5114 | return GetSpecialInputIndexUnchecked(); |
| 5115 | } |
| 5116 | size_t GetSpecialInputIndexUnchecked() const { |
| 5117 | return GetNumberOfArguments() + (HasCurrentMethodInput() ? 1u : 0u); |
| 5118 | } |
| 5119 | |
| 5120 | // Check if the method has a special input. |
| 5121 | bool HasSpecialInput() const { |
| 5122 | size_t other_inputs = |
| 5123 | GetSpecialInputIndexUnchecked() + (IsStaticWithExplicitClinitCheck() ? 1u : 0u); |
| 5124 | size_t input_count = InputCount(); |
| 5125 | DCHECK_LE(input_count - other_inputs, 1u) << other_inputs << " " << input_count; |
| 5126 | return other_inputs != input_count; |
| 5127 | } |
| 5128 | |
| 5129 | void AddSpecialInput(HInstruction* input) { |
| 5130 | // We allow only one special input. |
| 5131 | DCHECK(!HasSpecialInput()); |
| 5132 | InsertInputAt(GetSpecialInputIndexUnchecked(), input); |
| 5133 | } |
| 5134 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 5135 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 5136 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 5137 | // instruction; only relevant for static calls with explicit clinit check. |
| 5138 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5139 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5140 | size_t last_input_index = inputs_.size() - 1u; |
| 5141 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5142 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 5143 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5144 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5145 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5146 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 5147 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5148 | } |
| 5149 | |
| 5150 | // 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] | 5151 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5152 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5153 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5154 | } |
| 5155 | |
| 5156 | // Is this a call to a static method whose declaring class has an |
| 5157 | // implicit intialization check requirement? |
| 5158 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5159 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5160 | } |
| 5161 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 5162 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 5163 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5164 | protected: |
| 5165 | DEFAULT_COPY_CONSTRUCTOR(InvokeStaticOrDirect); |
| 5166 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 5167 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5168 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5169 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 5170 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 5171 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 5172 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 5173 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 5174 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5175 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 5176 | kFieldClinitCheckRequirement, |
| 5177 | kFieldClinitCheckRequirementSize>; |
| 5178 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5179 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 5180 | }; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5181 | std::ostream& operator<<(std::ostream& os, MethodLoadKind rhs); |
| 5182 | std::ostream& operator<<(std::ostream& os, CodePtrLocation rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 5183 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 5184 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5185 | class HInvokeVirtual final : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5186 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 5187 | HInvokeVirtual(ArenaAllocator* allocator, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5188 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5189 | DataType::Type return_type, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5190 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5191 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5192 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 5193 | MethodReference resolved_method_reference, |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 5194 | uint32_t vtable_index, |
| 5195 | bool enable_intrinsic_opt) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5196 | : HInvoke(kInvokeVirtual, |
| 5197 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5198 | number_of_arguments, |
| 5199 | 0u, |
| 5200 | return_type, |
| 5201 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5202 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5203 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 5204 | resolved_method_reference, |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 5205 | kVirtual, |
| 5206 | enable_intrinsic_opt), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5207 | vtable_index_(vtable_index) { |
| 5208 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5209 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5210 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5211 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5212 | bool CanBeNull() const override { |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 5213 | switch (GetIntrinsic()) { |
| 5214 | case Intrinsics::kThreadCurrentThread: |
| 5215 | case Intrinsics::kStringBufferAppend: |
| 5216 | case Intrinsics::kStringBufferToString: |
Vladimir Marko | d456117 | 2017-10-30 17:48:25 +0000 | [diff] [blame] | 5217 | case Intrinsics::kStringBuilderAppendObject: |
| 5218 | case Intrinsics::kStringBuilderAppendString: |
| 5219 | case Intrinsics::kStringBuilderAppendCharSequence: |
| 5220 | case Intrinsics::kStringBuilderAppendCharArray: |
| 5221 | case Intrinsics::kStringBuilderAppendBoolean: |
| 5222 | case Intrinsics::kStringBuilderAppendChar: |
| 5223 | case Intrinsics::kStringBuilderAppendInt: |
| 5224 | case Intrinsics::kStringBuilderAppendLong: |
| 5225 | case Intrinsics::kStringBuilderAppendFloat: |
| 5226 | case Intrinsics::kStringBuilderAppendDouble: |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 5227 | case Intrinsics::kStringBuilderToString: |
| 5228 | return false; |
| 5229 | default: |
| 5230 | return HInvoke::CanBeNull(); |
| 5231 | } |
| 5232 | } |
| 5233 | |
Vladimir Marko | ac27ac0 | 2021-02-01 09:31:02 +0000 | [diff] [blame] | 5234 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5235 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5236 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 5237 | |
| 5238 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 5239 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5240 | protected: |
| 5241 | DEFAULT_COPY_CONSTRUCTOR(InvokeVirtual); |
| 5242 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5243 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5244 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5245 | const uint32_t vtable_index_; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5246 | }; |
| 5247 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5248 | class HInvokeInterface final : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5249 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 5250 | HInvokeInterface(ArenaAllocator* allocator, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5251 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5252 | DataType::Type return_type, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5253 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5254 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5255 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 5256 | MethodReference resolved_method_reference, |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5257 | uint32_t imt_index, |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 5258 | MethodLoadKind load_kind, |
| 5259 | bool enable_intrinsic_opt) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5260 | : HInvoke(kInvokeInterface, |
| 5261 | allocator, |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5262 | number_of_arguments + (NeedsCurrentMethod(load_kind) ? 1 : 0), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5263 | 0u, |
| 5264 | return_type, |
| 5265 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5266 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5267 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 5268 | resolved_method_reference, |
Mythri Alle | d60aff5 | 2023-04-26 12:56:36 +0000 | [diff] [blame] | 5269 | kInterface, |
| 5270 | enable_intrinsic_opt), |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5271 | imt_index_(imt_index), |
| 5272 | hidden_argument_load_kind_(load_kind) { |
| 5273 | } |
| 5274 | |
| 5275 | static bool NeedsCurrentMethod(MethodLoadKind load_kind) { |
| 5276 | return load_kind == MethodLoadKind::kRecursive; |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5277 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5278 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5279 | bool IsClonable() const override { return true; } |
Santiago Aboy Solanes | e43aa3f | 2021-11-01 09:02:09 +0000 | [diff] [blame] | 5280 | bool NeedsBss() const override { |
| 5281 | return GetHiddenArgumentLoadKind() == MethodLoadKind::kBssEntry; |
| 5282 | } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5283 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5284 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5285 | // TODO: Add implicit null checks in intrinsics. |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 5286 | return (obj == InputAt(0)) && !IsIntrinsic(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5287 | } |
| 5288 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5289 | size_t GetSpecialInputIndex() const { |
| 5290 | return GetNumberOfArguments(); |
| 5291 | } |
| 5292 | |
| 5293 | void AddSpecialInput(HInstruction* input) { |
| 5294 | InsertInputAt(GetSpecialInputIndex(), input); |
| 5295 | } |
| 5296 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5297 | uint32_t GetImtIndex() const { return imt_index_; } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5298 | MethodLoadKind GetHiddenArgumentLoadKind() const { return hidden_argument_load_kind_; } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5299 | |
| 5300 | DECLARE_INSTRUCTION(InvokeInterface); |
| 5301 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5302 | protected: |
| 5303 | DEFAULT_COPY_CONSTRUCTOR(InvokeInterface); |
| 5304 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5305 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5306 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5307 | const uint32_t imt_index_; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5308 | |
| 5309 | // How the hidden argument (the interface method) is being loaded. |
| 5310 | const MethodLoadKind hidden_argument_load_kind_; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5311 | }; |
| 5312 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5313 | class HNeg final : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5314 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5315 | 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] | 5316 | : HUnaryOperation(kNeg, result_type, input, dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5317 | DCHECK_EQ(result_type, DataType::Kind(input->GetType())); |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 5318 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5319 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5320 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5321 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5322 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5323 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5324 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5325 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5326 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5327 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5328 | HConstant* Evaluate(HFloatConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5329 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 5330 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5331 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5332 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 5333 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 5334 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5335 | DECLARE_INSTRUCTION(Neg); |
| 5336 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5337 | protected: |
| 5338 | DEFAULT_COPY_CONSTRUCTOR(Neg); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5339 | }; |
| 5340 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5341 | class HNewArray final : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5342 | public: |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5343 | 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] | 5344 | : HExpression(kNewArray, DataType::Type::kReference, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5345 | SetRawInputAt(0, cls); |
| 5346 | SetRawInputAt(1, length); |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5347 | SetPackedField<ComponentSizeShiftField>(component_size_shift); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5348 | } |
| 5349 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5350 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5351 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5352 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5353 | bool NeedsEnvironment() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5354 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 5355 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5356 | bool CanThrow() const override { return true; } |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 5357 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5358 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5359 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5360 | HLoadClass* GetLoadClass() const { |
| 5361 | DCHECK(InputAt(0)->IsLoadClass()); |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 5362 | return InputAt(0)->AsLoadClass(); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | HInstruction* GetLength() const { |
| 5366 | return InputAt(1); |
| 5367 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 5368 | |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5369 | size_t GetComponentSizeShift() { |
| 5370 | return GetPackedField<ComponentSizeShiftField>(); |
| 5371 | } |
| 5372 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5373 | DECLARE_INSTRUCTION(NewArray); |
| 5374 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5375 | protected: |
| 5376 | DEFAULT_COPY_CONSTRUCTOR(NewArray); |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5377 | |
| 5378 | private: |
| 5379 | static constexpr size_t kFieldComponentSizeShift = kNumberOfGenericPackedBits; |
| 5380 | static constexpr size_t kFieldComponentSizeShiftSize = MinimumBitsToStore(3u); |
| 5381 | static constexpr size_t kNumberOfNewArrayPackedBits = |
| 5382 | kFieldComponentSizeShift + kFieldComponentSizeShiftSize; |
| 5383 | static_assert(kNumberOfNewArrayPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5384 | using ComponentSizeShiftField = |
Vladimir Marko | 1adb0de | 2023-03-03 09:16:24 +0000 | [diff] [blame] | 5385 | BitField<size_t, kFieldComponentSizeShift, kFieldComponentSizeShiftSize>; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5386 | }; |
| 5387 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5388 | class HAdd final : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5389 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5390 | HAdd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5391 | HInstruction* left, |
| 5392 | HInstruction* right, |
| 5393 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5394 | : HBinaryOperation(kAdd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5395 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5396 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5397 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5398 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5399 | 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] | 5400 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5401 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5402 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5403 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5404 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5405 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5406 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5407 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5408 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5409 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5410 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5411 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5412 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5413 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5414 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5415 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5416 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 5417 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5418 | DECLARE_INSTRUCTION(Add); |
| 5419 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5420 | protected: |
| 5421 | DEFAULT_COPY_CONSTRUCTOR(Add); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5422 | }; |
| 5423 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5424 | class HSub final : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5425 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5426 | HSub(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5427 | HInstruction* left, |
| 5428 | HInstruction* right, |
| 5429 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5430 | : HBinaryOperation(kSub, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5431 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5432 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5433 | 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] | 5434 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5435 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5436 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5437 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5438 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5439 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5440 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5441 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5442 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5443 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5444 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5445 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5446 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5447 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5448 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5449 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5450 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 5451 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5452 | DECLARE_INSTRUCTION(Sub); |
| 5453 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5454 | protected: |
| 5455 | DEFAULT_COPY_CONSTRUCTOR(Sub); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5456 | }; |
| 5457 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5458 | class HMul final : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5459 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5460 | HMul(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5461 | HInstruction* left, |
| 5462 | HInstruction* right, |
| 5463 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5464 | : HBinaryOperation(kMul, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5465 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5466 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5467 | bool IsCommutative() const override { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5468 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5469 | 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] | 5470 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5471 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5472 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5473 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5474 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5475 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5476 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5477 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5478 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5479 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5480 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5481 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5482 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5483 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5484 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5485 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5486 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5487 | |
| 5488 | DECLARE_INSTRUCTION(Mul); |
| 5489 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5490 | protected: |
| 5491 | DEFAULT_COPY_CONSTRUCTOR(Mul); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5492 | }; |
| 5493 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5494 | class HDiv final : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5495 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5496 | HDiv(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5497 | HInstruction* left, |
| 5498 | HInstruction* right, |
| 5499 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5500 | : HBinaryOperation(kDiv, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5501 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5502 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5503 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5504 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5505 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5506 | // Our graph structure ensures we never have 0 for `y` during |
| 5507 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5508 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5509 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5510 | return (y == -1) ? -x : x / y; |
| 5511 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5512 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5513 | template <typename T> |
| 5514 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5515 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5516 | return x / y; |
| 5517 | } |
| 5518 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5519 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5520 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5521 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5522 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5523 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5524 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5525 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5526 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5527 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5528 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5529 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5530 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5531 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5532 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5533 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5534 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5535 | |
| 5536 | DECLARE_INSTRUCTION(Div); |
| 5537 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5538 | protected: |
| 5539 | DEFAULT_COPY_CONSTRUCTOR(Div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5540 | }; |
| 5541 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5542 | class HRem final : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5543 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5544 | HRem(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5545 | HInstruction* left, |
| 5546 | HInstruction* right, |
| 5547 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5548 | : HBinaryOperation(kRem, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5549 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5550 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5551 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5552 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5553 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5554 | // Our graph structure ensures we never have 0 for `y` during |
| 5555 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5556 | DCHECK_NE(y, 0); |
| 5557 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 5558 | return (y == -1) ? 0 : x % y; |
| 5559 | } |
| 5560 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5561 | template <typename T> |
| 5562 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5563 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5564 | return std::fmod(x, y); |
| 5565 | } |
| 5566 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5567 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5568 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5569 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
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(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5572 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5573 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5574 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5575 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5576 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5577 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5578 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5579 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5580 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5581 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5582 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5583 | |
| 5584 | DECLARE_INSTRUCTION(Rem); |
| 5585 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5586 | protected: |
| 5587 | DEFAULT_COPY_CONSTRUCTOR(Rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5588 | }; |
| 5589 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5590 | class HMin final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5591 | public: |
| 5592 | HMin(DataType::Type result_type, |
| 5593 | HInstruction* left, |
| 5594 | HInstruction* right, |
| 5595 | uint32_t dex_pc) |
| 5596 | : HBinaryOperation(kMin, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5597 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5598 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5599 | |
| 5600 | // Evaluation for integral values. |
| 5601 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5602 | return (x <= y) ? x : y; |
| 5603 | } |
| 5604 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5605 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5606 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5607 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5608 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5609 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5610 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5611 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5612 | } |
| 5613 | // TODO: Evaluation for floating-point values. |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5614 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* x, |
| 5615 | [[maybe_unused]] HFloatConstant* y) const override { |
| 5616 | return nullptr; |
| 5617 | } |
| 5618 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* x, |
| 5619 | [[maybe_unused]] HDoubleConstant* y) const override { |
| 5620 | return nullptr; |
| 5621 | } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5622 | |
| 5623 | DECLARE_INSTRUCTION(Min); |
| 5624 | |
| 5625 | protected: |
| 5626 | DEFAULT_COPY_CONSTRUCTOR(Min); |
| 5627 | }; |
| 5628 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5629 | class HMax final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5630 | public: |
| 5631 | HMax(DataType::Type result_type, |
| 5632 | HInstruction* left, |
| 5633 | HInstruction* right, |
| 5634 | uint32_t dex_pc) |
| 5635 | : HBinaryOperation(kMax, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5636 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5637 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5638 | |
| 5639 | // Evaluation for integral values. |
| 5640 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5641 | return (x >= y) ? x : y; |
| 5642 | } |
| 5643 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5644 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5645 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5646 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5647 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5648 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5649 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5650 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5651 | } |
| 5652 | // TODO: Evaluation for floating-point values. |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5653 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* x, |
| 5654 | [[maybe_unused]] HFloatConstant* y) const override { |
| 5655 | return nullptr; |
| 5656 | } |
| 5657 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* x, |
| 5658 | [[maybe_unused]] HDoubleConstant* y) const override { |
| 5659 | return nullptr; |
| 5660 | } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5661 | |
| 5662 | DECLARE_INSTRUCTION(Max); |
| 5663 | |
| 5664 | protected: |
| 5665 | DEFAULT_COPY_CONSTRUCTOR(Max); |
| 5666 | }; |
| 5667 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5668 | class HAbs final : public HUnaryOperation { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5669 | public: |
| 5670 | HAbs(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5671 | : HUnaryOperation(kAbs, result_type, input, dex_pc) {} |
| 5672 | |
| 5673 | // Evaluation for integral values. |
| 5674 | template <typename T> static T ComputeIntegral(T x) { |
| 5675 | return x < 0 ? -x : x; |
| 5676 | } |
| 5677 | |
| 5678 | // Evaluation for floating-point values. |
| 5679 | // Note, as a "quality of implementation", rather than pure "spec compliance", |
| 5680 | // we require that Math.abs() clears the sign bit (but changes nothing else) |
| 5681 | // for all floating-point numbers, including NaN (signaling NaN may become quiet though). |
| 5682 | // http://b/30758343 |
| 5683 | template <typename T, typename S> static T ComputeFP(T x) { |
| 5684 | S bits = bit_cast<S, T>(x); |
| 5685 | return bit_cast<T, S>(bits & std::numeric_limits<S>::max()); |
| 5686 | } |
| 5687 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5688 | HConstant* Evaluate(HIntConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5689 | return GetBlock()->GetGraph()->GetIntConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5690 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5691 | HConstant* Evaluate(HLongConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5692 | return GetBlock()->GetGraph()->GetLongConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5693 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5694 | HConstant* Evaluate(HFloatConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5695 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5696 | ComputeFP<float, int32_t>(x->GetValue()), GetDexPc()); |
| 5697 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5698 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5699 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5700 | ComputeFP<double, int64_t>(x->GetValue()), GetDexPc()); |
| 5701 | } |
| 5702 | |
| 5703 | DECLARE_INSTRUCTION(Abs); |
| 5704 | |
| 5705 | protected: |
| 5706 | DEFAULT_COPY_CONSTRUCTOR(Abs); |
| 5707 | }; |
| 5708 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5709 | class HDivZeroCheck final : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5710 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 5711 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5712 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5713 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5714 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5715 | : HExpression(kDivZeroCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5716 | SetRawInputAt(0, value); |
| 5717 | } |
| 5718 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5719 | bool IsClonable() const override { return true; } |
| 5720 | bool CanBeMoved() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5721 | |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5722 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5723 | return true; |
| 5724 | } |
| 5725 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5726 | bool NeedsEnvironment() const override { return true; } |
| 5727 | bool CanThrow() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5728 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5729 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 5730 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5731 | protected: |
| 5732 | DEFAULT_COPY_CONSTRUCTOR(DivZeroCheck); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5733 | }; |
| 5734 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5735 | class HShl final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5736 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5737 | HShl(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5738 | HInstruction* value, |
| 5739 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5740 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5741 | : HBinaryOperation(kShl, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5742 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5743 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5744 | } |
| 5745 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5746 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5747 | 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] | 5748 | return value << (distance & max_shift_distance); |
| 5749 | } |
| 5750 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5751 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5752 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5753 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5754 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5755 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5756 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5757 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5758 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5759 | HConstant* Evaluate([[maybe_unused]] HLongConstant* value, |
| 5760 | [[maybe_unused]] HLongConstant* distance) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5761 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5762 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5763 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5764 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* value, |
| 5765 | [[maybe_unused]] HFloatConstant* distance) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5766 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5767 | UNREACHABLE(); |
| 5768 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5769 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* value, |
| 5770 | [[maybe_unused]] HDoubleConstant* distance) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5771 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5772 | UNREACHABLE(); |
| 5773 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5774 | |
| 5775 | DECLARE_INSTRUCTION(Shl); |
| 5776 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5777 | protected: |
| 5778 | DEFAULT_COPY_CONSTRUCTOR(Shl); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5779 | }; |
| 5780 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5781 | class HShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5782 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5783 | HShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5784 | HInstruction* value, |
| 5785 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5786 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5787 | : HBinaryOperation(kShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5788 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5789 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5790 | } |
| 5791 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5792 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5793 | 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] | 5794 | return value >> (distance & max_shift_distance); |
| 5795 | } |
| 5796 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5797 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5798 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5799 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5800 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5801 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5802 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5803 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5804 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5805 | HConstant* Evaluate([[maybe_unused]] HLongConstant* value, |
| 5806 | [[maybe_unused]] HLongConstant* distance) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5807 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5808 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5809 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5810 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* value, |
| 5811 | [[maybe_unused]] HFloatConstant* distance) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5812 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5813 | UNREACHABLE(); |
| 5814 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5815 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* value, |
| 5816 | [[maybe_unused]] HDoubleConstant* distance) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5817 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5818 | UNREACHABLE(); |
| 5819 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5820 | |
| 5821 | DECLARE_INSTRUCTION(Shr); |
| 5822 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5823 | protected: |
| 5824 | DEFAULT_COPY_CONSTRUCTOR(Shr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5825 | }; |
| 5826 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5827 | class HUShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5828 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5829 | HUShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5830 | HInstruction* value, |
| 5831 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5832 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5833 | : HBinaryOperation(kUShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5834 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5835 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5836 | } |
| 5837 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5838 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5839 | static T Compute(T value, int32_t distance, int32_t max_shift_distance) { |
Vladimir Marko | 4f99071 | 2021-07-14 12:45:13 +0100 | [diff] [blame] | 5840 | using V = std::make_unsigned_t<T>; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5841 | V ux = static_cast<V>(value); |
| 5842 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 5843 | } |
| 5844 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5845 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5846 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5847 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5848 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5849 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5850 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5851 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5852 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5853 | HConstant* Evaluate([[maybe_unused]] HLongConstant* value, |
| 5854 | [[maybe_unused]] HLongConstant* distance) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5855 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5856 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5857 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5858 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* value, |
| 5859 | [[maybe_unused]] HFloatConstant* distance) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5860 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5861 | UNREACHABLE(); |
| 5862 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5863 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* value, |
| 5864 | [[maybe_unused]] HDoubleConstant* distance) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5865 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5866 | UNREACHABLE(); |
| 5867 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5868 | |
| 5869 | DECLARE_INSTRUCTION(UShr); |
| 5870 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5871 | protected: |
| 5872 | DEFAULT_COPY_CONSTRUCTOR(UShr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5873 | }; |
| 5874 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5875 | class HAnd final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5876 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5877 | HAnd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5878 | HInstruction* left, |
| 5879 | HInstruction* right, |
| 5880 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5881 | : HBinaryOperation(kAnd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5882 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5883 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5884 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5885 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5886 | 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] | 5887 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5888 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5889 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5890 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5891 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5892 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5893 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5894 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5895 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5896 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* x, |
| 5897 | [[maybe_unused]] HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5898 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5899 | UNREACHABLE(); |
| 5900 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5901 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* x, |
| 5902 | [[maybe_unused]] HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5903 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5904 | UNREACHABLE(); |
| 5905 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5906 | |
| 5907 | DECLARE_INSTRUCTION(And); |
| 5908 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5909 | protected: |
| 5910 | DEFAULT_COPY_CONSTRUCTOR(And); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5911 | }; |
| 5912 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5913 | class HOr final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5914 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5915 | HOr(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5916 | HInstruction* left, |
| 5917 | HInstruction* right, |
| 5918 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5919 | : HBinaryOperation(kOr, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5920 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5921 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5922 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5923 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5924 | 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] | 5925 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5926 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5927 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5928 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5929 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5930 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5931 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5932 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5933 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5934 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* x, |
| 5935 | [[maybe_unused]] HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5936 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5937 | UNREACHABLE(); |
| 5938 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5939 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* x, |
| 5940 | [[maybe_unused]] HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5941 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5942 | UNREACHABLE(); |
| 5943 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5944 | |
| 5945 | DECLARE_INSTRUCTION(Or); |
| 5946 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5947 | protected: |
| 5948 | DEFAULT_COPY_CONSTRUCTOR(Or); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5949 | }; |
| 5950 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5951 | class HXor final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5952 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5953 | HXor(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5954 | HInstruction* left, |
| 5955 | HInstruction* right, |
| 5956 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5957 | : HBinaryOperation(kXor, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5958 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5959 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5960 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5961 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5962 | 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] | 5963 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5964 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5965 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5966 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5967 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5968 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5969 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5970 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5971 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5972 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* x, |
| 5973 | [[maybe_unused]] HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5974 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5975 | UNREACHABLE(); |
| 5976 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 5977 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* x, |
| 5978 | [[maybe_unused]] HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5979 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5980 | UNREACHABLE(); |
| 5981 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5982 | |
| 5983 | DECLARE_INSTRUCTION(Xor); |
| 5984 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5985 | protected: |
| 5986 | DEFAULT_COPY_CONSTRUCTOR(Xor); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5987 | }; |
| 5988 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5989 | class HRor final : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5990 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5991 | HRor(DataType::Type result_type, HInstruction* value, HInstruction* distance) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5992 | : HBinaryOperation(kRor, result_type, value, distance) { |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5993 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5994 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5995 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5996 | static T Compute(T value, int32_t distance, int32_t max_shift_value) { |
Vladimir Marko | 4f99071 | 2021-07-14 12:45:13 +0100 | [diff] [blame] | 5997 | using V = std::make_unsigned_t<T>; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5998 | V ux = static_cast<V>(value); |
| 5999 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6000 | return static_cast<T>(ux); |
| 6001 | } else { |
| 6002 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 6003 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 6004 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6005 | } |
| 6006 | } |
| 6007 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6008 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6009 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 6010 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6011 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6012 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6013 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 6014 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6015 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6016 | HConstant* Evaluate([[maybe_unused]] HLongConstant* value, |
| 6017 | [[maybe_unused]] HLongConstant* distance) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 6018 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 6019 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6020 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6021 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* value, |
| 6022 | [[maybe_unused]] HFloatConstant* distance) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6023 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 6024 | UNREACHABLE(); |
| 6025 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6026 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* value, |
| 6027 | [[maybe_unused]] HDoubleConstant* distance) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6028 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 6029 | UNREACHABLE(); |
| 6030 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6031 | |
| 6032 | DECLARE_INSTRUCTION(Ror); |
| 6033 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6034 | protected: |
| 6035 | DEFAULT_COPY_CONSTRUCTOR(Ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6036 | }; |
| 6037 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 6038 | // The value of a parameter in this method. Its location depends on |
| 6039 | // the calling convention. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6040 | class HParameterValue final : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 6041 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 6042 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6043 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 6044 | uint8_t index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6045 | DataType::Type parameter_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6046 | bool is_this = false) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6047 | : HExpression(kParameterValue, parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 6048 | dex_file_(dex_file), |
| 6049 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6050 | index_(index) { |
| 6051 | SetPackedFlag<kFlagIsThis>(is_this); |
| 6052 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 6053 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 6054 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 6055 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6056 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 6057 | uint8_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6058 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 6059 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6060 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6061 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 6062 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 6063 | DECLARE_INSTRUCTION(ParameterValue); |
| 6064 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6065 | protected: |
| 6066 | DEFAULT_COPY_CONSTRUCTOR(ParameterValue); |
| 6067 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 6068 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6069 | // Whether or not the parameter value corresponds to 'this' argument. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6070 | static constexpr size_t kFlagIsThis = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6071 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 6072 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 6073 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 6074 | "Too many packed fields."); |
| 6075 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 6076 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6077 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 6078 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 6079 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 6080 | const uint8_t index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 6081 | }; |
| 6082 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6083 | class HNot final : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 6084 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6085 | 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] | 6086 | : HUnaryOperation(kNot, result_type, input, dex_pc) { |
| 6087 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 6088 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6089 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6090 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6091 | return true; |
| 6092 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6093 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 6094 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 6095 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6096 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6097 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 6098 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6099 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6100 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 6101 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6102 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6103 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 6104 | UNREACHABLE(); |
| 6105 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6106 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6107 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 6108 | UNREACHABLE(); |
| 6109 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 6110 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 6111 | DECLARE_INSTRUCTION(Not); |
| 6112 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6113 | protected: |
| 6114 | DEFAULT_COPY_CONSTRUCTOR(Not); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 6115 | }; |
| 6116 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6117 | class HBooleanNot final : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6118 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6119 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6120 | : HUnaryOperation(kBooleanNot, DataType::Type::kBool, input, dex_pc) { |
| 6121 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6122 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6123 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6124 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6125 | return true; |
| 6126 | } |
| 6127 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 6128 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6129 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6130 | return !x; |
| 6131 | } |
| 6132 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6133 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6134 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 6135 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6136 | HConstant* Evaluate([[maybe_unused]] HLongConstant* x) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 6137 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6138 | UNREACHABLE(); |
| 6139 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6140 | HConstant* Evaluate([[maybe_unused]] HFloatConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6141 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 6142 | UNREACHABLE(); |
| 6143 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6144 | HConstant* Evaluate([[maybe_unused]] HDoubleConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6145 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 6146 | UNREACHABLE(); |
| 6147 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6148 | |
| 6149 | DECLARE_INSTRUCTION(BooleanNot); |
| 6150 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6151 | protected: |
| 6152 | DEFAULT_COPY_CONSTRUCTOR(BooleanNot); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6153 | }; |
| 6154 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6155 | class HTypeConversion final : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6156 | public: |
| 6157 | // Instantiate a type conversion of `input` to `result_type`. |
Vladimir Marko | c8fb211 | 2017-10-03 11:37:52 +0100 | [diff] [blame] | 6158 | 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] | 6159 | : HExpression(kTypeConversion, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6160 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 6161 | // Invariant: We should never generate a conversion to a Boolean value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6162 | DCHECK_NE(DataType::Type::kBool, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6163 | } |
| 6164 | |
| 6165 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6166 | DataType::Type GetInputType() const { return GetInput()->GetType(); } |
| 6167 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6168 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6169 | bool IsClonable() const override { return true; } |
| 6170 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6171 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6172 | return true; |
| 6173 | } |
Nicolas Geoffray | acc56ac | 2018-10-09 08:45:24 +0100 | [diff] [blame] | 6174 | // Return whether the conversion is implicit. This includes conversion to the same type. |
| 6175 | bool IsImplicitConversion() const { |
| 6176 | return DataType::IsTypeConversionImplicit(GetInputType(), GetResultType()); |
| 6177 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6178 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 6179 | // Try to statically evaluate the conversion and return a HConstant |
| 6180 | // containing the result. If the input cannot be converted, return nullptr. |
| 6181 | HConstant* TryStaticEvaluation() const; |
| 6182 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6183 | DECLARE_INSTRUCTION(TypeConversion); |
| 6184 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6185 | protected: |
| 6186 | DEFAULT_COPY_CONSTRUCTOR(TypeConversion); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6187 | }; |
| 6188 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 6189 | static constexpr uint32_t kNoRegNumber = -1; |
| 6190 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6191 | class HNullCheck final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6192 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 6193 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6194 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 6195 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6196 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6197 | : HExpression(kNullCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6198 | SetRawInputAt(0, value); |
| 6199 | } |
| 6200 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6201 | bool IsClonable() const override { return true; } |
| 6202 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6203 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6204 | return true; |
| 6205 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6206 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6207 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6208 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6209 | bool CanThrow() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 6210 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6211 | bool CanBeNull() const override { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 6212 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6213 | DECLARE_INSTRUCTION(NullCheck); |
| 6214 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6215 | protected: |
| 6216 | DEFAULT_COPY_CONSTRUCTOR(NullCheck); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6217 | }; |
| 6218 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6219 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 6220 | // 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] | 6221 | class FieldInfo : public ValueObject { |
| 6222 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6223 | FieldInfo(ArtField* field, |
| 6224 | MemberOffset field_offset, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6225 | DataType::Type field_type, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6226 | bool is_volatile, |
| 6227 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6228 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6229 | const DexFile& dex_file) |
| 6230 | : field_(field), |
| 6231 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6232 | field_type_(field_type), |
| 6233 | is_volatile_(is_volatile), |
| 6234 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6235 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6236 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6237 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6238 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6239 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6240 | DataType::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6241 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6242 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6243 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6244 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6245 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6246 | bool Equals(const FieldInfo& other) const { |
| 6247 | return field_ == other.field_ && |
| 6248 | field_offset_ == other.field_offset_ && |
| 6249 | field_type_ == other.field_type_ && |
| 6250 | is_volatile_ == other.is_volatile_ && |
| 6251 | index_ == other.index_ && |
| 6252 | declaring_class_def_index_ == other.declaring_class_def_index_ && |
| 6253 | &dex_file_ == &other.dex_file_; |
| 6254 | } |
| 6255 | |
| 6256 | std::ostream& Dump(std::ostream& os) const { |
| 6257 | os << field_ << ", off: " << field_offset_ << ", type: " << field_type_ |
| 6258 | << ", volatile: " << std::boolalpha << is_volatile_ << ", index_: " << std::dec << index_ |
| 6259 | << ", declaring_class: " << declaring_class_def_index_ << ", dex: " << dex_file_; |
| 6260 | return os; |
| 6261 | } |
| 6262 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6263 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6264 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6265 | const MemberOffset field_offset_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6266 | const DataType::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6267 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6268 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6269 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6270 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6271 | }; |
| 6272 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6273 | inline bool operator==(const FieldInfo& a, const FieldInfo& b) { |
| 6274 | return a.Equals(b); |
| 6275 | } |
| 6276 | |
| 6277 | inline std::ostream& operator<<(std::ostream& os, const FieldInfo& a) { |
| 6278 | return a.Dump(os); |
| 6279 | } |
| 6280 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6281 | class HInstanceFieldGet final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6282 | public: |
| 6283 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6284 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6285 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6286 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6287 | bool is_volatile, |
| 6288 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6289 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6290 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6291 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6292 | : HExpression(kInstanceFieldGet, |
| 6293 | field_type, |
| 6294 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 6295 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6296 | field_info_(field, |
| 6297 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6298 | field_type, |
| 6299 | is_volatile, |
| 6300 | field_idx, |
| 6301 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6302 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6303 | SetRawInputAt(0, value); |
| 6304 | } |
| 6305 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6306 | bool IsClonable() const override { return true; } |
| 6307 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6308 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6309 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 6310 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6311 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6312 | } |
| 6313 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6314 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 6315 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6316 | } |
| 6317 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6318 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 6319 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6320 | } |
| 6321 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6322 | bool IsFieldAccess() const override { return true; } |
| 6323 | const FieldInfo& GetFieldInfo() const override { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6324 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6325 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6326 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6327 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6328 | void SetType(DataType::Type new_type) { |
| 6329 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6330 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6331 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6332 | SetPackedField<TypeField>(new_type); |
| 6333 | } |
| 6334 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6335 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 6336 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6337 | protected: |
| 6338 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldGet); |
| 6339 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6340 | private: |
| 6341 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6342 | }; |
| 6343 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6344 | class HPredicatedInstanceFieldGet final : public HExpression<2> { |
| 6345 | public: |
| 6346 | HPredicatedInstanceFieldGet(HInstanceFieldGet* orig, |
| 6347 | HInstruction* target, |
| 6348 | HInstruction* default_val) |
| 6349 | : HExpression(kPredicatedInstanceFieldGet, |
| 6350 | orig->GetFieldType(), |
| 6351 | orig->GetSideEffects(), |
| 6352 | orig->GetDexPc()), |
| 6353 | field_info_(orig->GetFieldInfo()) { |
| 6354 | // NB Default-val is at 0 so we can avoid doing a move. |
| 6355 | SetRawInputAt(1, target); |
| 6356 | SetRawInputAt(0, default_val); |
| 6357 | } |
| 6358 | |
| 6359 | HPredicatedInstanceFieldGet(HInstruction* value, |
| 6360 | ArtField* field, |
| 6361 | HInstruction* default_value, |
| 6362 | DataType::Type field_type, |
| 6363 | MemberOffset field_offset, |
| 6364 | bool is_volatile, |
| 6365 | uint32_t field_idx, |
| 6366 | uint16_t declaring_class_def_index, |
| 6367 | const DexFile& dex_file, |
| 6368 | uint32_t dex_pc) |
| 6369 | : HExpression(kPredicatedInstanceFieldGet, |
| 6370 | field_type, |
| 6371 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 6372 | dex_pc), |
| 6373 | field_info_(field, |
| 6374 | field_offset, |
| 6375 | field_type, |
| 6376 | is_volatile, |
| 6377 | field_idx, |
| 6378 | declaring_class_def_index, |
| 6379 | dex_file) { |
Alex Light | 7432805 | 2021-03-29 18:11:23 -0700 | [diff] [blame] | 6380 | SetRawInputAt(1, value); |
| 6381 | SetRawInputAt(0, default_value); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6382 | } |
| 6383 | |
| 6384 | bool IsClonable() const override { |
| 6385 | return true; |
| 6386 | } |
| 6387 | bool CanBeMoved() const override { |
| 6388 | return !IsVolatile(); |
| 6389 | } |
| 6390 | |
| 6391 | HInstruction* GetDefaultValue() const { |
| 6392 | return InputAt(0); |
| 6393 | } |
| 6394 | HInstruction* GetTarget() const { |
| 6395 | return InputAt(1); |
| 6396 | } |
| 6397 | |
| 6398 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 6399 | const HPredicatedInstanceFieldGet* other_get = other->AsPredicatedInstanceFieldGet(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6400 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue() && |
| 6401 | GetDefaultValue() == other_get->GetDefaultValue(); |
| 6402 | } |
| 6403 | |
| 6404 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
| 6405 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
| 6406 | } |
| 6407 | |
| 6408 | size_t ComputeHashCode() const override { |
| 6409 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6410 | } |
| 6411 | |
| 6412 | bool IsFieldAccess() const override { return true; } |
| 6413 | const FieldInfo& GetFieldInfo() const override { return field_info_; } |
| 6414 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 6415 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
| 6416 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
| 6417 | |
| 6418 | void SetType(DataType::Type new_type) { |
| 6419 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6420 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6421 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6422 | SetPackedField<TypeField>(new_type); |
| 6423 | } |
| 6424 | |
| 6425 | DECLARE_INSTRUCTION(PredicatedInstanceFieldGet); |
| 6426 | |
| 6427 | protected: |
| 6428 | DEFAULT_COPY_CONSTRUCTOR(PredicatedInstanceFieldGet); |
| 6429 | |
| 6430 | private: |
| 6431 | const FieldInfo field_info_; |
| 6432 | }; |
| 6433 | |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6434 | enum class WriteBarrierKind { |
| 6435 | // Emit the write barrier, with a runtime optimization which checks if the value that it is being |
| 6436 | // set is null. |
| 6437 | kEmitWithNullCheck, |
| 6438 | // Emit the write barrier, without the runtime null check optimization. This could be set because: |
| 6439 | // A) It is a write barrier for an ArraySet (which does the optimization with the type check, so |
| 6440 | // it never does the optimization at the write barrier stage) |
| 6441 | // B) We know that the input can't be null |
| 6442 | // C) This write barrier is actually several write barriers coalesced into one. Potentially we |
| 6443 | // could ask if every value is null for a runtime optimization at the cost of compile time / code |
| 6444 | // size. At the time of writing it was deemed not worth the effort. |
| 6445 | kEmitNoNullCheck, |
| 6446 | // Skip emitting the write barrier. This could be set because: |
| 6447 | // A) The write barrier is not needed (e.g. it is not a reference, or the value is the null |
| 6448 | // constant) |
| 6449 | // B) This write barrier was coalesced into another one so there's no need to emit it. |
| 6450 | kDontEmit, |
| 6451 | kLast = kDontEmit |
| 6452 | }; |
| 6453 | std::ostream& operator<<(std::ostream& os, WriteBarrierKind rhs); |
| 6454 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6455 | class HInstanceFieldSet final : public HExpression<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6456 | public: |
| 6457 | HInstanceFieldSet(HInstruction* object, |
| 6458 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6459 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6460 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6461 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6462 | bool is_volatile, |
| 6463 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6464 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6465 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6466 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6467 | : HExpression(kInstanceFieldSet, |
| 6468 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 6469 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6470 | field_info_(field, |
| 6471 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6472 | field_type, |
| 6473 | is_volatile, |
| 6474 | field_idx, |
| 6475 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6476 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6477 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6478 | SetPackedFlag<kFlagIsPredicatedSet>(false); |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6479 | SetPackedField<WriteBarrierKindField>(WriteBarrierKind::kEmitWithNullCheck); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6480 | SetRawInputAt(0, object); |
| 6481 | SetRawInputAt(1, value); |
| 6482 | } |
| 6483 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6484 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6485 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6486 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 6487 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6488 | } |
| 6489 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6490 | bool IsFieldAccess() const override { return true; } |
| 6491 | const FieldInfo& GetFieldInfo() const override { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6492 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6493 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6494 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6495 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6496 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6497 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6498 | bool GetIsPredicatedSet() const { return GetPackedFlag<kFlagIsPredicatedSet>(); } |
| 6499 | void SetIsPredicatedSet(bool value = true) { SetPackedFlag<kFlagIsPredicatedSet>(value); } |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6500 | WriteBarrierKind GetWriteBarrierKind() { return GetPackedField<WriteBarrierKindField>(); } |
| 6501 | void SetWriteBarrierKind(WriteBarrierKind kind) { |
| 6502 | DCHECK(kind != WriteBarrierKind::kEmitWithNullCheck) |
| 6503 | << "We shouldn't go back to the original value."; |
| 6504 | SetPackedField<WriteBarrierKindField>(kind); |
| 6505 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6506 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6507 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 6508 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6509 | protected: |
| 6510 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldSet); |
| 6511 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6512 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6513 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6514 | static constexpr size_t kFlagIsPredicatedSet = kFlagValueCanBeNull + 1; |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6515 | static constexpr size_t kWriteBarrierKind = kFlagIsPredicatedSet + 1; |
| 6516 | static constexpr size_t kWriteBarrierKindSize = |
| 6517 | MinimumBitsToStore(static_cast<size_t>(WriteBarrierKind::kLast)); |
| 6518 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = |
| 6519 | kWriteBarrierKind + kWriteBarrierKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6520 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6521 | "Too many packed fields."); |
| 6522 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6523 | const FieldInfo field_info_; |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6524 | using WriteBarrierKindField = |
| 6525 | BitField<WriteBarrierKind, kWriteBarrierKind, kWriteBarrierKindSize>; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6526 | }; |
| 6527 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6528 | class HArrayGet final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6529 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6530 | HArrayGet(HInstruction* array, |
| 6531 | HInstruction* index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6532 | DataType::Type type, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6533 | uint32_t dex_pc) |
| 6534 | : HArrayGet(array, |
| 6535 | index, |
| 6536 | type, |
| 6537 | SideEffects::ArrayReadOfType(type), |
| 6538 | dex_pc, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6539 | /* is_string_char_at= */ false) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6540 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6541 | |
| 6542 | HArrayGet(HInstruction* array, |
| 6543 | HInstruction* index, |
| 6544 | DataType::Type type, |
| 6545 | SideEffects side_effects, |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6546 | uint32_t dex_pc, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6547 | bool is_string_char_at) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6548 | : HExpression(kArrayGet, type, side_effects, dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6549 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6550 | SetRawInputAt(0, array); |
| 6551 | SetRawInputAt(1, index); |
| 6552 | } |
| 6553 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6554 | bool IsClonable() const override { return true; } |
| 6555 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6556 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6557 | return true; |
| 6558 | } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6559 | bool CanDoImplicitNullCheckOn([[maybe_unused]] HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6560 | // TODO: We can be smarter here. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6561 | // Currently, unless the array is the result of NewArray, the array access is always |
| 6562 | // preceded by some form of null NullCheck necessary for the bounds check, usually |
| 6563 | // implicit null check on the ArrayLength input to BoundsCheck or Deoptimize for |
| 6564 | // dynamic BCE. There are cases when these could be removed to produce better code. |
| 6565 | // If we ever add optimizations to do so we should allow an implicit check here |
| 6566 | // (as long as the address falls in the first page). |
| 6567 | // |
| 6568 | // As an example of such fancy optimization, we could eliminate BoundsCheck for |
| 6569 | // a = cond ? new int[1] : null; |
| 6570 | // a[0]; // The Phi does not need bounds check for either input. |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6571 | return false; |
| 6572 | } |
| 6573 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 6574 | bool IsEquivalentOf(HArrayGet* other) const { |
| 6575 | bool result = (GetDexPc() == other->GetDexPc()); |
| 6576 | if (kIsDebugBuild && result) { |
| 6577 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 6578 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 6579 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6580 | if (DataType::IsIntOrLongType(GetType())) { |
| 6581 | DCHECK(DataType::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 6582 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6583 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| 6584 | DCHECK(DataType::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 6585 | } |
| 6586 | } |
| 6587 | return result; |
| 6588 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6589 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6590 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 6591 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6592 | HInstruction* GetArray() const { return InputAt(0); } |
| 6593 | HInstruction* GetIndex() const { return InputAt(1); } |
| 6594 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6595 | void SetType(DataType::Type new_type) { |
| 6596 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6597 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6598 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6599 | SetPackedField<TypeField>(new_type); |
| 6600 | } |
| 6601 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6602 | DECLARE_INSTRUCTION(ArrayGet); |
| 6603 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6604 | protected: |
| 6605 | DEFAULT_COPY_CONSTRUCTOR(ArrayGet); |
| 6606 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6607 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6608 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 6609 | // intrinsic in the instruction simplifier. We can always determine whether |
| 6610 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 6611 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 6612 | // 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] | 6613 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6614 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 6615 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6616 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6617 | }; |
| 6618 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6619 | class HArraySet final : public HExpression<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6620 | public: |
| 6621 | HArraySet(HInstruction* array, |
| 6622 | HInstruction* index, |
| 6623 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6624 | DataType::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 6625 | uint32_t dex_pc) |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6626 | : HArraySet(array, |
| 6627 | index, |
| 6628 | value, |
| 6629 | expected_component_type, |
| 6630 | // Make a best guess for side effects now, may be refined during SSA building. |
| 6631 | ComputeSideEffects(GetComponentType(value->GetType(), expected_component_type)), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6632 | dex_pc) { |
| 6633 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6634 | |
| 6635 | HArraySet(HInstruction* array, |
| 6636 | HInstruction* index, |
| 6637 | HInstruction* value, |
| 6638 | DataType::Type expected_component_type, |
| 6639 | SideEffects side_effects, |
| 6640 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6641 | : HExpression(kArraySet, side_effects, dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6642 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6643 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6644 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 6645 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6646 | // ArraySets never do the null check optimization at the write barrier stage. |
| 6647 | SetPackedField<WriteBarrierKindField>(WriteBarrierKind::kEmitNoNullCheck); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6648 | SetRawInputAt(0, array); |
| 6649 | SetRawInputAt(1, index); |
| 6650 | SetRawInputAt(2, value); |
| 6651 | } |
| 6652 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6653 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6654 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6655 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6656 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6657 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6658 | } |
| 6659 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 6660 | // Can throw ArrayStoreException. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6661 | bool CanThrow() const override { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 6662 | |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6663 | bool CanDoImplicitNullCheckOn([[maybe_unused]] HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6664 | // TODO: Same as for ArrayGet. |
| 6665 | return false; |
| 6666 | } |
| 6667 | |
Santiago Aboy Solanes | 13c3ce1 | 2022-12-05 12:05:43 +0000 | [diff] [blame] | 6668 | void ClearTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6669 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Santiago Aboy Solanes | 13c3ce1 | 2022-12-05 12:05:43 +0000 | [diff] [blame] | 6670 | // Clear the `CanTriggerGC` flag too as we can only trigger a GC when doing a type check. |
| 6671 | SetSideEffects(GetSideEffects().Exclusion(SideEffects::CanTriggerGC())); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6672 | } |
| 6673 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6674 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6675 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6676 | } |
| 6677 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6678 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6679 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6680 | } |
| 6681 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6682 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6683 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 6684 | bool StaticTypeOfArrayIsObjectArray() const { |
| 6685 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 6686 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6687 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6688 | HInstruction* GetArray() const { return InputAt(0); } |
| 6689 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6690 | HInstruction* GetValue() const { return InputAt(2); } |
| 6691 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6692 | DataType::Type GetComponentType() const { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6693 | return GetComponentType(GetValue()->GetType(), GetRawExpectedComponentType()); |
| 6694 | } |
| 6695 | |
| 6696 | static DataType::Type GetComponentType(DataType::Type value_type, |
| 6697 | DataType::Type expected_component_type) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6698 | // The Dex format does not type floating point index operations. Since the |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6699 | // `expected_component_type` comes from SSA building and can therefore not |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6700 | // be correct, we also check what is the value type. If it is a floating |
| 6701 | // point type, we must use that type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6702 | return ((value_type == DataType::Type::kFloat32) || (value_type == DataType::Type::kFloat64)) |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6703 | ? value_type |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6704 | : expected_component_type; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6705 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6706 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6707 | DataType::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6708 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6709 | } |
| 6710 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6711 | static SideEffects ComputeSideEffects(DataType::Type type) { |
| 6712 | return SideEffects::ArrayWriteOfType(type).Union(SideEffectsForArchRuntimeCalls(type)); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 6713 | } |
| 6714 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6715 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type value_type) { |
| 6716 | return (value_type == DataType::Type::kReference) ? SideEffects::CanTriggerGC() |
| 6717 | : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6718 | } |
| 6719 | |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6720 | WriteBarrierKind GetWriteBarrierKind() { return GetPackedField<WriteBarrierKindField>(); } |
| 6721 | |
| 6722 | void SetWriteBarrierKind(WriteBarrierKind kind) { |
| 6723 | DCHECK(kind != WriteBarrierKind::kEmitNoNullCheck) |
| 6724 | << "We shouldn't go back to the original value."; |
| 6725 | DCHECK(kind != WriteBarrierKind::kEmitWithNullCheck) |
| 6726 | << "We never do the null check optimization for ArraySets."; |
| 6727 | SetPackedField<WriteBarrierKindField>(kind); |
| 6728 | } |
| 6729 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6730 | DECLARE_INSTRUCTION(ArraySet); |
| 6731 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6732 | protected: |
| 6733 | DEFAULT_COPY_CONSTRUCTOR(ArraySet); |
| 6734 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6735 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6736 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 6737 | static constexpr size_t kFieldExpectedComponentTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6738 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6739 | static constexpr size_t kFlagNeedsTypeCheck = |
| 6740 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 6741 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6742 | // Cached information for the reference_type_info_ so that codegen |
| 6743 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6744 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6745 | static constexpr size_t kWriteBarrierKind = kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 6746 | static constexpr size_t kWriteBarrierKindSize = |
| 6747 | MinimumBitsToStore(static_cast<size_t>(WriteBarrierKind::kLast)); |
| 6748 | static constexpr size_t kNumberOfArraySetPackedBits = kWriteBarrierKind + kWriteBarrierKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6749 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6750 | using ExpectedComponentTypeField = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6751 | BitField<DataType::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6752 | |
| 6753 | using WriteBarrierKindField = |
| 6754 | BitField<WriteBarrierKind, kWriteBarrierKind, kWriteBarrierKindSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6755 | }; |
| 6756 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6757 | class HArrayLength final : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6758 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6759 | 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] | 6760 | : HExpression(kArrayLength, DataType::Type::kInt32, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6761 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6762 | // Note that arrays do not change length, so the instruction does not |
| 6763 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6764 | SetRawInputAt(0, array); |
| 6765 | } |
| 6766 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6767 | bool IsClonable() const override { return true; } |
| 6768 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6769 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6770 | return true; |
| 6771 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6772 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 6773 | return obj == InputAt(0); |
| 6774 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6775 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6776 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 6777 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6778 | DECLARE_INSTRUCTION(ArrayLength); |
| 6779 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6780 | protected: |
| 6781 | DEFAULT_COPY_CONSTRUCTOR(ArrayLength); |
| 6782 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6783 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6784 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 6785 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 6786 | // determine whether a particular HArrayLength is actually a String.length() by |
| 6787 | // looking at the type of the input but that requires holding the mutator lock, so |
| 6788 | // 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] | 6789 | static constexpr size_t kFlagIsStringLength = kNumberOfGenericPackedBits; |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6790 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 6791 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6792 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6793 | }; |
| 6794 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6795 | class HBoundsCheck final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6796 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 6797 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6798 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 6799 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6800 | HBoundsCheck(HInstruction* index, |
| 6801 | HInstruction* length, |
| 6802 | uint32_t dex_pc, |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6803 | bool is_string_char_at = false) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6804 | : HExpression(kBoundsCheck, index->GetType(), SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6805 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(index->GetType())); |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6806 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6807 | SetRawInputAt(0, index); |
| 6808 | SetRawInputAt(1, length); |
| 6809 | } |
| 6810 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6811 | bool IsClonable() const override { return true; } |
| 6812 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 6813 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6814 | return true; |
| 6815 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6816 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6817 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6818 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6819 | bool CanThrow() const override { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 6820 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 6821 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6822 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6823 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6824 | |
| 6825 | DECLARE_INSTRUCTION(BoundsCheck); |
| 6826 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6827 | protected: |
| 6828 | DEFAULT_COPY_CONSTRUCTOR(BoundsCheck); |
| 6829 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6830 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6831 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | f02046e | 2018-10-02 15:31:32 +0100 | [diff] [blame] | 6832 | static constexpr size_t kNumberOfBoundsCheckPackedBits = kFlagIsStringCharAt + 1; |
| 6833 | static_assert(kNumberOfBoundsCheckPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6834 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6835 | }; |
| 6836 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6837 | class HSuspendCheck final : public HExpression<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6838 | public: |
Stelios Ioannou | c54cc7c | 2021-07-09 17:06:03 +0100 | [diff] [blame] | 6839 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc, bool is_no_op = false) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6840 | : HExpression(kSuspendCheck, SideEffects::CanTriggerGC(), dex_pc), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6841 | slow_path_(nullptr) { |
Stelios Ioannou | c54cc7c | 2021-07-09 17:06:03 +0100 | [diff] [blame] | 6842 | SetPackedFlag<kFlagIsNoOp>(is_no_op); |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6843 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6844 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6845 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6846 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6847 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6848 | return true; |
| 6849 | } |
| 6850 | |
Stelios Ioannou | c54cc7c | 2021-07-09 17:06:03 +0100 | [diff] [blame] | 6851 | void SetIsNoOp(bool is_no_op) { SetPackedFlag<kFlagIsNoOp>(is_no_op); } |
| 6852 | bool IsNoOp() const { return GetPackedFlag<kFlagIsNoOp>(); } |
| 6853 | |
| 6854 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6855 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 6856 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6857 | |
| 6858 | DECLARE_INSTRUCTION(SuspendCheck); |
| 6859 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6860 | protected: |
| 6861 | DEFAULT_COPY_CONSTRUCTOR(SuspendCheck); |
| 6862 | |
Stelios Ioannou | c54cc7c | 2021-07-09 17:06:03 +0100 | [diff] [blame] | 6863 | // True if the HSuspendCheck should not emit any code during codegen. It is |
| 6864 | // not possible to simply remove this instruction to disable codegen, as |
| 6865 | // other optimizations (e.g: CHAGuardVisitor::HoistGuard) depend on |
| 6866 | // HSuspendCheck being present in every loop. |
| 6867 | static constexpr size_t kFlagIsNoOp = kNumberOfGenericPackedBits; |
| 6868 | static constexpr size_t kNumberOfSuspendCheckPackedBits = kFlagIsNoOp + 1; |
| 6869 | static_assert(kNumberOfSuspendCheckPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6870 | "Too many packed fields."); |
| 6871 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6872 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6873 | // Only used for code generation, in order to share the same slow path between back edges |
| 6874 | // of a same loop. |
| 6875 | SlowPathCode* slow_path_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6876 | }; |
| 6877 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 6878 | // Pseudo-instruction which doesn't generate any code. |
| 6879 | // If `emit_environment` is true, it can be used to generate an environment. It is used, for |
| 6880 | // example, to provide the native debugger with mapping information. It ensures that we can generate |
| 6881 | // line number and local variables at this point. |
| 6882 | class HNop : public HExpression<0> { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6883 | public: |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 6884 | explicit HNop(uint32_t dex_pc, bool needs_environment) |
| 6885 | : HExpression<0>(kNop, SideEffects::None(), dex_pc), needs_environment_(needs_environment) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6886 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6887 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6888 | bool NeedsEnvironment() const override { |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 6889 | return needs_environment_; |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6890 | } |
| 6891 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 6892 | DECLARE_INSTRUCTION(Nop); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6893 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6894 | protected: |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 6895 | DEFAULT_COPY_CONSTRUCTOR(Nop); |
| 6896 | |
| 6897 | private: |
| 6898 | bool needs_environment_; |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6899 | }; |
| 6900 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6901 | /** |
| 6902 | * Instruction to load a Class object. |
| 6903 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6904 | class HLoadClass final : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6905 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6906 | // Determines how to load the Class. |
| 6907 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6908 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 6909 | kInvalid = -1, |
| 6910 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6911 | // Use the Class* from the method's own ArtMethod*. |
| 6912 | kReferrersClass, |
| 6913 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6914 | // 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] | 6915 | // Used for boot image classes referenced by boot image code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6916 | kBootImageLinkTimePcRelative, |
| 6917 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6918 | // 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] | 6919 | // Used for boot image classes referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6920 | kBootImageRelRo, |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6921 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6922 | // 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] | 6923 | // 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] | 6924 | kBssEntry, |
| 6925 | |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6926 | // Load from an entry for public class in the .bss section using a PC-relative load. |
| 6927 | // Used for classes that were unresolved during AOT-compilation outside the literal |
| 6928 | // package of the compiling class. Such classes are accessible only if they are public |
| 6929 | // and the .bss entry shall therefore be filled only if the resolved class is public. |
| 6930 | kBssEntryPublic, |
| 6931 | |
| 6932 | // Load from an entry for package class in the .bss section using a PC-relative load. |
| 6933 | // Used for classes that were unresolved during AOT-compilation but within the literal |
| 6934 | // package of the compiling class. Such classes are accessible if they are public or |
| 6935 | // in the same package which, given the literal package match, requires only matching |
| 6936 | // defining class loader and the .bss entry shall therefore be filled only if at least |
| 6937 | // one of those conditions holds. Note that all code in an oat file belongs to classes |
| 6938 | // with the same defining class loader. |
| 6939 | kBssEntryPackage, |
| 6940 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6941 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 6942 | // Used for boot image classes referenced by apps in JIT-compiled code. |
| 6943 | kJitBootImageAddress, |
| 6944 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6945 | // Load from the root table associated with the JIT compiled method. |
| 6946 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6947 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6948 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6949 | // the codegen is unable to use another appropriate kind. |
| 6950 | kRuntimeCall, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6951 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6952 | kLast = kRuntimeCall |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6953 | }; |
| 6954 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6955 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6956 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6957 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6958 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6959 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6960 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6961 | bool needs_access_check) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6962 | : HInstruction(kLoadClass, |
| 6963 | DataType::Type::kReference, |
| 6964 | SideEffectsForArchRuntimeCalls(), |
| 6965 | dex_pc), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6966 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6967 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6968 | dex_file_(dex_file), |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6969 | klass_(klass) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 6970 | // Referrers class should not need access check. We never inline unverified |
| 6971 | // methods so we can't possibly end up in this situation. |
Santiago Aboy Solanes | 872ec72 | 2022-02-18 14:10:25 +0000 | [diff] [blame] | 6972 | DCHECK_IMPLIES(is_referrers_class, !needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6973 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6974 | SetPackedField<LoadKindField>( |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6975 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kRuntimeCall); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6976 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6977 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6978 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6979 | SetPackedFlag<kFlagValidLoadedClassRTI>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6980 | } |
| 6981 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6982 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6983 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6984 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6985 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6986 | LoadKind GetLoadKind() const { |
| 6987 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6988 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6989 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6990 | bool HasPcRelativeLoadKind() const { |
| 6991 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6992 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6993 | GetLoadKind() == LoadKind::kBssEntry || |
| 6994 | GetLoadKind() == LoadKind::kBssEntryPublic || |
| 6995 | GetLoadKind() == LoadKind::kBssEntryPackage; |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6996 | } |
| 6997 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6998 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6999 | |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame] | 7000 | bool InstructionDataEquals(const HInstruction* other) const override; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7001 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7002 | size_t ComputeHashCode() const override { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7003 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7004 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7005 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7006 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7007 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7008 | } |
Santiago Aboy Solanes | e43aa3f | 2021-11-01 09:02:09 +0000 | [diff] [blame] | 7009 | bool NeedsBss() const override { |
| 7010 | LoadKind load_kind = GetLoadKind(); |
| 7011 | return load_kind == LoadKind::kBssEntry || |
| 7012 | load_kind == LoadKind::kBssEntryPublic || |
| 7013 | load_kind == LoadKind::kBssEntryPackage; |
| 7014 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7015 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 7016 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7017 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7018 | } |
| 7019 | |
| 7020 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7021 | return NeedsAccessCheck() || |
| 7022 | MustGenerateClinitCheck() || |
Nicolas Geoffray | 358bb39 | 2023-07-25 12:42:58 +0100 | [diff] [blame] | 7023 | NeedsBss() || |
| 7024 | GetLoadKind() == LoadKind::kRuntimeCall; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7025 | } |
| 7026 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7027 | bool CanThrow() const override { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7028 | return NeedsAccessCheck() || |
| 7029 | MustGenerateClinitCheck() || |
| 7030 | // If the class is in the boot image, the lookup in the runtime call cannot throw. |
Nicolas Geoffray | 358bb39 | 2023-07-25 12:42:58 +0100 | [diff] [blame] | 7031 | ((GetLoadKind() == LoadKind::kRuntimeCall || NeedsBss()) && !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7032 | } |
| 7033 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 7034 | ReferenceTypeInfo GetLoadedClassRTI() { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7035 | if (GetPackedFlag<kFlagValidLoadedClassRTI>()) { |
| 7036 | // 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] | 7037 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact= */ true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7038 | } else { |
| 7039 | return ReferenceTypeInfo::CreateInvalid(); |
| 7040 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 7041 | } |
| 7042 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7043 | // Loaded class RTI is marked as valid by RTP if the klass_ is admissible. |
Vladimir Marko | ffafe8b | 2021-04-23 10:29:27 +0000 | [diff] [blame] | 7044 | void SetValidLoadedClassRTI() { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7045 | DCHECK(klass_ != nullptr); |
| 7046 | SetPackedFlag<kFlagValidLoadedClassRTI>(true); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 7047 | } |
| 7048 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7049 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7050 | const DexFile& GetDexFile() const { return dex_file_; } |
| 7051 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7052 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 7053 | return SideEffects::CanTriggerGC(); |
| 7054 | } |
| 7055 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7056 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7057 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7058 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7059 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7060 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7061 | bool MustResolveTypeOnSlowPath() const { |
| 7062 | // Check that this instruction has a slow path. |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7063 | LoadKind load_kind = GetLoadKind(); |
| 7064 | DCHECK(load_kind != LoadKind::kRuntimeCall); // kRuntimeCall calls on main path. |
| 7065 | bool must_resolve_type_on_slow_path = |
| 7066 | load_kind == LoadKind::kBssEntry || |
| 7067 | load_kind == LoadKind::kBssEntryPublic || |
| 7068 | load_kind == LoadKind::kBssEntryPackage; |
| 7069 | DCHECK(must_resolve_type_on_slow_path || MustGenerateClinitCheck()); |
| 7070 | return must_resolve_type_on_slow_path; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7071 | } |
| 7072 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7073 | void MarkInBootImage() { |
| 7074 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 7075 | } |
| 7076 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7077 | void AddSpecialInput(HInstruction* special_input); |
| 7078 | |
| 7079 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 7080 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7081 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 7082 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 7083 | } |
| 7084 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7085 | Handle<mirror::Class> GetClass() const { |
| 7086 | return klass_; |
| 7087 | } |
| 7088 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7089 | DECLARE_INSTRUCTION(LoadClass); |
| 7090 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7091 | protected: |
| 7092 | DEFAULT_COPY_CONSTRUCTOR(LoadClass); |
| 7093 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7094 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7095 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7096 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7097 | // Whether this instruction must generate the initialization check. |
| 7098 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7099 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7100 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 7101 | static constexpr size_t kFieldLoadKindSize = |
| 7102 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7103 | static constexpr size_t kFlagValidLoadedClassRTI = kFieldLoadKind + kFieldLoadKindSize; |
| 7104 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagValidLoadedClassRTI + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7105 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7106 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 7107 | |
| 7108 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7109 | return load_kind == LoadKind::kReferrersClass || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7110 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7111 | load_kind == LoadKind::kBssEntry || |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7112 | load_kind == LoadKind::kBssEntryPublic || |
| 7113 | load_kind == LoadKind::kBssEntryPackage || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7114 | load_kind == LoadKind::kRuntimeCall; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7115 | } |
| 7116 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7117 | void SetLoadKindInternal(LoadKind load_kind); |
| 7118 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7119 | // The special input is the HCurrentMethod for kRuntimeCall or kReferrersClass. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7120 | // 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] | 7121 | // for PC-relative loads, i.e. kBssEntry* or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7122 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7123 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7124 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 7125 | // - The compiling method's dex file if the class is defined there too. |
| 7126 | // - The compiling method's dex file if the class is referenced there. |
| 7127 | // - 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] | 7128 | // kBssEntry* or kRuntimeCall, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7129 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7130 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7131 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7132 | Handle<mirror::Class> klass_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7133 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7134 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 7135 | |
| 7136 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 7137 | inline void HLoadClass::SetLoadKind(LoadKind load_kind) { |
| 7138 | // The load kind should be determined before inserting the instruction to the graph. |
| 7139 | DCHECK(GetBlock() == nullptr); |
| 7140 | DCHECK(GetEnvironment() == nullptr); |
| 7141 | SetPackedField<LoadKindField>(load_kind); |
| 7142 | if (load_kind != LoadKind::kRuntimeCall && load_kind != LoadKind::kReferrersClass) { |
| 7143 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 7144 | } |
| 7145 | if (!NeedsEnvironment()) { |
| 7146 | SetSideEffects(SideEffects::None()); |
| 7147 | } |
| 7148 | } |
| 7149 | |
| 7150 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7151 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7152 | // The special input is used for PC-relative loads on some architectures, |
| 7153 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7154 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7155 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7156 | GetLoadKind() == LoadKind::kBssEntry || |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7157 | GetLoadKind() == LoadKind::kBssEntryPublic || |
| 7158 | GetLoadKind() == LoadKind::kBssEntryPackage || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7159 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7160 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 7161 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 7162 | special_input->AddUseAt(this, 0); |
| 7163 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7164 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7165 | class HLoadString final : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7166 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7167 | // Determines how to load the String. |
| 7168 | enum class LoadKind { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7169 | // 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] | 7170 | // Used for boot image strings referenced by boot image code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7171 | kBootImageLinkTimePcRelative, |
| 7172 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7173 | // 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] | 7174 | // Used for boot image strings referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7175 | kBootImageRelRo, |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7176 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7177 | // 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] | 7178 | // 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] | 7179 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7180 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7181 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 7182 | // Used for boot image strings referenced by apps in JIT-compiled code. |
| 7183 | kJitBootImageAddress, |
| 7184 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7185 | // Load from the root table associated with the JIT compiled method. |
| 7186 | kJitTableAddress, |
| 7187 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7188 | // Load using a simple runtime call. This is the fall-back load kind when |
| 7189 | // the codegen is unable to use another appropriate kind. |
| 7190 | kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7191 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7192 | kLast = kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7193 | }; |
| 7194 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 7195 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7196 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7197 | const DexFile& dex_file, |
| 7198 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7199 | : HInstruction(kLoadString, |
| 7200 | DataType::Type::kReference, |
| 7201 | SideEffectsForArchRuntimeCalls(), |
| 7202 | dex_pc), |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7203 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7204 | string_index_(string_index), |
| 7205 | dex_file_(dex_file) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7206 | SetPackedField<LoadKindField>(LoadKind::kRuntimeCall); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 7207 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7208 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7209 | bool IsClonable() const override { return true; } |
Santiago Aboy Solanes | e43aa3f | 2021-11-01 09:02:09 +0000 | [diff] [blame] | 7210 | bool NeedsBss() const override { |
| 7211 | return GetLoadKind() == LoadKind::kBssEntry; |
| 7212 | } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7213 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7214 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7215 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7216 | LoadKind GetLoadKind() const { |
| 7217 | return GetPackedField<LoadKindField>(); |
| 7218 | } |
| 7219 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7220 | bool HasPcRelativeLoadKind() const { |
| 7221 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 7222 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 7223 | GetLoadKind() == LoadKind::kBssEntry; |
| 7224 | } |
| 7225 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7226 | const DexFile& GetDexFile() const { |
| 7227 | return dex_file_; |
| 7228 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7229 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7230 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7231 | return string_index_; |
| 7232 | } |
| 7233 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7234 | Handle<mirror::String> GetString() const { |
| 7235 | return string_; |
| 7236 | } |
| 7237 | |
| 7238 | void SetString(Handle<mirror::String> str) { |
| 7239 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7240 | } |
| 7241 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7242 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7243 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7244 | bool InstructionDataEquals(const HInstruction* other) const override; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7245 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7246 | size_t ComputeHashCode() const override { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7247 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7248 | // Will call the runtime if we need to load the string through |
| 7249 | // 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] | 7250 | bool NeedsEnvironment() const override { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7251 | LoadKind load_kind = GetLoadKind(); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7252 | if (load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7253 | load_kind == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7254 | load_kind == LoadKind::kJitBootImageAddress || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7255 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7256 | return false; |
| 7257 | } |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 7258 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7259 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7260 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7261 | bool CanBeNull() const override { return false; } |
| 7262 | bool CanThrow() const override { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7263 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7264 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 7265 | return SideEffects::CanTriggerGC(); |
| 7266 | } |
| 7267 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7268 | void AddSpecialInput(HInstruction* special_input); |
| 7269 | |
| 7270 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 7271 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7272 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 7273 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7274 | } |
| 7275 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7276 | DECLARE_INSTRUCTION(LoadString); |
| 7277 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7278 | protected: |
| 7279 | DEFAULT_COPY_CONSTRUCTOR(LoadString); |
| 7280 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7281 | private: |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 7282 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7283 | static constexpr size_t kFieldLoadKindSize = |
| 7284 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 7285 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7286 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7287 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7288 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7289 | void SetLoadKindInternal(LoadKind load_kind); |
| 7290 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7291 | // The special input is the HCurrentMethod for kRuntimeCall. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7292 | // 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] | 7293 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7294 | HUserRecord<HInstruction*> special_input_; |
| 7295 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7296 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7297 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7298 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7299 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7300 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7301 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 7302 | |
| 7303 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 7304 | inline void HLoadString::SetLoadKind(LoadKind load_kind) { |
| 7305 | // The load kind should be determined before inserting the instruction to the graph. |
| 7306 | DCHECK(GetBlock() == nullptr); |
| 7307 | DCHECK(GetEnvironment() == nullptr); |
| 7308 | DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); |
| 7309 | SetPackedField<LoadKindField>(load_kind); |
| 7310 | if (load_kind != LoadKind::kRuntimeCall) { |
| 7311 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 7312 | } |
| 7313 | if (!NeedsEnvironment()) { |
| 7314 | SetSideEffects(SideEffects::None()); |
| 7315 | } |
| 7316 | } |
| 7317 | |
| 7318 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7319 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7320 | // The special input is used for PC-relative loads on some architectures, |
| 7321 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7322 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7323 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7324 | GetLoadKind() == LoadKind::kBssEntry || |
| 7325 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7326 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 7327 | // so use the GetInputRecords() from the base class to set the input record. |
| 7328 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 7329 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7330 | special_input->AddUseAt(this, 0); |
| 7331 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7332 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7333 | class HLoadMethodHandle final : public HInstruction { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7334 | public: |
| 7335 | HLoadMethodHandle(HCurrentMethod* current_method, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 7336 | uint16_t method_handle_idx, |
| 7337 | const DexFile& dex_file, |
| 7338 | uint32_t dex_pc) |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7339 | : HInstruction(kLoadMethodHandle, |
| 7340 | DataType::Type::kReference, |
| 7341 | SideEffectsForArchRuntimeCalls(), |
| 7342 | dex_pc), |
| 7343 | special_input_(HUserRecord<HInstruction*>(current_method)), |
| 7344 | method_handle_idx_(method_handle_idx), |
| 7345 | dex_file_(dex_file) { |
| 7346 | } |
| 7347 | |
| 7348 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 7349 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7350 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 7351 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 7352 | } |
| 7353 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7354 | bool IsClonable() const override { return true; } |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7355 | |
| 7356 | uint16_t GetMethodHandleIndex() const { return method_handle_idx_; } |
| 7357 | |
| 7358 | const DexFile& GetDexFile() const { return dex_file_; } |
| 7359 | |
| 7360 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 7361 | return SideEffects::CanTriggerGC(); |
| 7362 | } |
| 7363 | |
Nicolas Geoffray | aafb81b | 2022-06-29 09:36:23 +0100 | [diff] [blame] | 7364 | bool CanThrow() const override { return true; } |
| 7365 | |
| 7366 | bool NeedsEnvironment() const override { return true; } |
| 7367 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7368 | DECLARE_INSTRUCTION(LoadMethodHandle); |
| 7369 | |
| 7370 | protected: |
| 7371 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodHandle); |
| 7372 | |
| 7373 | private: |
| 7374 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 7375 | HUserRecord<HInstruction*> special_input_; |
| 7376 | |
| 7377 | const uint16_t method_handle_idx_; |
| 7378 | const DexFile& dex_file_; |
| 7379 | }; |
| 7380 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7381 | class HLoadMethodType final : public HInstruction { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7382 | public: |
| 7383 | HLoadMethodType(HCurrentMethod* current_method, |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 7384 | dex::ProtoIndex proto_index, |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7385 | const DexFile& dex_file, |
| 7386 | uint32_t dex_pc) |
| 7387 | : HInstruction(kLoadMethodType, |
| 7388 | DataType::Type::kReference, |
| 7389 | SideEffectsForArchRuntimeCalls(), |
| 7390 | dex_pc), |
| 7391 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 7392 | proto_index_(proto_index), |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7393 | dex_file_(dex_file) { |
| 7394 | } |
| 7395 | |
| 7396 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 7397 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7398 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 7399 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 7400 | } |
| 7401 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7402 | bool IsClonable() const override { return true; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7403 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 7404 | dex::ProtoIndex GetProtoIndex() const { return proto_index_; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7405 | |
| 7406 | const DexFile& GetDexFile() const { return dex_file_; } |
| 7407 | |
| 7408 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 7409 | return SideEffects::CanTriggerGC(); |
| 7410 | } |
| 7411 | |
Nicolas Geoffray | aafb81b | 2022-06-29 09:36:23 +0100 | [diff] [blame] | 7412 | bool CanThrow() const override { return true; } |
| 7413 | |
| 7414 | bool NeedsEnvironment() const override { return true; } |
| 7415 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7416 | DECLARE_INSTRUCTION(LoadMethodType); |
| 7417 | |
| 7418 | protected: |
| 7419 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodType); |
| 7420 | |
| 7421 | private: |
| 7422 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 7423 | HUserRecord<HInstruction*> special_input_; |
| 7424 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 7425 | const dex::ProtoIndex proto_index_; |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7426 | const DexFile& dex_file_; |
| 7427 | }; |
| 7428 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7429 | /** |
| 7430 | * Performs an initialization check on its Class object input. |
| 7431 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7432 | class HClinitCheck final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7433 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 7434 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 7435 | : HExpression( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7436 | kClinitCheck, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7437 | DataType::Type::kReference, |
Mingyao Yang | 217eb06 | 2017-12-11 15:20:07 -0800 | [diff] [blame] | 7438 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7439 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7440 | SetRawInputAt(0, constant); |
| 7441 | } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 7442 | // TODO: Make ClinitCheck clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7443 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 7444 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7445 | return true; |
| 7446 | } |
| 7447 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7448 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7449 | // May call runtime to initialize the class. |
| 7450 | return true; |
| 7451 | } |
| 7452 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7453 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7454 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7455 | HLoadClass* GetLoadClass() const { |
| 7456 | DCHECK(InputAt(0)->IsLoadClass()); |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 7457 | return InputAt(0)->AsLoadClass(); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7458 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7459 | |
| 7460 | DECLARE_INSTRUCTION(ClinitCheck); |
| 7461 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7462 | |
| 7463 | protected: |
| 7464 | DEFAULT_COPY_CONSTRUCTOR(ClinitCheck); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7465 | }; |
| 7466 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7467 | class HStaticFieldGet final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7468 | public: |
| 7469 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7470 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7471 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7472 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 7473 | bool is_volatile, |
| 7474 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 7475 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 7476 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 7477 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7478 | : HExpression(kStaticFieldGet, |
| 7479 | field_type, |
| 7480 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 7481 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7482 | field_info_(field, |
| 7483 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 7484 | field_type, |
| 7485 | is_volatile, |
| 7486 | field_idx, |
| 7487 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7488 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7489 | SetRawInputAt(0, cls); |
| 7490 | } |
| 7491 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7492 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7493 | bool IsClonable() const override { return true; } |
| 7494 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7495 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7496 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 7497 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7498 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7499 | } |
| 7500 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7501 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7502 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 7503 | } |
| 7504 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 7505 | bool IsFieldAccess() const override { return true; } |
| 7506 | const FieldInfo& GetFieldInfo() const override { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7507 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7508 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7509 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7510 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 7511 | void SetType(DataType::Type new_type) { |
| 7512 | DCHECK(DataType::IsIntegralType(GetType())); |
| 7513 | DCHECK(DataType::IsIntegralType(new_type)); |
| 7514 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 7515 | SetPackedField<TypeField>(new_type); |
| 7516 | } |
| 7517 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7518 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 7519 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7520 | protected: |
| 7521 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldGet); |
| 7522 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7523 | private: |
| 7524 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7525 | }; |
| 7526 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7527 | class HStaticFieldSet final : public HExpression<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7528 | public: |
| 7529 | HStaticFieldSet(HInstruction* cls, |
| 7530 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7531 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7532 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7533 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 7534 | bool is_volatile, |
| 7535 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 7536 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 7537 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 7538 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7539 | : HExpression(kStaticFieldSet, |
| 7540 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 7541 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7542 | field_info_(field, |
| 7543 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 7544 | field_type, |
| 7545 | is_volatile, |
| 7546 | field_idx, |
| 7547 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7548 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7549 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 7550 | SetPackedField<WriteBarrierKindField>(WriteBarrierKind::kEmitWithNullCheck); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7551 | SetRawInputAt(0, cls); |
| 7552 | SetRawInputAt(1, value); |
| 7553 | } |
| 7554 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7555 | bool IsClonable() const override { return true; } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 7556 | bool IsFieldAccess() const override { return true; } |
| 7557 | const FieldInfo& GetFieldInfo() const override { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7558 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7559 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7560 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7561 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 7562 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7563 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 7564 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 7565 | |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 7566 | WriteBarrierKind GetWriteBarrierKind() { return GetPackedField<WriteBarrierKindField>(); } |
| 7567 | void SetWriteBarrierKind(WriteBarrierKind kind) { |
| 7568 | DCHECK(kind != WriteBarrierKind::kEmitWithNullCheck) |
| 7569 | << "We shouldn't go back to the original value."; |
| 7570 | SetPackedField<WriteBarrierKindField>(kind); |
| 7571 | } |
| 7572 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7573 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 7574 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7575 | protected: |
| 7576 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldSet); |
| 7577 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7578 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7579 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 7580 | static constexpr size_t kWriteBarrierKind = kFlagValueCanBeNull + 1; |
| 7581 | static constexpr size_t kWriteBarrierKindSize = |
| 7582 | MinimumBitsToStore(static_cast<size_t>(WriteBarrierKind::kLast)); |
| 7583 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = |
| 7584 | kWriteBarrierKind + kWriteBarrierKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7585 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 7586 | "Too many packed fields."); |
| 7587 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7588 | const FieldInfo field_info_; |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 7589 | using WriteBarrierKindField = |
| 7590 | BitField<WriteBarrierKind, kWriteBarrierKind, kWriteBarrierKindSize>; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7591 | }; |
| 7592 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 7593 | class HStringBuilderAppend final : public HVariableInputSizeInstruction { |
| 7594 | public: |
| 7595 | HStringBuilderAppend(HIntConstant* format, |
| 7596 | uint32_t number_of_arguments, |
Vladimir Marko | 41de450 | 2019-05-21 10:00:15 +0100 | [diff] [blame] | 7597 | bool has_fp_args, |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 7598 | ArenaAllocator* allocator, |
| 7599 | uint32_t dex_pc) |
| 7600 | : HVariableInputSizeInstruction( |
| 7601 | kStringBuilderAppend, |
| 7602 | DataType::Type::kReference, |
Vladimir Marko | 41de450 | 2019-05-21 10:00:15 +0100 | [diff] [blame] | 7603 | SideEffects::CanTriggerGC().Union( |
| 7604 | // The runtime call may read memory from inputs. It never writes outside |
| 7605 | // of the newly allocated result object or newly allocated helper objects, |
| 7606 | // except for float/double arguments where we reuse thread-local helper objects. |
| 7607 | has_fp_args ? SideEffects::AllWritesAndReads() : SideEffects::AllReads()), |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 7608 | dex_pc, |
| 7609 | allocator, |
| 7610 | number_of_arguments + /* format */ 1u, |
| 7611 | kArenaAllocInvokeInputs) { |
| 7612 | DCHECK_GE(number_of_arguments, 1u); // There must be something to append. |
| 7613 | SetRawInputAt(FormatIndex(), format); |
| 7614 | } |
| 7615 | |
| 7616 | void SetArgumentAt(size_t index, HInstruction* argument) { |
| 7617 | DCHECK_LE(index, GetNumberOfArguments()); |
| 7618 | SetRawInputAt(index, argument); |
| 7619 | } |
| 7620 | |
| 7621 | // Return the number of arguments, excluding the format. |
| 7622 | size_t GetNumberOfArguments() const { |
| 7623 | DCHECK_GE(InputCount(), 1u); |
| 7624 | return InputCount() - 1u; |
| 7625 | } |
| 7626 | |
| 7627 | size_t FormatIndex() const { |
| 7628 | return GetNumberOfArguments(); |
| 7629 | } |
| 7630 | |
| 7631 | HIntConstant* GetFormat() { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 7632 | return InputAt(FormatIndex())->AsIntConstant(); |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 7633 | } |
| 7634 | |
| 7635 | bool NeedsEnvironment() const override { return true; } |
| 7636 | |
| 7637 | bool CanThrow() const override { return true; } |
| 7638 | |
Vladimir Marko | b1fe5e1 | 2020-03-10 14:30:49 +0000 | [diff] [blame] | 7639 | bool CanBeNull() const override { return false; } |
| 7640 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 7641 | DECLARE_INSTRUCTION(StringBuilderAppend); |
| 7642 | |
| 7643 | protected: |
| 7644 | DEFAULT_COPY_CONSTRUCTOR(StringBuilderAppend); |
| 7645 | }; |
| 7646 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7647 | class HUnresolvedInstanceFieldGet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7648 | public: |
| 7649 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7650 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7651 | uint32_t field_index, |
| 7652 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7653 | : HExpression(kUnresolvedInstanceFieldGet, |
| 7654 | field_type, |
| 7655 | SideEffects::AllExceptGCDependency(), |
| 7656 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7657 | field_index_(field_index) { |
| 7658 | SetRawInputAt(0, obj); |
| 7659 | } |
| 7660 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7661 | bool IsClonable() const override { return true; } |
| 7662 | bool NeedsEnvironment() const override { return true; } |
| 7663 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7664 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7665 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7666 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7667 | |
| 7668 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 7669 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7670 | protected: |
| 7671 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldGet); |
| 7672 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7673 | private: |
| 7674 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7675 | }; |
| 7676 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7677 | class HUnresolvedInstanceFieldSet final : public HExpression<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7678 | public: |
| 7679 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 7680 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7681 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7682 | uint32_t field_index, |
| 7683 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7684 | : HExpression(kUnresolvedInstanceFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7685 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7686 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7687 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7688 | SetRawInputAt(0, obj); |
| 7689 | SetRawInputAt(1, value); |
| 7690 | } |
| 7691 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7692 | bool IsClonable() const override { return true; } |
| 7693 | bool NeedsEnvironment() const override { return true; } |
| 7694 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7695 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7696 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7697 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7698 | |
| 7699 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 7700 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7701 | protected: |
| 7702 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldSet); |
| 7703 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7704 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7705 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 7706 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7707 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7708 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 7709 | kFieldFieldType + kFieldFieldTypeSize; |
| 7710 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7711 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7712 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7713 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7714 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7715 | }; |
| 7716 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7717 | class HUnresolvedStaticFieldGet final : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7718 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7719 | HUnresolvedStaticFieldGet(DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7720 | uint32_t field_index, |
| 7721 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7722 | : HExpression(kUnresolvedStaticFieldGet, |
| 7723 | field_type, |
| 7724 | SideEffects::AllExceptGCDependency(), |
| 7725 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7726 | field_index_(field_index) { |
| 7727 | } |
| 7728 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7729 | bool IsClonable() const override { return true; } |
| 7730 | bool NeedsEnvironment() const override { return true; } |
| 7731 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7732 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7733 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7734 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7735 | |
| 7736 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 7737 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7738 | protected: |
| 7739 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldGet); |
| 7740 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7741 | private: |
| 7742 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7743 | }; |
| 7744 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7745 | class HUnresolvedStaticFieldSet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7746 | public: |
| 7747 | HUnresolvedStaticFieldSet(HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7748 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7749 | uint32_t field_index, |
| 7750 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7751 | : HExpression(kUnresolvedStaticFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7752 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7753 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7754 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7755 | SetRawInputAt(0, value); |
| 7756 | } |
| 7757 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7758 | bool IsClonable() const override { return true; } |
| 7759 | bool NeedsEnvironment() const override { return true; } |
| 7760 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7761 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7762 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7763 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7764 | |
| 7765 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 7766 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7767 | protected: |
| 7768 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldSet); |
| 7769 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7770 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7771 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 7772 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7773 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7774 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 7775 | kFieldFieldType + kFieldFieldTypeSize; |
| 7776 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7777 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7778 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7779 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7780 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7781 | }; |
| 7782 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7783 | // Implement the move-exception DEX instruction. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7784 | class HLoadException final : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7785 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7786 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7787 | : HExpression(kLoadException, DataType::Type::kReference, SideEffects::None(), dex_pc) { |
| 7788 | } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7789 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7790 | bool CanBeNull() const override { return false; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 7791 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7792 | DECLARE_INSTRUCTION(LoadException); |
| 7793 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7794 | protected: |
| 7795 | DEFAULT_COPY_CONSTRUCTOR(LoadException); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7796 | }; |
| 7797 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7798 | // Implicit part of move-exception which clears thread-local exception storage. |
| 7799 | // 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] | 7800 | class HClearException final : public HExpression<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7801 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7802 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7803 | : HExpression(kClearException, SideEffects::AllWrites(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7804 | } |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7805 | |
| 7806 | DECLARE_INSTRUCTION(ClearException); |
| 7807 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7808 | protected: |
| 7809 | DEFAULT_COPY_CONSTRUCTOR(ClearException); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7810 | }; |
| 7811 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7812 | class HThrow final : public HExpression<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7813 | public: |
| 7814 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7815 | : HExpression(kThrow, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7816 | SetRawInputAt(0, exception); |
| 7817 | } |
| 7818 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7819 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7820 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7821 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7822 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7823 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7824 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7825 | bool AlwaysThrows() const override { return true; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 7826 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7827 | DECLARE_INSTRUCTION(Throw); |
| 7828 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7829 | protected: |
| 7830 | DEFAULT_COPY_CONSTRUCTOR(Throw); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7831 | }; |
| 7832 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7833 | /** |
| 7834 | * Implementation strategies for the code generator of a HInstanceOf |
| 7835 | * or `HCheckCast`. |
| 7836 | */ |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 7837 | 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] | 7838 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7839 | kExactCheck, // Can do a single class compare. |
| 7840 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 7841 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 7842 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 7843 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7844 | kArrayCheck, // No optimization yet when checking against a generic array. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7845 | kBitstringCheck, // Compare the type check bitstring. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7846 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7847 | }; |
| 7848 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 7849 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 7850 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7851 | // Note: HTypeCheckInstruction is just a helper class, not an abstract instruction with an |
| 7852 | // `IsTypeCheckInstruction()`. (New virtual methods in the HInstruction class have a high cost.) |
| 7853 | class HTypeCheckInstruction : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7854 | public: |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7855 | HTypeCheckInstruction(InstructionKind kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7856 | DataType::Type type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7857 | HInstruction* object, |
| 7858 | HInstruction* target_class_or_null, |
| 7859 | TypeCheckKind check_kind, |
| 7860 | Handle<mirror::Class> klass, |
| 7861 | uint32_t dex_pc, |
| 7862 | ArenaAllocator* allocator, |
| 7863 | HIntConstant* bitstring_path_to_root, |
| 7864 | HIntConstant* bitstring_mask, |
| 7865 | SideEffects side_effects) |
| 7866 | : HVariableInputSizeInstruction( |
| 7867 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7868 | type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7869 | side_effects, |
| 7870 | dex_pc, |
| 7871 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7872 | /* number_of_inputs= */ check_kind == TypeCheckKind::kBitstringCheck ? 4u : 2u, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7873 | kArenaAllocTypeCheckInputs), |
| 7874 | klass_(klass) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7875 | SetPackedField<TypeCheckKindField>(check_kind); |
| 7876 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7877 | SetPackedFlag<kFlagValidTargetClassRTI>(false); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7878 | SetRawInputAt(0, object); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7879 | SetRawInputAt(1, target_class_or_null); |
| 7880 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_path_to_root != nullptr); |
| 7881 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_mask != nullptr); |
| 7882 | if (check_kind == TypeCheckKind::kBitstringCheck) { |
| 7883 | DCHECK(target_class_or_null->IsNullConstant()); |
| 7884 | SetRawInputAt(2, bitstring_path_to_root); |
| 7885 | SetRawInputAt(3, bitstring_mask); |
| 7886 | } else { |
| 7887 | DCHECK(target_class_or_null->IsLoadClass()); |
| 7888 | } |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7889 | } |
| 7890 | |
| 7891 | HLoadClass* GetTargetClass() const { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7892 | DCHECK_NE(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7893 | HInstruction* load_class = InputAt(1); |
| 7894 | DCHECK(load_class->IsLoadClass()); |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 7895 | return load_class->AsLoadClass(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7896 | } |
| 7897 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7898 | uint32_t GetBitstringPathToRoot() const { |
| 7899 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7900 | HInstruction* path_to_root = InputAt(2); |
| 7901 | DCHECK(path_to_root->IsIntConstant()); |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 7902 | return static_cast<uint32_t>(path_to_root->AsIntConstant()->GetValue()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7903 | } |
| 7904 | |
| 7905 | uint32_t GetBitstringMask() const { |
| 7906 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7907 | HInstruction* mask = InputAt(3); |
| 7908 | DCHECK(mask->IsIntConstant()); |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 7909 | return static_cast<uint32_t>(mask->AsIntConstant()->GetValue()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7910 | } |
| 7911 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7912 | bool IsClonable() const override { return true; } |
| 7913 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7914 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7915 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7916 | DCHECK(other->IsInstanceOf() || other->IsCheckCast()) << other->DebugName(); |
| 7917 | return GetPackedFields() == down_cast<const HTypeCheckInstruction*>(other)->GetPackedFields(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7918 | } |
| 7919 | |
Andreas Gampe | 3fbd3ad | 2018-03-26 21:14:46 +0000 | [diff] [blame] | 7920 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 7921 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 7922 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 7923 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
| 7924 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7925 | ReferenceTypeInfo GetTargetClassRTI() { |
| 7926 | if (GetPackedFlag<kFlagValidTargetClassRTI>()) { |
| 7927 | // 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] | 7928 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact= */ true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7929 | } else { |
| 7930 | return ReferenceTypeInfo::CreateInvalid(); |
| 7931 | } |
| 7932 | } |
| 7933 | |
| 7934 | // Target class RTI is marked as valid by RTP if the klass_ is admissible. |
Vladimir Marko | ffafe8b | 2021-04-23 10:29:27 +0000 | [diff] [blame] | 7935 | void SetValidTargetClassRTI() { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7936 | DCHECK(klass_ != nullptr); |
| 7937 | SetPackedFlag<kFlagValidTargetClassRTI>(true); |
| 7938 | } |
| 7939 | |
| 7940 | Handle<mirror::Class> GetClass() const { |
| 7941 | return klass_; |
| 7942 | } |
| 7943 | |
| 7944 | protected: |
| 7945 | DEFAULT_COPY_CONSTRUCTOR(TypeCheckInstruction); |
| 7946 | |
| 7947 | private: |
| 7948 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 7949 | static constexpr size_t kFieldTypeCheckKindSize = |
| 7950 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 7951 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 7952 | static constexpr size_t kFlagValidTargetClassRTI = kFlagMustDoNullCheck + 1; |
| 7953 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagValidTargetClassRTI + 1; |
| 7954 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7955 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
| 7956 | |
| 7957 | Handle<mirror::Class> klass_; |
| 7958 | }; |
| 7959 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7960 | class HInstanceOf final : public HTypeCheckInstruction { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7961 | public: |
| 7962 | HInstanceOf(HInstruction* object, |
| 7963 | HInstruction* target_class_or_null, |
| 7964 | TypeCheckKind check_kind, |
| 7965 | Handle<mirror::Class> klass, |
| 7966 | uint32_t dex_pc, |
| 7967 | ArenaAllocator* allocator, |
| 7968 | HIntConstant* bitstring_path_to_root, |
| 7969 | HIntConstant* bitstring_mask) |
| 7970 | : HTypeCheckInstruction(kInstanceOf, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7971 | DataType::Type::kBool, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7972 | object, |
| 7973 | target_class_or_null, |
| 7974 | check_kind, |
| 7975 | klass, |
| 7976 | dex_pc, |
| 7977 | allocator, |
| 7978 | bitstring_path_to_root, |
| 7979 | bitstring_mask, |
| 7980 | SideEffectsForArchRuntimeCalls(check_kind)) {} |
| 7981 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7982 | bool IsClonable() const override { return true; } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 7983 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7984 | bool NeedsEnvironment() const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7985 | return CanCallRuntime(GetTypeCheckKind()); |
| 7986 | } |
| 7987 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7988 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
Vladimir Marko | 54f4fbd | 2020-02-12 10:52:22 +0000 | [diff] [blame] | 7989 | // TODO: Re-evaluate now that mips codegen has been removed. |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7990 | return check_kind != TypeCheckKind::kExactCheck; |
| 7991 | } |
| 7992 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7993 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7994 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7995 | } |
| 7996 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7997 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7998 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7999 | protected: |
| 8000 | DEFAULT_COPY_CONSTRUCTOR(InstanceOf); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 8001 | }; |
| 8002 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8003 | class HBoundType final : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8004 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 8005 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 8006 | : HExpression(kBoundType, DataType::Type::kReference, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8007 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 8008 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 8009 | SetPackedFlag<kFlagCanBeNull>(true); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8010 | DCHECK_EQ(input->GetType(), DataType::Type::kReference); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8011 | SetRawInputAt(0, input); |
| 8012 | } |
| 8013 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8014 | bool InstructionDataEquals(const HInstruction* other) const override; |
| 8015 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8016 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 8017 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 8018 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8019 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 8020 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8021 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 8022 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8023 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 8024 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8025 | } |
| 8026 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8027 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 8028 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8029 | DECLARE_INSTRUCTION(BoundType); |
| 8030 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8031 | protected: |
| 8032 | DEFAULT_COPY_CONSTRUCTOR(BoundType); |
| 8033 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8034 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8035 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 8036 | // is false then CanBeNull() cannot be true). |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 8037 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8038 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 8039 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 8040 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 8041 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8042 | // 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] | 8043 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 8044 | // It is used to bound the type in cases like: |
| 8045 | // if (x instanceof ClassX) { |
| 8046 | // // uper_bound_ will be ClassX |
| 8047 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 8048 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8049 | }; |
| 8050 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8051 | class HCheckCast final : public HTypeCheckInstruction { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 8052 | public: |
| 8053 | HCheckCast(HInstruction* object, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8054 | HInstruction* target_class_or_null, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 8055 | TypeCheckKind check_kind, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8056 | Handle<mirror::Class> klass, |
| 8057 | uint32_t dex_pc, |
| 8058 | ArenaAllocator* allocator, |
| 8059 | HIntConstant* bitstring_path_to_root, |
| 8060 | HIntConstant* bitstring_mask) |
| 8061 | : HTypeCheckInstruction(kCheckCast, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 8062 | DataType::Type::kVoid, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8063 | object, |
| 8064 | target_class_or_null, |
| 8065 | check_kind, |
| 8066 | klass, |
| 8067 | dex_pc, |
| 8068 | allocator, |
| 8069 | bitstring_path_to_root, |
| 8070 | bitstring_mask, |
| 8071 | SideEffects::CanTriggerGC()) {} |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 8072 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8073 | bool IsClonable() const override { return true; } |
| 8074 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 8075 | // Instruction may throw a CheckCastError. |
| 8076 | return true; |
| 8077 | } |
| 8078 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8079 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 8080 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 8081 | DECLARE_INSTRUCTION(CheckCast); |
| 8082 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8083 | protected: |
| 8084 | DEFAULT_COPY_CONSTRUCTOR(CheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 8085 | }; |
| 8086 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 8087 | /** |
| 8088 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 8089 | * @details We define the combined barrier types that are actually required |
| 8090 | * by the Java Memory Model, rather than using exactly the terminology from |
| 8091 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 8092 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 8093 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 8094 | * The current recipe is as follows: |
| 8095 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 8096 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 8097 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 8098 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 8099 | * class has final fields. |
| 8100 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 8101 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 8102 | */ |
| 8103 | enum MemBarrierKind { |
| 8104 | kAnyStore, |
| 8105 | kLoadAny, |
| 8106 | kStoreStore, |
| 8107 | kAnyAny, |
| 8108 | kNTStoreStore, |
| 8109 | kLastBarrierKind = kNTStoreStore |
| 8110 | }; |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 8111 | std::ostream& operator<<(std::ostream& os, MemBarrierKind kind); |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 8112 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8113 | class HMemoryBarrier final : public HExpression<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 8114 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 8115 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 8116 | : HExpression(kMemoryBarrier, |
| 8117 | SideEffects::AllWritesAndReads(), // Assume write/read on all fields/arrays. |
| 8118 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8119 | SetPackedField<BarrierKindField>(barrier_kind); |
| 8120 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 8121 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8122 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8123 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8124 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 8125 | |
| 8126 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 8127 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8128 | protected: |
| 8129 | DEFAULT_COPY_CONSTRUCTOR(MemoryBarrier); |
| 8130 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 8131 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8132 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 8133 | static constexpr size_t kFieldBarrierKindSize = |
| 8134 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 8135 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 8136 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 8137 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 8138 | "Too many packed fields."); |
| 8139 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 8140 | }; |
| 8141 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8142 | // A constructor fence orders all prior stores to fields that could be accessed via a final field of |
| 8143 | // the specified object(s), with respect to any subsequent store that might "publish" |
| 8144 | // (i.e. make visible) the specified object to another thread. |
| 8145 | // |
| 8146 | // JLS 17.5.1 "Semantics of final fields" states that a freeze action happens |
| 8147 | // for all final fields (that were set) at the end of the invoked constructor. |
| 8148 | // |
| 8149 | // The constructor fence models the freeze actions for the final fields of an object |
| 8150 | // being constructed (semantically at the end of the constructor). Constructor fences |
| 8151 | // have a per-object affinity; two separate objects being constructed get two separate |
| 8152 | // constructor fences. |
| 8153 | // |
| 8154 | // (Note: that if calling a super-constructor or forwarding to another constructor, |
| 8155 | // the freezes would happen at the end of *that* constructor being invoked). |
| 8156 | // |
| 8157 | // The memory model guarantees that when the object being constructed is "published" after |
| 8158 | // constructor completion (i.e. escapes the current thread via a store), then any final field |
| 8159 | // writes must be observable on other threads (once they observe that publication). |
| 8160 | // |
| 8161 | // Further, anything written before the freeze, and read by dereferencing through the final field, |
| 8162 | // must also be visible (so final object field could itself have an object with non-final fields; |
| 8163 | // yet the freeze must also extend to them). |
| 8164 | // |
| 8165 | // Constructor example: |
| 8166 | // |
| 8167 | // class HasFinal { |
| 8168 | // final int field; Optimizing IR for <init>()V: |
| 8169 | // HasFinal() { |
| 8170 | // field = 123; HInstanceFieldSet(this, HasFinal.field, 123) |
| 8171 | // // freeze(this.field); HConstructorFence(this) |
| 8172 | // } HReturn |
| 8173 | // } |
| 8174 | // |
| 8175 | // HConstructorFence can serve double duty as a fence for new-instance/new-array allocations of |
| 8176 | // already-initialized classes; in that case the allocation must act as a "default-initializer" |
| 8177 | // of the object which effectively writes the class pointer "final field". |
| 8178 | // |
| 8179 | // For example, we can model default-initialiation as roughly the equivalent of the following: |
| 8180 | // |
| 8181 | // class Object { |
| 8182 | // private final Class header; |
| 8183 | // } |
| 8184 | // |
| 8185 | // Java code: Optimizing IR: |
| 8186 | // |
| 8187 | // T new_instance<T>() { |
| 8188 | // Object obj = allocate_memory(T.class.size); obj = HInvoke(art_quick_alloc_object, T) |
| 8189 | // obj.header = T.class; // header write is done by above call. |
| 8190 | // // freeze(obj.header) HConstructorFence(obj) |
| 8191 | // return (T)obj; |
| 8192 | // } |
| 8193 | // |
| 8194 | // See also: |
Vladimir Marko | c1c3452 | 2018-10-31 13:56:49 +0000 | [diff] [blame] | 8195 | // * DexCompilationUnit::RequiresConstructorBarrier |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8196 | // * QuasiAtomic::ThreadFenceForConstructor |
| 8197 | // |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8198 | class HConstructorFence final : public HVariableInputSizeInstruction { |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8199 | // A fence has variable inputs because the inputs can be removed |
| 8200 | // after prepare_for_register_allocation phase. |
| 8201 | // (TODO: In the future a fence could freeze multiple objects |
| 8202 | // after merging two fences together.) |
| 8203 | public: |
| 8204 | // `fence_object` is the reference that needs to be protected for correct publication. |
| 8205 | // |
| 8206 | // It makes sense in the following situations: |
| 8207 | // * <init> constructors, it's the "this" parameter (i.e. HParameterValue, s.t. IsThis() == true). |
| 8208 | // * new-instance-like instructions, it's the return value (i.e. HNewInstance). |
| 8209 | // |
| 8210 | // After construction the `fence_object` becomes the 0th input. |
| 8211 | // This is not an input in a real sense, but just a convenient place to stash the information |
| 8212 | // about the associated object. |
| 8213 | HConstructorFence(HInstruction* fence_object, |
| 8214 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 8215 | ArenaAllocator* allocator) |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8216 | // We strongly suspect there is not a more accurate way to describe the fine-grained reordering |
| 8217 | // constraints described in the class header. We claim that these SideEffects constraints |
| 8218 | // enforce a superset of the real constraints. |
| 8219 | // |
| 8220 | // The ordering described above is conservatively modeled with SideEffects as follows: |
| 8221 | // |
| 8222 | // * To prevent reordering of the publication stores: |
| 8223 | // ----> "Reads of objects" is the initial SideEffect. |
| 8224 | // * For every primitive final field store in the constructor: |
| 8225 | // ----> Union that field's type as a read (e.g. "Read of T") into the SideEffect. |
| 8226 | // * If there are any stores to reference final fields in the constructor: |
| 8227 | // ----> Use a more conservative "AllReads" SideEffect because any stores to any references |
| 8228 | // that are reachable from `fence_object` also need to be prevented for reordering |
| 8229 | // (and we do not want to do alias analysis to figure out what those stores are). |
| 8230 | // |
| 8231 | // In the implementation, this initially starts out as an "all reads" side effect; this is an |
| 8232 | // even more conservative approach than the one described above, and prevents all of the |
| 8233 | // above reordering without analyzing any of the instructions in the constructor. |
| 8234 | // |
| 8235 | // If in a later phase we discover that there are no writes to reference final fields, |
| 8236 | // 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] | 8237 | : HVariableInputSizeInstruction(kConstructorFence, |
| 8238 | SideEffects::AllReads(), |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8239 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 8240 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8241 | /* number_of_inputs= */ 1, |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8242 | kArenaAllocConstructorFenceInputs) { |
| 8243 | DCHECK(fence_object != nullptr); |
| 8244 | SetRawInputAt(0, fence_object); |
| 8245 | } |
| 8246 | |
| 8247 | // The object associated with this constructor fence. |
| 8248 | // |
| 8249 | // (Note: This will be null after the prepare_for_register_allocation phase, |
| 8250 | // as all constructor fence inputs are removed there). |
| 8251 | HInstruction* GetFenceObject() const { |
| 8252 | return InputAt(0); |
| 8253 | } |
| 8254 | |
| 8255 | // Find all the HConstructorFence uses (`fence_use`) for `this` and: |
| 8256 | // - Delete `fence_use` from `this`'s use list. |
| 8257 | // - Delete `this` from `fence_use`'s inputs list. |
| 8258 | // - If the `fence_use` is dead, remove it from the graph. |
| 8259 | // |
| 8260 | // A fence is considered dead once it no longer has any uses |
| 8261 | // and all of the inputs are dead. |
| 8262 | // |
| 8263 | // This must *not* be called during/after prepare_for_register_allocation, |
| 8264 | // because that removes all the inputs to the fences but the fence is actually |
| 8265 | // still considered live. |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8266 | // |
| 8267 | // Returns how many HConstructorFence instructions were removed from graph. |
| 8268 | static size_t RemoveConstructorFences(HInstruction* instruction); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8269 | |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 8270 | // Combine all inputs of `this` and `other` instruction and remove |
| 8271 | // `other` from the graph. |
| 8272 | // |
| 8273 | // Inputs are unique after the merge. |
| 8274 | // |
| 8275 | // Requirement: `this` must not be the same as `other. |
| 8276 | void Merge(HConstructorFence* other); |
| 8277 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 8278 | // Check if this constructor fence is protecting |
| 8279 | // an HNewInstance or HNewArray that is also the immediate |
| 8280 | // predecessor of `this`. |
| 8281 | // |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 8282 | // If `ignore_inputs` is true, then the immediate predecessor doesn't need |
| 8283 | // to be one of the inputs of `this`. |
| 8284 | // |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 8285 | // Returns the associated HNewArray or HNewInstance, |
| 8286 | // or null otherwise. |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 8287 | HInstruction* GetAssociatedAllocation(bool ignore_inputs = false); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 8288 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8289 | DECLARE_INSTRUCTION(ConstructorFence); |
| 8290 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8291 | protected: |
| 8292 | DEFAULT_COPY_CONSTRUCTOR(ConstructorFence); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8293 | }; |
| 8294 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8295 | class HMonitorOperation final : public HExpression<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8296 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8297 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8298 | kEnter, |
| 8299 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8300 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8301 | }; |
| 8302 | |
| 8303 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 8304 | : HExpression(kMonitorOperation, |
| 8305 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 8306 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8307 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8308 | SetRawInputAt(0, object); |
| 8309 | } |
| 8310 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 8311 | // Instruction may go into runtime, so we need an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8312 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 8313 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8314 | bool CanThrow() const override { |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 8315 | // Verifier guarantees that monitor-exit cannot throw. |
| 8316 | // This is important because it allows the HGraphBuilder to remove |
| 8317 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 8318 | return IsEnter(); |
| 8319 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8320 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8321 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 8322 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8323 | |
| 8324 | DECLARE_INSTRUCTION(MonitorOperation); |
| 8325 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8326 | protected: |
| 8327 | DEFAULT_COPY_CONSTRUCTOR(MonitorOperation); |
| 8328 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 8329 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8330 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 8331 | static constexpr size_t kFieldOperationKindSize = |
| 8332 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 8333 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 8334 | kFieldOperationKind + kFieldOperationKindSize; |
| 8335 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 8336 | "Too many packed fields."); |
| 8337 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8338 | }; |
| 8339 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8340 | class HSelect final : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8341 | public: |
| 8342 | HSelect(HInstruction* condition, |
| 8343 | HInstruction* true_value, |
| 8344 | HInstruction* false_value, |
| 8345 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 8346 | : HExpression(kSelect, HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8347 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 8348 | |
| 8349 | // First input must be `true_value` or `false_value` to allow codegens to |
| 8350 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 8351 | // that architectures which implement HSelect as a conditional move also |
| 8352 | // will not need to invert the condition. |
| 8353 | SetRawInputAt(0, false_value); |
| 8354 | SetRawInputAt(1, true_value); |
| 8355 | SetRawInputAt(2, condition); |
| 8356 | } |
| 8357 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8358 | bool IsClonable() const override { return true; } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8359 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 8360 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 8361 | HInstruction* GetCondition() const { return InputAt(2); } |
| 8362 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8363 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 8364 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 8365 | return true; |
| 8366 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8367 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8368 | bool CanBeNull() const override { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8369 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 8370 | } |
| 8371 | |
| 8372 | DECLARE_INSTRUCTION(Select); |
| 8373 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8374 | protected: |
| 8375 | DEFAULT_COPY_CONSTRUCTOR(Select); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8376 | }; |
| 8377 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 8378 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8379 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8380 | MoveOperands(Location source, |
| 8381 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8382 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8383 | HInstruction* instruction) |
| 8384 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8385 | |
| 8386 | Location GetSource() const { return source_; } |
| 8387 | Location GetDestination() const { return destination_; } |
| 8388 | |
| 8389 | void SetSource(Location value) { source_ = value; } |
| 8390 | void SetDestination(Location value) { destination_ = value; } |
| 8391 | |
| 8392 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 8393 | // destination (but not the source). |
| 8394 | Location MarkPending() { |
| 8395 | DCHECK(!IsPending()); |
| 8396 | Location dest = destination_; |
| 8397 | destination_ = Location::NoLocation(); |
| 8398 | return dest; |
| 8399 | } |
| 8400 | |
| 8401 | void ClearPending(Location dest) { |
| 8402 | DCHECK(IsPending()); |
| 8403 | destination_ = dest; |
| 8404 | } |
| 8405 | |
| 8406 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8407 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 8408 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8409 | } |
| 8410 | |
| 8411 | // True if this blocks a move from the given location. |
| 8412 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 8413 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8414 | } |
| 8415 | |
| 8416 | // A move is redundant if it's been eliminated, if its source and |
| 8417 | // destination are the same, or if its destination is unneeded. |
| 8418 | bool IsRedundant() const { |
| 8419 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 8420 | } |
| 8421 | |
| 8422 | // We clear both operands to indicate move that's been eliminated. |
| 8423 | void Eliminate() { |
| 8424 | source_ = destination_ = Location::NoLocation(); |
| 8425 | } |
| 8426 | |
| 8427 | bool IsEliminated() const { |
Santiago Aboy Solanes | 872ec72 | 2022-02-18 14:10:25 +0000 | [diff] [blame] | 8428 | DCHECK_IMPLIES(source_.IsInvalid(), destination_.IsInvalid()); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8429 | return source_.IsInvalid(); |
| 8430 | } |
| 8431 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8432 | DataType::Type GetType() const { return type_; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 8433 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8434 | bool Is64BitMove() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8435 | return DataType::Is64BitType(type_); |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8436 | } |
| 8437 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 8438 | HInstruction* GetInstruction() const { return instruction_; } |
| 8439 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8440 | private: |
| 8441 | Location source_; |
| 8442 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8443 | // The type this move is for. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8444 | DataType::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 8445 | // The instruction this move is assocatied with. Null when this move is |
| 8446 | // for moving an input in the expected locations of user (including a phi user). |
| 8447 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 8448 | // in the same parallel move. |
| 8449 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8450 | }; |
| 8451 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8452 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 8453 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8454 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 8455 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8456 | class HParallelMove final : public HExpression<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8457 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 8458 | explicit HParallelMove(ArenaAllocator* allocator, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 8459 | : HExpression(kParallelMove, SideEffects::None(), dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 8460 | moves_(allocator->Adapter(kArenaAllocMoveOperands)) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8461 | moves_.reserve(kDefaultNumberOfMoves); |
| 8462 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8463 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8464 | void AddMove(Location source, |
| 8465 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8466 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8467 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 8468 | DCHECK(source.IsValid()); |
| 8469 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 8470 | if (kIsDebugBuild) { |
| 8471 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8472 | for (const MoveOperands& move : moves_) { |
| 8473 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8474 | // Special case the situation where the move is for the spill slot |
| 8475 | // of the instruction. |
| 8476 | if ((GetPrevious() == instruction) |
| 8477 | || ((GetPrevious() == nullptr) |
| 8478 | && instruction->IsPhi() |
| 8479 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8480 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8481 | << "Doing parallel moves for the same instruction."; |
| 8482 | } else { |
| 8483 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 8484 | } |
| 8485 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 8486 | } |
| 8487 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8488 | for (const MoveOperands& move : moves_) { |
| 8489 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 8490 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8491 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Alex Light | a7c66e7 | 2021-01-27 11:41:58 -0800 | [diff] [blame] | 8492 | << source << " ==> " << destination << " for " << SafePrint(instruction); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 8493 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 8494 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8495 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8496 | } |
| 8497 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8498 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8499 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8500 | } |
| 8501 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8502 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8503 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 8504 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8505 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8506 | protected: |
| 8507 | DEFAULT_COPY_CONSTRUCTOR(ParallelMove); |
| 8508 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8509 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8510 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8511 | }; |
| 8512 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8513 | // This instruction computes an intermediate address pointing in the 'middle' of an object. The |
| 8514 | // result pointer cannot be handled by GC, so extra care is taken to make sure that this value is |
| 8515 | // never used across anything that can trigger GC. |
| 8516 | // The result of this instruction is not a pointer in the sense of `DataType::Type::kreference`. |
| 8517 | // So we represent it by the type `DataType::Type::kInt`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8518 | class HIntermediateAddress final : public HExpression<2> { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8519 | public: |
| 8520 | HIntermediateAddress(HInstruction* base_address, HInstruction* offset, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 8521 | : HExpression(kIntermediateAddress, |
| 8522 | DataType::Type::kInt32, |
| 8523 | SideEffects::DependsOnGC(), |
| 8524 | dex_pc) { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8525 | DCHECK_EQ(DataType::Size(DataType::Type::kInt32), |
| 8526 | DataType::Size(DataType::Type::kReference)) |
| 8527 | << "kPrimInt and kPrimNot have different sizes."; |
| 8528 | SetRawInputAt(0, base_address); |
| 8529 | SetRawInputAt(1, offset); |
| 8530 | } |
| 8531 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8532 | bool IsClonable() const override { return true; } |
| 8533 | bool CanBeMoved() const override { return true; } |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 8534 | bool InstructionDataEquals([[maybe_unused]] const HInstruction* other) const override { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8535 | return true; |
| 8536 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8537 | bool IsActualObject() const override { return false; } |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8538 | |
| 8539 | HInstruction* GetBaseAddress() const { return InputAt(0); } |
| 8540 | HInstruction* GetOffset() const { return InputAt(1); } |
| 8541 | |
| 8542 | DECLARE_INSTRUCTION(IntermediateAddress); |
| 8543 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8544 | protected: |
| 8545 | DEFAULT_COPY_CONSTRUCTOR(IntermediateAddress); |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8546 | }; |
| 8547 | |
| 8548 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8549 | } // namespace art |
| 8550 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 8551 | #include "nodes_vector.h" |
| 8552 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 8553 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 8554 | #include "nodes_shared.h" |
| 8555 | #endif |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 8556 | #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64) |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8557 | #include "nodes_x86.h" |
| 8558 | #endif |
| 8559 | |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 8560 | namespace art HIDDEN { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8561 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8562 | class OptimizingCompilerStats; |
| 8563 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8564 | class HGraphVisitor : public ValueObject { |
| 8565 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8566 | explicit HGraphVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 8567 | : stats_(stats), |
| 8568 | graph_(graph) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 8569 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8570 | |
Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 8571 | virtual void VisitInstruction([[maybe_unused]] HInstruction* instruction) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8572 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 8573 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 8574 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8575 | void VisitInsertionOrder(); |
| 8576 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 8577 | // Visit the graph following dominator tree reverse post-order. |
| 8578 | void VisitReversePostOrder(); |
| 8579 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 8580 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8581 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8582 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8583 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8584 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 8585 | |
| 8586 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 8587 | |
| 8588 | #undef DECLARE_VISIT_INSTRUCTION |
| 8589 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8590 | protected: |
| 8591 | OptimizingCompilerStats* stats_; |
| 8592 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8593 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 8594 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8595 | |
| 8596 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 8597 | }; |
| 8598 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8599 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 8600 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8601 | explicit HGraphDelegateVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 8602 | : HGraphVisitor(graph, stats) {} |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8603 | virtual ~HGraphDelegateVisitor() {} |
| 8604 | |
| 8605 | // Visit functions that delegate to to super class. |
| 8606 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8607 | void Visit##name(H##name* instr) override { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8608 | |
| 8609 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 8610 | |
| 8611 | #undef DECLARE_VISIT_INSTRUCTION |
| 8612 | |
| 8613 | private: |
| 8614 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 8615 | }; |
| 8616 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8617 | // Create a clone of the instruction, insert it into the graph; replace the old one with a new |
| 8618 | // and remove the old instruction. |
| 8619 | HInstruction* ReplaceInstrOrPhiByClone(HInstruction* instr); |
| 8620 | |
| 8621 | // Create a clone for each clonable instructions/phis and replace the original with the clone. |
| 8622 | // |
| 8623 | // Used for testing individual instruction cloner. |
Vladimir Marko | 30759fa | 2023-04-05 09:43:21 +0200 | [diff] [blame] | 8624 | class CloneAndReplaceInstructionVisitor final : public HGraphDelegateVisitor { |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8625 | public: |
| 8626 | explicit CloneAndReplaceInstructionVisitor(HGraph* graph) |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8627 | : HGraphDelegateVisitor(graph), instr_replaced_by_clones_count_(0) {} |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8628 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8629 | void VisitInstruction(HInstruction* instruction) override { |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8630 | if (instruction->IsClonable()) { |
| 8631 | ReplaceInstrOrPhiByClone(instruction); |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8632 | instr_replaced_by_clones_count_++; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8633 | } |
| 8634 | } |
| 8635 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8636 | size_t GetInstrReplacedByClonesCount() const { return instr_replaced_by_clones_count_; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8637 | |
| 8638 | private: |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8639 | size_t instr_replaced_by_clones_count_; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8640 | |
| 8641 | DISALLOW_COPY_AND_ASSIGN(CloneAndReplaceInstructionVisitor); |
| 8642 | }; |
| 8643 | |
Artem Serov | 0b284aa | 2021-12-14 23:16:21 +0000 | [diff] [blame] | 8644 | // Iterator over the blocks that are part of the loop; includes blocks which are part |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8645 | // of an inner loop. The order in which the blocks are iterated is on their |
| 8646 | // block id. |
| 8647 | class HBlocksInLoopIterator : public ValueObject { |
| 8648 | public: |
| 8649 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 8650 | : blocks_in_loop_(info.GetBlocks()), |
| 8651 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 8652 | index_(0) { |
| 8653 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 8654 | Advance(); |
| 8655 | } |
| 8656 | } |
| 8657 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8658 | bool Done() const { return index_ == blocks_.size(); } |
| 8659 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8660 | void Advance() { |
| 8661 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8662 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8663 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 8664 | break; |
| 8665 | } |
| 8666 | } |
| 8667 | } |
| 8668 | |
| 8669 | private: |
| 8670 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8671 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8672 | size_t index_; |
| 8673 | |
| 8674 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 8675 | }; |
| 8676 | |
Artem Serov | 0b284aa | 2021-12-14 23:16:21 +0000 | [diff] [blame] | 8677 | // Iterator over the blocks that are part of the loop; includes blocks which are part |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8678 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 8679 | // post order. |
| 8680 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 8681 | public: |
| 8682 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 8683 | : blocks_in_loop_(info.GetBlocks()), |
| 8684 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 8685 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8686 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8687 | Advance(); |
| 8688 | } |
| 8689 | } |
| 8690 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8691 | bool Done() const { return index_ == blocks_.size(); } |
| 8692 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8693 | void Advance() { |
| 8694 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8695 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 8696 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8697 | break; |
| 8698 | } |
| 8699 | } |
| 8700 | } |
| 8701 | |
| 8702 | private: |
| 8703 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8704 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8705 | size_t index_; |
| 8706 | |
| 8707 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 8708 | }; |
| 8709 | |
Artem Serov | 0b284aa | 2021-12-14 23:16:21 +0000 | [diff] [blame] | 8710 | // Iterator over the blocks that are part of the loop; includes blocks which are part |
| 8711 | // of an inner loop. The order in which the blocks are iterated is post order. |
| 8712 | class HBlocksInLoopPostOrderIterator : public ValueObject { |
| 8713 | public: |
| 8714 | explicit HBlocksInLoopPostOrderIterator(const HLoopInformation& info) |
| 8715 | : blocks_in_loop_(info.GetBlocks()), |
| 8716 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 8717 | index_(blocks_.size() - 1) { |
| 8718 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
| 8719 | Advance(); |
| 8720 | } |
| 8721 | } |
| 8722 | |
| 8723 | bool Done() const { return index_ < 0; } |
| 8724 | HBasicBlock* Current() const { return blocks_[index_]; } |
| 8725 | void Advance() { |
| 8726 | --index_; |
| 8727 | for (; index_ >= 0; --index_) { |
| 8728 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
| 8729 | break; |
| 8730 | } |
| 8731 | } |
| 8732 | } |
| 8733 | |
| 8734 | private: |
| 8735 | const BitVector& blocks_in_loop_; |
| 8736 | const ArenaVector<HBasicBlock*>& blocks_; |
| 8737 | |
| 8738 | int32_t index_; |
| 8739 | |
| 8740 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopPostOrderIterator); |
| 8741 | }; |
| 8742 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 8743 | // Returns int64_t value of a properly typed constant. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 8744 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 8745 | if (constant->IsIntConstant()) { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 8746 | return constant->AsIntConstant()->GetValue(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 8747 | } else if (constant->IsLongConstant()) { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 8748 | return constant->AsLongConstant()->GetValue(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 8749 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 8750 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 8751 | return 0; |
| 8752 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 8753 | } |
| 8754 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 8755 | // Returns true iff instruction is an integral constant (and sets value on success). |
| 8756 | inline bool IsInt64AndGet(HInstruction* instruction, /*out*/ int64_t* value) { |
| 8757 | if (instruction->IsIntConstant()) { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 8758 | *value = instruction->AsIntConstant()->GetValue(); |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 8759 | return true; |
| 8760 | } else if (instruction->IsLongConstant()) { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 8761 | *value = instruction->AsLongConstant()->GetValue(); |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 8762 | return true; |
| 8763 | } else if (instruction->IsNullConstant()) { |
| 8764 | *value = 0; |
| 8765 | return true; |
| 8766 | } |
| 8767 | return false; |
| 8768 | } |
| 8769 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 8770 | // Returns true iff instruction is the given integral constant. |
| 8771 | inline bool IsInt64Value(HInstruction* instruction, int64_t value) { |
| 8772 | int64_t val = 0; |
| 8773 | return IsInt64AndGet(instruction, &val) && val == value; |
| 8774 | } |
| 8775 | |
| 8776 | // Returns true iff instruction is a zero bit pattern. |
| 8777 | inline bool IsZeroBitPattern(HInstruction* instruction) { |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 8778 | return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern(); |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 8779 | } |
| 8780 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 8781 | // Implement HInstruction::Is##type() for concrete instructions. |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8782 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8783 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } |
| 8784 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 8785 | #undef INSTRUCTION_TYPE_CHECK |
| 8786 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 8787 | // Implement HInstruction::Is##type() for abstract instructions. |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8788 | #define INSTRUCTION_TYPE_CHECK_RESULT(type, super) \ |
| 8789 | std::is_base_of<BaseType, H##type>::value, |
| 8790 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 8791 | inline bool HInstruction::Is##type() const { \ |
| 8792 | DCHECK_LT(GetKind(), kLastInstructionKind); \ |
| 8793 | using BaseType = H##type; \ |
| 8794 | static constexpr bool results[] = { \ |
| 8795 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK_RESULT) \ |
| 8796 | }; \ |
| 8797 | return results[static_cast<size_t>(GetKind())]; \ |
| 8798 | } |
| 8799 | |
| 8800 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 8801 | #undef INSTRUCTION_TYPE_CHECK |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 8802 | #undef INSTRUCTION_TYPE_CHECK_RESULT |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8803 | |
| 8804 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 8805 | inline const H##type* HInstruction::As##type() const { \ |
| 8806 | DCHECK(Is##type()); \ |
| 8807 | return down_cast<const H##type*>(this); \ |
| 8808 | } \ |
| 8809 | inline H##type* HInstruction::As##type() { \ |
| 8810 | DCHECK(Is##type()); \ |
| 8811 | return down_cast<H##type*>(this); \ |
| 8812 | } \ |
Vladimir Marko | 79dc217 | 2023-04-05 10:33:07 +0000 | [diff] [blame] | 8813 | inline const H##type* HInstruction::As##type##OrNull() const { \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8814 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 8815 | } \ |
Vladimir Marko | 79dc217 | 2023-04-05 10:33:07 +0000 | [diff] [blame] | 8816 | inline H##type* HInstruction::As##type##OrNull() { \ |
Vladimir Marko | f2eef5f | 2023-04-06 10:29:19 +0000 | [diff] [blame] | 8817 | return Is##type() ? down_cast<H##type*>(this) : nullptr; \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8818 | } |
| 8819 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8820 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 8821 | #undef INSTRUCTION_TYPE_CAST |
| 8822 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8823 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 8824 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 8825 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 8826 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 8827 | size_t number_of_new_blocks, |
| 8828 | size_t after) { |
| 8829 | DCHECK_LT(after, blocks->size()); |
| 8830 | size_t old_size = blocks->size(); |
| 8831 | size_t new_size = old_size + number_of_new_blocks; |
| 8832 | blocks->resize(new_size); |
| 8833 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 8834 | } |
| 8835 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8836 | /* |
| 8837 | * Hunt "under the hood" of array lengths (leading to array references), |
| 8838 | * null checks (also leading to array references), and new arrays |
| 8839 | * (leading to the actual length). This makes it more likely related |
| 8840 | * instructions become actually comparable. |
| 8841 | */ |
| 8842 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 8843 | while (instruction->IsArrayLength() || |
| 8844 | instruction->IsNullCheck() || |
| 8845 | instruction->IsNewArray()) { |
| 8846 | instruction = instruction->IsNewArray() |
Vladimir Marko | cde6497 | 2023-04-25 16:40:06 +0000 | [diff] [blame] | 8847 | ? instruction->AsNewArray()->GetLength() |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8848 | : instruction->InputAt(0); |
| 8849 | } |
| 8850 | return instruction; |
| 8851 | } |
| 8852 | |
Artem Serov | b47b978 | 2019-12-04 21:02:09 +0000 | [diff] [blame] | 8853 | inline bool IsAddOrSub(const HInstruction* instruction) { |
| 8854 | return instruction->IsAdd() || instruction->IsSub(); |
| 8855 | } |
| 8856 | |
Artem Serov | 21c7e6f | 2017-07-27 16:04:42 +0100 | [diff] [blame] | 8857 | void RemoveEnvironmentUses(HInstruction* instruction); |
| 8858 | bool HasEnvironmentUsedByOthers(HInstruction* instruction); |
| 8859 | void ResetEnvironmentInputRecords(HInstruction* instruction); |
| 8860 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 8861 | // Detects an instruction that is >= 0. As long as the value is carried by |
| 8862 | // a single instruction, arithmetic wrap-around cannot occur. |
| 8863 | bool IsGEZero(HInstruction* instruction); |
| 8864 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8865 | } // namespace art |
| 8866 | |
| 8867 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |