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 | |
Alex Light | 86fe9b8 | 2020-11-16 16:54:01 +0000 | [diff] [blame] | 24 | #include "base/arena_allocator.h" |
Mathieu Chartier | e5d80f8 | 2015-10-15 17:47:48 -0700 | [diff] [blame] | 25 | #include "base/arena_bit_vector.h" |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 26 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 27 | #include "base/arena_object.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 28 | #include "base/array_ref.h" |
Vladimir Marko | 3fae129 | 2019-06-07 11:26:25 +0100 | [diff] [blame] | 29 | #include "base/intrusive_forward_list.h" |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 30 | #include "base/iteration_range.h" |
Andreas Gampe | 7fbc4a5 | 2018-11-28 08:26:47 -0800 | [diff] [blame] | 31 | #include "base/mutex.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 32 | #include "base/quasi_atomic.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 33 | #include "base/stl_util.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 34 | #include "base/transform_array_ref.h" |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 35 | #include "art_method.h" |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 36 | #include "block_namer.h" |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 37 | #include "class_root.h" |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 38 | #include "compilation_kind.h" |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 39 | #include "data_type.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 40 | #include "deoptimization_kind.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 41 | #include "dex/dex_file.h" |
| 42 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 43 | #include "dex/invoke_type.h" |
David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 44 | #include "dex/method_reference.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 45 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 46 | #include "handle.h" |
| 47 | #include "handle_scope.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 48 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 49 | #include "locations.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 50 | #include "mirror/class.h" |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 51 | #include "mirror/method_type.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 52 | #include "offsets.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 53 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 54 | namespace art { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 55 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 56 | class ArenaStack; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 57 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 58 | class HBasicBlock; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 59 | class HConstructorFence; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 60 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 61 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 62 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 63 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 64 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 65 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 66 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 67 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 68 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 69 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 70 | class HNullConstant; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 71 | class HParameterValue; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 72 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 73 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 74 | class HTryBoundary; |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 75 | class FieldInfo; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 76 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 77 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 78 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 79 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 80 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 81 | namespace mirror { |
| 82 | class DexCache; |
| 83 | } // namespace mirror |
| 84 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 85 | static const int kDefaultNumberOfBlocks = 8; |
| 86 | static const int kDefaultNumberOfSuccessors = 2; |
| 87 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 88 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 89 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 90 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 91 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 92 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 93 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 94 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 95 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 96 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 97 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 98 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 99 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 100 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 101 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 102 | static constexpr uint32_t kNoDexPc = -1; |
| 103 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 104 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 105 | // For the purposes of the compiler, the dex files must actually be the same object |
| 106 | // if we want to safely treat them as the same. This is especially important for JIT |
| 107 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 108 | // times and provide different class resolution but no two class loaders should ever |
| 109 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 110 | // all sorts of weird failures. |
| 111 | return &lhs == &rhs; |
| 112 | } |
| 113 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 114 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 115 | // All types. |
| 116 | kCondEQ, // == |
| 117 | kCondNE, // != |
| 118 | // Signed integers and floating-point numbers. |
| 119 | kCondLT, // < |
| 120 | kCondLE, // <= |
| 121 | kCondGT, // > |
| 122 | kCondGE, // >= |
| 123 | // Unsigned integers. |
| 124 | kCondB, // < |
| 125 | kCondBE, // <= |
| 126 | kCondA, // > |
| 127 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 128 | // First and last aliases. |
| 129 | kCondFirst = kCondEQ, |
| 130 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 133 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 134 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 135 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 136 | kAnalysisFailThrowCatchLoop, |
| 137 | kAnalysisFailAmbiguousArrayOp, |
Nicolas Geoffray | 0846a8f | 2018-09-12 15:21:07 +0100 | [diff] [blame] | 138 | kAnalysisFailIrreducibleLoopAndStringInit, |
Nicolas Geoffray | 7cfc8f5 | 2019-08-07 10:41:09 +0100 | [diff] [blame] | 139 | kAnalysisFailPhiEquivalentInOsr, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 140 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 143 | template <typename T> |
| 144 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 145 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 146 | } |
| 147 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 148 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 149 | public: |
| 150 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 151 | |
| 152 | void AddInstruction(HInstruction* instruction); |
| 153 | void RemoveInstruction(HInstruction* instruction); |
| 154 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 155 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 156 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 157 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 158 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 159 | // Return true if this list contains `instruction`. |
| 160 | bool Contains(HInstruction* instruction) const; |
| 161 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 162 | // Return true if `instruction1` is found before `instruction2` in |
| 163 | // this instruction list and false otherwise. Abort if none |
| 164 | // of these instructions is found. |
| 165 | bool FoundBefore(const HInstruction* instruction1, |
| 166 | const HInstruction* instruction2) const; |
| 167 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 168 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 169 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 170 | |
| 171 | // Update the block of all instructions to be `block`. |
| 172 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 173 | |
| 174 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 175 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 176 | void Add(const HInstructionList& instruction_list); |
| 177 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 178 | // Return the number of instructions in the list. This is an expensive operation. |
| 179 | size_t CountSize() const; |
| 180 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 181 | private: |
| 182 | HInstruction* first_instruction_; |
| 183 | HInstruction* last_instruction_; |
| 184 | |
| 185 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 186 | friend class HGraph; |
| 187 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 188 | friend class HInstructionIterator; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 189 | friend class HInstructionIteratorHandleChanges; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 190 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 191 | |
| 192 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 193 | }; |
| 194 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 195 | class ReferenceTypeInfo : ValueObject { |
| 196 | public: |
Vladimir Marko | 4f99071 | 2021-07-14 12:45:13 +0100 | [diff] [blame] | 197 | using TypeHandle = Handle<mirror::Class>; |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 198 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 199 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 200 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 201 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 202 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 203 | } |
| 204 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 205 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 206 | return ReferenceTypeInfo(type_handle, is_exact); |
| 207 | } |
| 208 | |
| 209 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 210 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 211 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 212 | return handle.GetReference() != nullptr; |
| 213 | } |
| 214 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 215 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 216 | return IsValidHandle(type_handle_); |
| 217 | } |
| 218 | |
| 219 | bool IsExact() const { return is_exact_; } |
| 220 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 221 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 222 | DCHECK(IsValid()); |
| 223 | return GetTypeHandle()->IsObjectClass(); |
| 224 | } |
| 225 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 226 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 227 | DCHECK(IsValid()); |
| 228 | return GetTypeHandle()->IsStringClass(); |
| 229 | } |
| 230 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 231 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 232 | DCHECK(IsValid()); |
| 233 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 234 | } |
| 235 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 236 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 237 | DCHECK(IsValid()); |
| 238 | return GetTypeHandle()->IsInterface(); |
| 239 | } |
| 240 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 241 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 242 | DCHECK(IsValid()); |
| 243 | return GetTypeHandle()->IsArrayClass(); |
| 244 | } |
| 245 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 246 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 247 | DCHECK(IsValid()); |
| 248 | return GetTypeHandle()->IsPrimitiveArray(); |
| 249 | } |
| 250 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 251 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 252 | DCHECK(IsValid()); |
| 253 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 254 | } |
| 255 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 256 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 257 | DCHECK(IsValid()); |
| 258 | if (!IsExact()) return false; |
| 259 | if (!IsArrayClass()) return false; |
| 260 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 261 | } |
| 262 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 263 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 264 | DCHECK(IsValid()); |
| 265 | if (!IsExact()) return false; |
| 266 | if (!IsArrayClass()) return false; |
| 267 | if (!rti.IsArrayClass()) return false; |
| 268 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 269 | rti.GetTypeHandle()->GetComponentType()); |
| 270 | } |
| 271 | |
| 272 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 273 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 274 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 275 | DCHECK(IsValid()); |
| 276 | DCHECK(rti.IsValid()); |
| 277 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 278 | } |
| 279 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 280 | // Returns true if the type information provide the same amount of details. |
| 281 | // Note that it does not mean that the instructions have the same actual type |
| 282 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 283 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 284 | if (!IsValid() && !rti.IsValid()) { |
| 285 | // Invalid types are equal. |
| 286 | return true; |
| 287 | } |
| 288 | if (!IsValid() || !rti.IsValid()) { |
| 289 | // One is valid, the other not. |
| 290 | return false; |
| 291 | } |
| 292 | return IsExact() == rti.IsExact() |
| 293 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 294 | } |
| 295 | |
| 296 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 297 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 298 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 299 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 300 | |
| 301 | // The class of the object. |
| 302 | TypeHandle type_handle_; |
| 303 | // Whether or not the type is exact or a superclass of the actual type. |
| 304 | // Whether or not we have any information about this type. |
| 305 | bool is_exact_; |
| 306 | }; |
| 307 | |
| 308 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 309 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 310 | class HandleCache { |
| 311 | public: |
| 312 | explicit HandleCache(VariableSizedHandleScope* handles) : handles_(handles) { } |
| 313 | |
| 314 | VariableSizedHandleScope* GetHandles() { return handles_; } |
| 315 | |
| 316 | template <typename T> |
| 317 | MutableHandle<T> NewHandle(T* object) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 318 | return handles_->NewHandle(object); |
| 319 | } |
| 320 | |
| 321 | template <typename T> |
| 322 | MutableHandle<T> NewHandle(ObjPtr<T> object) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 323 | return handles_->NewHandle(object); |
| 324 | } |
| 325 | |
| 326 | ReferenceTypeInfo::TypeHandle GetObjectClassHandle() { |
| 327 | return GetRootHandle(ClassRoot::kJavaLangObject, &object_class_handle_); |
| 328 | } |
| 329 | |
| 330 | ReferenceTypeInfo::TypeHandle GetClassClassHandle() { |
| 331 | return GetRootHandle(ClassRoot::kJavaLangClass, &class_class_handle_); |
| 332 | } |
| 333 | |
| 334 | ReferenceTypeInfo::TypeHandle GetMethodHandleClassHandle() { |
| 335 | return GetRootHandle(ClassRoot::kJavaLangInvokeMethodHandleImpl, &method_handle_class_handle_); |
| 336 | } |
| 337 | |
| 338 | ReferenceTypeInfo::TypeHandle GetMethodTypeClassHandle() { |
| 339 | return GetRootHandle(ClassRoot::kJavaLangInvokeMethodType, &method_type_class_handle_); |
| 340 | } |
| 341 | |
| 342 | ReferenceTypeInfo::TypeHandle GetStringClassHandle() { |
| 343 | return GetRootHandle(ClassRoot::kJavaLangString, &string_class_handle_); |
| 344 | } |
| 345 | |
| 346 | ReferenceTypeInfo::TypeHandle GetThrowableClassHandle() { |
| 347 | return GetRootHandle(ClassRoot::kJavaLangThrowable, &throwable_class_handle_); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | private: |
| 352 | inline ReferenceTypeInfo::TypeHandle GetRootHandle(ClassRoot class_root, |
| 353 | ReferenceTypeInfo::TypeHandle* cache) { |
| 354 | if (UNLIKELY(!ReferenceTypeInfo::IsValidHandle(*cache))) { |
| 355 | *cache = CreateRootHandle(handles_, class_root); |
| 356 | } |
| 357 | return *cache; |
| 358 | } |
| 359 | |
| 360 | static ReferenceTypeInfo::TypeHandle CreateRootHandle(VariableSizedHandleScope* handles, |
| 361 | ClassRoot class_root); |
| 362 | |
| 363 | VariableSizedHandleScope* handles_; |
| 364 | |
| 365 | ReferenceTypeInfo::TypeHandle object_class_handle_; |
| 366 | ReferenceTypeInfo::TypeHandle class_class_handle_; |
| 367 | ReferenceTypeInfo::TypeHandle method_handle_class_handle_; |
| 368 | ReferenceTypeInfo::TypeHandle method_type_class_handle_; |
| 369 | ReferenceTypeInfo::TypeHandle string_class_handle_; |
| 370 | ReferenceTypeInfo::TypeHandle throwable_class_handle_; |
| 371 | }; |
| 372 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 373 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 374 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 375 | public: |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 376 | HGraph(ArenaAllocator* allocator, |
| 377 | ArenaStack* arena_stack, |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 378 | VariableSizedHandleScope* handles, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 379 | const DexFile& dex_file, |
| 380 | uint32_t method_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 381 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 382 | InvokeType invoke_type = kInvalidInvokeType, |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 383 | bool dead_reference_safe = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 384 | bool debuggable = false, |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 385 | CompilationKind compilation_kind = CompilationKind::kOptimized, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 386 | int start_instruction_id = 0) |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 387 | : allocator_(allocator), |
| 388 | arena_stack_(arena_stack), |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 389 | handle_cache_(handles), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 390 | blocks_(allocator->Adapter(kArenaAllocBlockList)), |
| 391 | reverse_post_order_(allocator->Adapter(kArenaAllocReversePostOrder)), |
| 392 | linear_order_(allocator->Adapter(kArenaAllocLinearOrder)), |
Alex Light | 86fe9b8 | 2020-11-16 16:54:01 +0000 | [diff] [blame] | 393 | reachability_graph_(allocator, 0, 0, true, kArenaAllocReachabilityGraph), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 394 | entry_block_(nullptr), |
| 395 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 396 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 397 | number_of_vregs_(0), |
| 398 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 399 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 400 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 401 | has_try_catch_(false), |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 402 | has_monitor_operations_(false), |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 403 | has_simd_(false), |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 404 | has_loops_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 405 | has_irreducible_loops_(false), |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 406 | has_direct_critical_native_call_(false), |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 407 | dead_reference_safe_(dead_reference_safe), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 408 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 409 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 410 | dex_file_(dex_file), |
| 411 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 412 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 413 | in_ssa_form_(false), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 414 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 415 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 416 | cached_null_constant_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 417 | cached_int_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 418 | cached_float_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 419 | cached_long_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 420 | cached_double_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 421 | cached_current_method_(nullptr), |
Nicolas Geoffray | 53fec08 | 2017-03-27 12:56:16 +0100 | [diff] [blame] | 422 | art_method_(nullptr), |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 423 | compilation_kind_(compilation_kind), |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 424 | cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 425 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 426 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 427 | |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 428 | std::ostream& Dump(std::ostream& os, |
| 429 | std::optional<std::reference_wrapper<const BlockNamer>> namer = std::nullopt); |
| 430 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 431 | ArenaAllocator* GetAllocator() const { return allocator_; } |
| 432 | ArenaStack* GetArenaStack() const { return arena_stack_; } |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 433 | |
| 434 | HandleCache* GetHandleCache() { return &handle_cache_; } |
| 435 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 436 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 437 | |
Alex Light | 210a78d | 2020-11-30 16:58:05 -0800 | [diff] [blame] | 438 | // An iterator to only blocks that are still actually in the graph (when |
| 439 | // blocks are removed they are replaced with 'nullptr' in GetBlocks to |
| 440 | // simplify block-id assignment and avoid memmoves in the block-list). |
| 441 | IterationRange<FilterNull<ArenaVector<HBasicBlock*>::const_iterator>> GetActiveBlocks() const { |
| 442 | return FilterOutNull(MakeIterationRange(GetBlocks())); |
| 443 | } |
| 444 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 445 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 446 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 447 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 448 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 449 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 450 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 451 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 452 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 453 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 454 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 455 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 456 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 457 | void ComputeDominanceInformation(); |
| 458 | void ClearDominanceInformation(); |
Alex Light | 86fe9b8 | 2020-11-16 16:54:01 +0000 | [diff] [blame] | 459 | void ComputeReachabilityInformation(); |
| 460 | void ClearReachabilityInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 461 | void ClearLoopInformation(); |
| 462 | void FindBackEdges(ArenaBitVector* visited); |
| 463 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 464 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 465 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 466 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 467 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 468 | // 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] | 469 | // 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] | 470 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 471 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 472 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 473 | // order and loop information. |
| 474 | void ComputeTryBlockInformation(); |
| 475 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 476 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 477 | // Returns the instruction to replace the invoke expression or null if the |
| 478 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 479 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 480 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 481 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 482 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 483 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 484 | // should be the new back edge. |
| 485 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 486 | HBasicBlock* reference, |
| 487 | bool replace_if_back_edge); |
| 488 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 489 | // Need to add a couple of blocks to test if the loop body is entered and |
| 490 | // put deoptimization instructions, etc. |
| 491 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 492 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 493 | // Adds a new loop directly after the loop with the given header and exit. |
| 494 | // Returns the new preheader. |
| 495 | HBasicBlock* TransformLoopForVectorization(HBasicBlock* header, |
| 496 | HBasicBlock* body, |
| 497 | HBasicBlock* exit); |
| 498 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 499 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 500 | // other blocks and has no instructions or phis. |
| 501 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 502 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 503 | // Splits the edge between `block` and `successor` while preserving the |
| 504 | // indices in the predecessor/successor lists. If there are multiple edges |
| 505 | // between the blocks, the lowest indices are used. |
| 506 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 507 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 508 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 509 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
Artem Serov | c73ee37 | 2017-07-31 15:08:40 +0100 | [diff] [blame] | 510 | void OrderLoopHeaderPredecessors(HBasicBlock* header); |
Artem Serov | 09faaea | 2017-12-07 14:36:01 +0000 | [diff] [blame] | 511 | |
| 512 | // Transform a loop into a format with a single preheader. |
| 513 | // |
| 514 | // Each phi in the header should be split: original one in the header should only hold |
| 515 | // inputs reachable from the back edges and a single input from the preheader. The newly created |
| 516 | // phi in the preheader should collate the inputs from the original multiple incoming blocks. |
| 517 | // |
| 518 | // Loops in the graph typically have a single preheader, so this method is used to "repair" loops |
| 519 | // that no longer have this property. |
| 520 | void TransformLoopToSinglePreheaderFormat(HBasicBlock* header); |
| 521 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 522 | void SimplifyLoop(HBasicBlock* header); |
| 523 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 524 | int32_t GetNextInstructionId() { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 525 | CHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 526 | return current_instruction_id_++; |
| 527 | } |
| 528 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 529 | int32_t GetCurrentInstructionId() const { |
| 530 | return current_instruction_id_; |
| 531 | } |
| 532 | |
| 533 | void SetCurrentInstructionId(int32_t id) { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 534 | CHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 535 | current_instruction_id_ = id; |
| 536 | } |
| 537 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 538 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 539 | return maximum_number_of_out_vregs_; |
| 540 | } |
| 541 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 542 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 543 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 544 | } |
| 545 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 546 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 547 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 548 | } |
| 549 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 550 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 551 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 552 | } |
| 553 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 554 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 555 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 556 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 557 | } |
| 558 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 559 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 560 | number_of_vregs_ = number_of_vregs; |
| 561 | } |
| 562 | |
| 563 | uint16_t GetNumberOfVRegs() const { |
| 564 | return number_of_vregs_; |
| 565 | } |
| 566 | |
| 567 | void SetNumberOfInVRegs(uint16_t value) { |
| 568 | number_of_in_vregs_ = value; |
| 569 | } |
| 570 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 571 | uint16_t GetNumberOfInVRegs() const { |
| 572 | return number_of_in_vregs_; |
| 573 | } |
| 574 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 575 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 576 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 577 | return number_of_vregs_ - number_of_in_vregs_; |
| 578 | } |
| 579 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 580 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 581 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 582 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 583 | |
Eric Holk | 1868de9 | 2020-02-12 09:10:21 -0800 | [diff] [blame] | 584 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() const { |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 585 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 586 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 587 | } |
| 588 | |
| 589 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 590 | return ReverseRange(GetReversePostOrder()); |
| 591 | } |
| 592 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 593 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 594 | return linear_order_; |
| 595 | } |
| 596 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 597 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 598 | return ReverseRange(GetLinearOrder()); |
| 599 | } |
| 600 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 601 | bool HasBoundsChecks() const { |
| 602 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 603 | } |
| 604 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 605 | void SetHasBoundsChecks(bool value) { |
| 606 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 607 | } |
| 608 | |
Alex Light | 86fe9b8 | 2020-11-16 16:54:01 +0000 | [diff] [blame] | 609 | // Returns true if dest is reachable from source, using either blocks or block-ids. |
| 610 | bool PathBetween(const HBasicBlock* source, const HBasicBlock* dest) const; |
| 611 | bool PathBetween(uint32_t source_id, uint32_t dest_id) const; |
| 612 | |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 613 | // Is the code known to be robust against eliminating dead references |
| 614 | // and the effects of early finalization? |
| 615 | bool IsDeadReferenceSafe() const { return dead_reference_safe_; } |
| 616 | |
| 617 | void MarkDeadReferenceUnsafe() { dead_reference_safe_ = false; } |
| 618 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 619 | bool IsDebuggable() const { return debuggable_; } |
| 620 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 621 | // 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] | 622 | // already, it is created and inserted into the graph. This method is only for |
| 623 | // integral types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 624 | 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] | 625 | |
| 626 | // TODO: This is problematic for the consistency of reference type propagation |
| 627 | // because it can be created anytime after the pass and thus it will be left |
| 628 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 629 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 630 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 631 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 632 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 633 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 634 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 635 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 636 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 637 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 638 | 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] | 639 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 640 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 641 | 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] | 642 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 643 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 644 | HCurrentMethod* GetCurrentMethod(); |
| 645 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 646 | const DexFile& GetDexFile() const { |
| 647 | return dex_file_; |
| 648 | } |
| 649 | |
| 650 | uint32_t GetMethodIdx() const { |
| 651 | return method_idx_; |
| 652 | } |
| 653 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 654 | // Get the method name (without the signature), e.g. "<init>" |
| 655 | const char* GetMethodName() const; |
| 656 | |
| 657 | // Get the pretty method name (class + name + optionally signature). |
| 658 | std::string PrettyMethod(bool with_signature = true) const; |
| 659 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 660 | InvokeType GetInvokeType() const { |
| 661 | return invoke_type_; |
| 662 | } |
| 663 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 664 | InstructionSet GetInstructionSet() const { |
| 665 | return instruction_set_; |
| 666 | } |
| 667 | |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 668 | bool IsCompilingOsr() const { return compilation_kind_ == CompilationKind::kOsr; } |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 669 | |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 670 | bool IsCompilingBaseline() const { return compilation_kind_ == CompilationKind::kBaseline; } |
| 671 | |
| 672 | CompilationKind GetCompilationKind() const { return compilation_kind_; } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 673 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 674 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 675 | return cha_single_implementation_list_; |
| 676 | } |
| 677 | |
| 678 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 679 | cha_single_implementation_list_.insert(method); |
| 680 | } |
| 681 | |
| 682 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 683 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 684 | } |
| 685 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 686 | bool HasTryCatch() const { return has_try_catch_; } |
| 687 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 688 | |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 689 | bool HasMonitorOperations() const { return has_monitor_operations_; } |
| 690 | void SetHasMonitorOperations(bool value) { has_monitor_operations_ = value; } |
| 691 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 692 | bool HasSIMD() const { return has_simd_; } |
| 693 | void SetHasSIMD(bool value) { has_simd_ = value; } |
| 694 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 695 | bool HasLoops() const { return has_loops_; } |
| 696 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 697 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 698 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 699 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 700 | |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 701 | bool HasDirectCriticalNativeCall() const { return has_direct_critical_native_call_; } |
| 702 | void SetHasDirectCriticalNativeCall(bool value) { has_direct_critical_native_call_ = value; } |
| 703 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 704 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 705 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 706 | |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 707 | // Returns an instruction with the opposite Boolean value from 'cond'. |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 708 | // The instruction has been inserted into the graph, either as a constant, or |
| 709 | // before cursor. |
| 710 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 711 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 712 | ReferenceTypeInfo GetInexactObjectRti() { |
| 713 | return ReferenceTypeInfo::Create(handle_cache_.GetObjectClassHandle(), /* is_exact= */ false); |
| 714 | } |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 715 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 716 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 717 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 718 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 719 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 720 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 721 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 722 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 723 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 724 | template <class InstructionType, typename ValueType> |
| 725 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 726 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 727 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 728 | // Try to find an existing constant of the given value. |
| 729 | InstructionType* constant = nullptr; |
| 730 | auto cached_constant = cache->find(value); |
| 731 | if (cached_constant != cache->end()) { |
| 732 | constant = cached_constant->second; |
| 733 | } |
| 734 | |
| 735 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 736 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 737 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 738 | constant = new (allocator_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 739 | cache->Overwrite(value, constant); |
| 740 | InsertConstant(constant); |
| 741 | } |
| 742 | return constant; |
| 743 | } |
| 744 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 745 | void InsertConstant(HConstant* instruction); |
| 746 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 747 | // Cache a float constant into the graph. This method should only be |
| 748 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 749 | void CacheFloatConstant(HFloatConstant* constant); |
| 750 | |
| 751 | // See CacheFloatConstant comment. |
| 752 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 753 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 754 | ArenaAllocator* const allocator_; |
| 755 | ArenaStack* const arena_stack_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 756 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 757 | HandleCache handle_cache_; |
| 758 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 759 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 760 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 761 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 762 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 763 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 764 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 765 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 766 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 767 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 768 | |
Alex Light | 86fe9b8 | 2020-11-16 16:54:01 +0000 | [diff] [blame] | 769 | // Reachability graph for checking connectedness between nodes. Acts as a partitioned vector where |
| 770 | // each RoundUp(blocks_.size(), BitVector::kWordBits) is the reachability of each node. |
| 771 | ArenaBitVectorArray reachability_graph_; |
| 772 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 773 | HBasicBlock* entry_block_; |
| 774 | HBasicBlock* exit_block_; |
| 775 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 776 | // 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] | 777 | uint16_t maximum_number_of_out_vregs_; |
| 778 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 779 | // The number of virtual registers in this method. Contains the parameters. |
| 780 | uint16_t number_of_vregs_; |
| 781 | |
| 782 | // The number of virtual registers used by parameters of this method. |
| 783 | uint16_t number_of_in_vregs_; |
| 784 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 785 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 786 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 787 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 788 | // Flag whether there are bounds checks in the graph. We can skip |
| 789 | // BCE if it's false. It's only best effort to keep it up to date in |
| 790 | // the presence of code elimination so there might be false positives. |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 791 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 792 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 793 | // Flag whether there are try/catch blocks in the graph. We will skip |
| 794 | // try/catch-related passes if it's false. It's only best effort to keep |
| 795 | // it up to date in the presence of code elimination so there might be |
| 796 | // false positives. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 797 | bool has_try_catch_; |
| 798 | |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 799 | // Flag whether there are any HMonitorOperation in the graph. If yes this will mandate |
| 800 | // DexRegisterMap to be present to allow deadlock analysis for non-debuggable code. |
| 801 | bool has_monitor_operations_; |
| 802 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 803 | // Flag whether SIMD instructions appear in the graph. If true, the |
| 804 | // code generators may have to be more careful spilling the wider |
| 805 | // contents of SIMD registers. |
| 806 | bool has_simd_; |
| 807 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 808 | // Flag whether there are any loops in the graph. We can skip loop |
| 809 | // optimization if it's false. It's only best effort to keep it up |
| 810 | // to date in the presence of code elimination so there might be false |
| 811 | // positives. |
| 812 | bool has_loops_; |
| 813 | |
| 814 | // Flag whether there are any irreducible loops in the graph. It's only |
| 815 | // best effort to keep it up to date in the presence of code elimination |
| 816 | // so there might be false positives. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 817 | bool has_irreducible_loops_; |
| 818 | |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 819 | // Flag whether there are any direct calls to native code registered |
| 820 | // for @CriticalNative methods. |
| 821 | bool has_direct_critical_native_call_; |
| 822 | |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 823 | // Is the code known to be robust against eliminating dead references |
| 824 | // and the effects of early finalization? If false, dead reference variables |
| 825 | // are kept if they might be visible to the garbage collector. |
| 826 | // Currently this means that the class was declared to be dead-reference-safe, |
| 827 | // the method accesses no reachability-sensitive fields or data, and the same |
| 828 | // is true for any methods that were inlined into the current one. |
| 829 | bool dead_reference_safe_; |
| 830 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 831 | // Indicates whether the graph should be compiled in a way that |
| 832 | // ensures full debuggability. If false, we can apply more |
| 833 | // aggressive optimizations that may limit the level of debugging. |
| 834 | const bool debuggable_; |
| 835 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 836 | // 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] | 837 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 838 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 839 | // The dex file from which the method is from. |
| 840 | const DexFile& dex_file_; |
| 841 | |
| 842 | // The method index in the dex file. |
| 843 | const uint32_t method_idx_; |
| 844 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 845 | // If inlined, this encodes how the callee is being invoked. |
| 846 | const InvokeType invoke_type_; |
| 847 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 848 | // Whether the graph has been transformed to SSA form. Only used |
| 849 | // in debug mode to ensure we are not using properties only valid |
| 850 | // for non-SSA form (like the number of temporaries). |
| 851 | bool in_ssa_form_; |
| 852 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 853 | // Number of CHA guards in the graph. Used to short-circuit the |
| 854 | // CHA guard optimization pass when there is no CHA guard left. |
| 855 | uint32_t number_of_cha_guards_; |
| 856 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 857 | const InstructionSet instruction_set_; |
| 858 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 859 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 860 | HNullConstant* cached_null_constant_; |
| 861 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 862 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 863 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 864 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 865 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 866 | HCurrentMethod* cached_current_method_; |
| 867 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 868 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 869 | // for example for methods whose declaring class could not be resolved |
| 870 | // (such as when the superclass could not be found). |
| 871 | ArtMethod* art_method_; |
| 872 | |
Nicolas Geoffray | 0d60a2b | 2020-06-17 14:31:56 +0100 | [diff] [blame] | 873 | // How we are compiling the graph: either optimized, osr, or baseline. |
| 874 | // For osr, we will make all loops seen as irreducible and emit special |
| 875 | // stack maps to mark compiled code entries which the interpreter can |
| 876 | // directly jump to. |
| 877 | const CompilationKind compilation_kind_; |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 878 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 879 | // List of methods that are assumed to have single implementation. |
| 880 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 881 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 882 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 883 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 884 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 885 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 886 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 887 | }; |
| 888 | |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 889 | inline std::ostream& operator<<(std::ostream& os, HGraph& graph) { |
| 890 | return graph.Dump(os); |
| 891 | } |
| 892 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 893 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 894 | public: |
| 895 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 896 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 897 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 898 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 899 | contains_irreducible_loop_(false), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 900 | back_edges_(graph->GetAllocator()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 901 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 902 | blocks_(graph->GetAllocator(), |
| 903 | graph->GetBlocks().size(), |
| 904 | true, |
| 905 | kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 906 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 907 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 908 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 909 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 910 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 911 | |
| 912 | void Dump(std::ostream& os); |
| 913 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 914 | HBasicBlock* GetHeader() const { |
| 915 | return header_; |
| 916 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 917 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 918 | void SetHeader(HBasicBlock* block) { |
| 919 | header_ = block; |
| 920 | } |
| 921 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 922 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 923 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 924 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 925 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 926 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 927 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 930 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 931 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 932 | } |
| 933 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 934 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 935 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 936 | } |
| 937 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 938 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 939 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 940 | } |
| 941 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 942 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 943 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 944 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 945 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 946 | } |
| 947 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 948 | // Returns the lifetime position of the back edge that has the |
| 949 | // greatest lifetime position. |
| 950 | size_t GetLifetimeEnd() const; |
| 951 | |
| 952 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 953 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 954 | } |
| 955 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 956 | // Finds blocks that are part of this loop. |
| 957 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 958 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 959 | // Updates blocks population of the loop and all of its outer' ones recursively after the |
| 960 | // population of the inner loop is updated. |
| 961 | void PopulateInnerLoopUpwards(HLoopInformation* inner_loop); |
| 962 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 963 | // Returns whether this loop information contains `block`. |
| 964 | // Note that this loop information *must* be populated before entering this function. |
| 965 | bool Contains(const HBasicBlock& block) const; |
| 966 | |
| 967 | // Returns whether this loop information is an inner loop of `other`. |
| 968 | // Note that `other` *must* be populated before entering this function. |
| 969 | bool IsIn(const HLoopInformation& other) const; |
| 970 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 971 | // Returns true if instruction is not defined within this loop. |
| 972 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 973 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 974 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 975 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 976 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 977 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 978 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 979 | void ClearAllBlocks() { |
| 980 | blocks_.ClearAllBits(); |
| 981 | } |
| 982 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 983 | bool HasBackEdgeNotDominatedByHeader() const; |
| 984 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 985 | bool IsPopulated() const { |
| 986 | return blocks_.GetHighestBitSet() != -1; |
| 987 | } |
| 988 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 989 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 990 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 991 | bool HasExitEdge() const; |
| 992 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 993 | // Resets back edge and blocks-in-loop data. |
| 994 | void ResetBasicBlockData() { |
| 995 | back_edges_.clear(); |
| 996 | ClearAllBlocks(); |
| 997 | } |
| 998 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 999 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1000 | // Internal recursive implementation of `Populate`. |
| 1001 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 1002 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1003 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1004 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1005 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1006 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 1007 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1008 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1009 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1010 | |
| 1011 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 1012 | }; |
| 1013 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1014 | // Stores try/catch information for basic blocks. |
| 1015 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 1016 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1017 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1018 | public: |
| 1019 | // Try block information constructor. |
| 1020 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 1021 | : try_entry_(&try_entry), |
| 1022 | catch_dex_file_(nullptr), |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1023 | catch_type_index_(dex::TypeIndex::Invalid()) { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1024 | DCHECK(try_entry_ != nullptr); |
| 1025 | } |
| 1026 | |
| 1027 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1028 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1029 | : try_entry_(nullptr), |
| 1030 | catch_dex_file_(&dex_file), |
| 1031 | catch_type_index_(catch_type_index) {} |
| 1032 | |
| 1033 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 1034 | |
| 1035 | const HTryBoundary& GetTryEntry() const { |
| 1036 | DCHECK(IsTryBlock()); |
| 1037 | return *try_entry_; |
| 1038 | } |
| 1039 | |
| 1040 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 1041 | |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1042 | bool IsValidTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1043 | DCHECK(IsCatchBlock()); |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1044 | return catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1047 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1048 | DCHECK(IsCatchBlock()); |
| 1049 | return catch_type_index_; |
| 1050 | } |
| 1051 | |
| 1052 | const DexFile& GetCatchDexFile() const { |
| 1053 | DCHECK(IsCatchBlock()); |
| 1054 | return *catch_dex_file_; |
| 1055 | } |
| 1056 | |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1057 | void SetInvalidTypeIndex() { |
| 1058 | catch_type_index_ = dex::TypeIndex::Invalid(); |
| 1059 | } |
| 1060 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1061 | private: |
| 1062 | // One of possibly several TryBoundary instructions entering the block's try. |
| 1063 | // Only set for try blocks. |
| 1064 | const HTryBoundary* try_entry_; |
| 1065 | |
| 1066 | // Exception type information. Only set for catch blocks. |
| 1067 | const DexFile* catch_dex_file_; |
Nicolas Geoffray | ebc3b25 | 2019-01-09 10:47:02 +0000 | [diff] [blame] | 1068 | dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1069 | }; |
| 1070 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1071 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1072 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1073 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1074 | // A block in a method. Contains the list of instructions represented |
| 1075 | // as a double linked list. Each block knows its predecessors and |
| 1076 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1077 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1078 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1079 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 1080 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1081 | : graph_(graph), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1082 | predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), |
| 1083 | successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1084 | loop_information_(nullptr), |
| 1085 | dominator_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1086 | dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1087 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1088 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1089 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1090 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1091 | try_catch_information_(nullptr) { |
| 1092 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 1093 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 1094 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 1095 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1096 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1097 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1098 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 1101 | size_t GetNumberOfPredecessors() const { |
| 1102 | return GetPredecessors().size(); |
| 1103 | } |
| 1104 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1105 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1106 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 1109 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 1110 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 1111 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1112 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 1113 | return ContainsElement(successors_, block, start_from); |
| 1114 | } |
| 1115 | |
| 1116 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1117 | return dominated_blocks_; |
| 1118 | } |
| 1119 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1120 | bool IsEntryBlock() const { |
| 1121 | return graph_->GetEntryBlock() == this; |
| 1122 | } |
| 1123 | |
| 1124 | bool IsExitBlock() const { |
| 1125 | return graph_->GetExitBlock() == this; |
| 1126 | } |
| 1127 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1128 | bool IsSingleGoto() const; |
Mads Ager | 16e5289 | 2017-07-14 13:11:37 +0200 | [diff] [blame] | 1129 | bool IsSingleReturn() const; |
Mingyao Yang | 46721ef | 2017-10-05 14:45:17 -0700 | [diff] [blame] | 1130 | bool IsSingleReturnOrReturnVoidAllowingPhis() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1131 | bool IsSingleTryBoundary() const; |
| 1132 | |
| 1133 | // Returns true if this block emits nothing but a jump. |
| 1134 | bool IsSingleJump() const { |
| 1135 | HLoopInformation* loop_info = GetLoopInformation(); |
| 1136 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 1137 | // Back edges generate a suspend check. |
| 1138 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 1139 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1140 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1141 | void AddBackEdge(HBasicBlock* back_edge) { |
| 1142 | if (loop_information_ == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1143 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1144 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1145 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1146 | loop_information_->AddBackEdge(back_edge); |
| 1147 | } |
| 1148 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 1149 | // Registers a back edge; if the block was not a loop header before the call associates a newly |
| 1150 | // created loop info with it. |
| 1151 | // |
| 1152 | // Used in SuperblockCloner to preserve LoopInformation object instead of reseting loop |
| 1153 | // info for all blocks during back edges recalculation. |
| 1154 | void AddBackEdgeWhileUpdating(HBasicBlock* back_edge) { |
| 1155 | if (loop_information_ == nullptr || loop_information_->GetHeader() != this) { |
| 1156 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
| 1157 | } |
| 1158 | loop_information_->AddBackEdge(back_edge); |
| 1159 | } |
| 1160 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1161 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1162 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1163 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1164 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1165 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1166 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1167 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1168 | HBasicBlock* GetDominator() const { return dominator_; } |
| 1169 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1170 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 1171 | |
| 1172 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 1173 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 1174 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1175 | |
| 1176 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1177 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 1178 | } |
| 1179 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1180 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1181 | |
| 1182 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1183 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1186 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1187 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1188 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1189 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1190 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1191 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1192 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1193 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1194 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1195 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1196 | successors_.push_back(block); |
| 1197 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1200 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1201 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1202 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1203 | new_block->predecessors_.push_back(this); |
| 1204 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1207 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1208 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1209 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1210 | new_block->successors_.push_back(this); |
| 1211 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1214 | // Insert `this` between `predecessor` and `successor. This method |
Alex Light | 1e52a07 | 2019-06-25 09:12:04 -0700 | [diff] [blame] | 1215 | // preserves the indices, and will update the first edge found between |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1216 | // `predecessor` and `successor`. |
| 1217 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1218 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1219 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1220 | successor->predecessors_[predecessor_index] = this; |
| 1221 | predecessor->successors_[successor_index] = this; |
| 1222 | successors_.push_back(successor); |
| 1223 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1224 | } |
| 1225 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1226 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1227 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1228 | } |
| 1229 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1230 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1231 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1234 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1235 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1239 | predecessors_.push_back(block); |
| 1240 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1241 | } |
| 1242 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1243 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1244 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1245 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1246 | } |
| 1247 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1248 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1249 | DCHECK_EQ(successors_.size(), 2u); |
| 1250 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1251 | } |
| 1252 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1253 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1254 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1255 | } |
| 1256 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1257 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1258 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1259 | } |
| 1260 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1261 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1262 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1263 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1267 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1268 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1272 | // predecessors is at index `idx`. |
| 1273 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1274 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1275 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1276 | } |
| 1277 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1278 | // Create a new block between this block and its predecessors. The new block |
| 1279 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1280 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1281 | // loop and try/catch information are not updated. |
| 1282 | HBasicBlock* CreateImmediateDominator(); |
| 1283 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1284 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1285 | // created, latter block. Note that this method will add the block to the |
| 1286 | // graph, create a Goto at the end of the former block and will create an edge |
| 1287 | // 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] | 1288 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1289 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1290 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1291 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1292 | // created block. Note that this method just updates raw block information, |
| 1293 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1294 | // update the graph, reverse post order, loop information, nor make sure the |
| 1295 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1296 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1297 | |
| 1298 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1299 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1300 | |
| 1301 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1302 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1303 | // that this method does not update the graph, reverse post order, loop |
| 1304 | // information, nor make sure the blocks are consistent (for example ending |
| 1305 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1306 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1307 | |
| 1308 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1309 | // of `this` are moved to `other`. |
| 1310 | // Note that this method does not update the graph, reverse post order, loop |
| 1311 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1312 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1313 | void ReplaceWith(HBasicBlock* other); |
| 1314 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1315 | // Merges the instructions of `other` at the end of `this`. |
| 1316 | void MergeInstructionsWith(HBasicBlock* other); |
| 1317 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1318 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1319 | // order, links to predecessors, successors, dominators and deletes the block |
| 1320 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1321 | // predecessor of `other` and vice versa. |
| 1322 | void MergeWith(HBasicBlock* other); |
| 1323 | |
| 1324 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1325 | // removes it from all loops it is included in and eventually from the graph. |
| 1326 | // The block must not dominate any other block. Predecessors and successors |
| 1327 | // are safely updated. |
| 1328 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1329 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1330 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1331 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1332 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1333 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1334 | // Replace phi `initial` with `replacement` within this block. |
| 1335 | void ReplaceAndRemovePhiWith(HPhi* initial, HPhi* replacement); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1336 | // Replace instruction `initial` with `replacement` within this block. |
| 1337 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1338 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1339 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1340 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1341 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1342 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1343 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1344 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1345 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1346 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1347 | |
| 1348 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1349 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1350 | } |
| 1351 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1352 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1353 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1354 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1355 | } |
| 1356 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1357 | bool IsFirstPredecessorBackEdge() const { |
| 1358 | DCHECK(IsLoopHeader()); |
| 1359 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1360 | } |
| 1361 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1362 | HLoopInformation* GetLoopInformation() const { |
| 1363 | return loop_information_; |
| 1364 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1365 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1366 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1367 | // 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] | 1368 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1369 | void SetInLoop(HLoopInformation* info) { |
| 1370 | if (IsLoopHeader()) { |
| 1371 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1372 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1373 | loop_information_ = info; |
| 1374 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1375 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1376 | // Note that a non loop header having a loop information means this loop information |
| 1377 | // has already been populated |
| 1378 | loop_information_ = info; |
| 1379 | } else { |
| 1380 | // Block is part of an inner loop. Do not update the loop information. |
| 1381 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1382 | // at this point, because this method is being called while populating `info`. |
| 1383 | } |
| 1384 | } |
| 1385 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1386 | // Raw update of the loop information. |
| 1387 | void SetLoopInformation(HLoopInformation* info) { |
| 1388 | loop_information_ = info; |
| 1389 | } |
| 1390 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1391 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1392 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1393 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1394 | |
| 1395 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1396 | try_catch_information_ = try_catch_information; |
| 1397 | } |
| 1398 | |
| 1399 | bool IsTryBlock() const { |
| 1400 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1401 | } |
| 1402 | |
| 1403 | bool IsCatchBlock() const { |
| 1404 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1405 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1406 | |
| 1407 | // Returns the try entry that this block's successors should have. They will |
| 1408 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1409 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1410 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1411 | |
Aart Bik | 75ff2c9 | 2018-04-21 01:28:11 +0000 | [diff] [blame] | 1412 | bool HasThrowingInstructions() const; |
| 1413 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1414 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1415 | bool Dominates(HBasicBlock* block) const; |
| 1416 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1417 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1418 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1419 | |
| 1420 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1421 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1422 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1423 | bool EndsWithControlFlowInstruction() const; |
Aart Bik | 4dc09e7 | 2018-05-11 14:40:31 -0700 | [diff] [blame] | 1424 | bool EndsWithReturn() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1425 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1426 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1427 | bool HasSinglePhi() const; |
| 1428 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1429 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1430 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1431 | ArenaVector<HBasicBlock*> predecessors_; |
| 1432 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1433 | HInstructionList instructions_; |
| 1434 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1435 | HLoopInformation* loop_information_; |
| 1436 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1437 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1438 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1439 | // The dex program counter of the first instruction of this block. |
| 1440 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1441 | size_t lifetime_start_; |
| 1442 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1443 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1444 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1445 | friend class HGraph; |
| 1446 | friend class HInstruction; |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 1447 | // Allow manual control of the ordering of predecessors/successors |
| 1448 | friend class OptimizingUnitTestHelper; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1449 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1450 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1451 | }; |
| 1452 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1453 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1454 | // from the innermost to the outermost. |
| 1455 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1456 | public: |
| 1457 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1458 | : current_(block.GetLoopInformation()) {} |
| 1459 | |
| 1460 | bool Done() const { return current_ == nullptr; } |
| 1461 | |
| 1462 | void Advance() { |
| 1463 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1464 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | HLoopInformation* Current() const { |
| 1468 | DCHECK(!Done()); |
| 1469 | return current_; |
| 1470 | } |
| 1471 | |
| 1472 | private: |
| 1473 | HLoopInformation* current_; |
| 1474 | |
| 1475 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1476 | }; |
| 1477 | |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1478 | #define FOR_EACH_CONCRETE_INSTRUCTION_SCALAR_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1479 | M(Above, Condition) \ |
| 1480 | M(AboveOrEqual, Condition) \ |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 1481 | M(Abs, UnaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1482 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1483 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1484 | M(ArrayGet, Instruction) \ |
| 1485 | M(ArrayLength, Instruction) \ |
| 1486 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1487 | M(Below, Condition) \ |
| 1488 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1489 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1490 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1491 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1492 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1493 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1494 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1495 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1496 | M(Compare, BinaryOperation) \ |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1497 | M(ConstructorFence, Instruction) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1498 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1499 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1500 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1501 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1502 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1503 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1504 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1505 | M(Exit, Instruction) \ |
| 1506 | M(FloatConstant, Constant) \ |
| 1507 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1508 | M(GreaterThan, Condition) \ |
| 1509 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1510 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1511 | M(InstanceFieldGet, Instruction) \ |
| 1512 | M(InstanceFieldSet, Instruction) \ |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 1513 | M(PredicatedInstanceFieldGet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1514 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1515 | M(IntConstant, Constant) \ |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 1516 | M(IntermediateAddress, Instruction) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1517 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1518 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1519 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1520 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1521 | M(InvokePolymorphic, Invoke) \ |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1522 | M(InvokeCustom, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1523 | M(LessThan, Condition) \ |
| 1524 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1525 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1526 | M(LoadException, Instruction) \ |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 1527 | M(LoadMethodHandle, Instruction) \ |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 1528 | M(LoadMethodType, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1529 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1530 | M(LongConstant, Constant) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1531 | M(Max, Instruction) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1532 | M(MemoryBarrier, Instruction) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1533 | M(Min, BinaryOperation) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1534 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1535 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1536 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1537 | M(Neg, UnaryOperation) \ |
| 1538 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1539 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1540 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1541 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1542 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1543 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1544 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1545 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1546 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1547 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1548 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1549 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1550 | M(Return, Instruction) \ |
| 1551 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1552 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1553 | M(Shl, BinaryOperation) \ |
| 1554 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1555 | M(StaticFieldGet, Instruction) \ |
| 1556 | M(StaticFieldSet, Instruction) \ |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 1557 | M(StringBuilderAppend, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1558 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1559 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1560 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1561 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1562 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1563 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1564 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1565 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1566 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1567 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1568 | M(UShr, BinaryOperation) \ |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1569 | M(Xor, BinaryOperation) |
| 1570 | |
| 1571 | #define FOR_EACH_CONCRETE_INSTRUCTION_VECTOR_COMMON(M) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1572 | M(VecReplicateScalar, VecUnaryOperation) \ |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1573 | M(VecExtractScalar, VecUnaryOperation) \ |
| 1574 | M(VecReduce, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1575 | M(VecCnv, VecUnaryOperation) \ |
| 1576 | M(VecNeg, VecUnaryOperation) \ |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1577 | M(VecAbs, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1578 | M(VecNot, VecUnaryOperation) \ |
| 1579 | M(VecAdd, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1580 | M(VecHalvingAdd, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1581 | M(VecSub, VecBinaryOperation) \ |
| 1582 | M(VecMul, VecBinaryOperation) \ |
| 1583 | M(VecDiv, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1584 | M(VecMin, VecBinaryOperation) \ |
| 1585 | M(VecMax, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1586 | M(VecAnd, VecBinaryOperation) \ |
| 1587 | M(VecAndNot, VecBinaryOperation) \ |
| 1588 | M(VecOr, VecBinaryOperation) \ |
| 1589 | M(VecXor, VecBinaryOperation) \ |
Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1590 | M(VecSaturationAdd, VecBinaryOperation) \ |
| 1591 | M(VecSaturationSub, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1592 | M(VecShl, VecBinaryOperation) \ |
| 1593 | M(VecShr, VecBinaryOperation) \ |
| 1594 | M(VecUShr, VecBinaryOperation) \ |
Aart Bik | 8de5916 | 2017-04-21 09:42:01 -0700 | [diff] [blame] | 1595 | M(VecSetScalars, VecOperation) \ |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1596 | M(VecMultiplyAccumulate, VecOperation) \ |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1597 | M(VecSADAccumulate, VecOperation) \ |
Artem Serov | aaac0e3 | 2018-08-07 00:52:22 +0100 | [diff] [blame] | 1598 | M(VecDotProd, VecOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1599 | M(VecLoad, VecMemoryOperation) \ |
| 1600 | M(VecStore, VecMemoryOperation) \ |
Artem Serov | 0771884 | 2020-02-24 18:51:42 +0000 | [diff] [blame] | 1601 | M(VecPredSetAll, VecPredSetOperation) \ |
| 1602 | M(VecPredWhile, VecPredSetOperation) \ |
| 1603 | M(VecPredCondition, VecOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1604 | |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1605 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1606 | FOR_EACH_CONCRETE_INSTRUCTION_SCALAR_COMMON(M) \ |
| 1607 | FOR_EACH_CONCRETE_INSTRUCTION_VECTOR_COMMON(M) |
| 1608 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1609 | /* |
| 1610 | * Instructions, shared across several (not all) architectures. |
| 1611 | */ |
| 1612 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1613 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1614 | #else |
| 1615 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1616 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1617 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1618 | M(MultiplyAccumulate, Instruction) \ |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 1619 | M(IntermediateAddressIndex, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1620 | #endif |
| 1621 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1622 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1623 | |
| 1624 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1625 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1626 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1627 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1628 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1629 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1630 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1631 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1632 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1633 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1634 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1635 | |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 1636 | #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64) |
| 1637 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) \ |
Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 1638 | M(X86AndNot, Instruction) \ |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 1639 | M(X86MaskOrResetLeastSetBit, Instruction) |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 1640 | #else |
| 1641 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) |
| 1642 | #endif |
| 1643 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1644 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1645 | |
| 1646 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1647 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1648 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1649 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1650 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
| 1651 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 1652 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) \ |
| 1653 | FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(M) |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1654 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1655 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1656 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1657 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1658 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1659 | M(BinaryOperation, Instruction) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1660 | M(Invoke, Instruction) \ |
| 1661 | M(VecOperation, Instruction) \ |
| 1662 | M(VecUnaryOperation, VecOperation) \ |
| 1663 | M(VecBinaryOperation, VecOperation) \ |
Artem Serov | 0771884 | 2020-02-24 18:51:42 +0000 | [diff] [blame] | 1664 | M(VecMemoryOperation, VecOperation) \ |
| 1665 | M(VecPredSetOperation, VecOperation) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1666 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1667 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1668 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1669 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1670 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1671 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1672 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1673 | #undef FORWARD_DECLARATION |
| 1674 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1675 | #define DECLARE_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1676 | private: \ |
| 1677 | H##type& operator=(const H##type&) = delete; \ |
| 1678 | public: \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1679 | const char* DebugName() const override { return #type; } \ |
| 1680 | HInstruction* Clone(ArenaAllocator* arena) const override { \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1681 | DCHECK(IsClonable()); \ |
| 1682 | return new (arena) H##type(*this->As##type()); \ |
| 1683 | } \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1684 | void Accept(HGraphVisitor* visitor) override |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1685 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1686 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1687 | private: \ |
| 1688 | H##type& operator=(const H##type&) = delete; \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 1689 | public: |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1690 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 1691 | #define DEFAULT_COPY_CONSTRUCTOR(type) H##type(const H##type& other) = default; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1692 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1693 | template <typename T> |
Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 1694 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode>, |
| 1695 | public IntrusiveForwardListNode<HUseListNode<T>> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1696 | public: |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1697 | // Get the instruction which has this use as one of the inputs. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1698 | T GetUser() const { return user_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1699 | // Get the position of the input record that this use corresponds to. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1700 | size_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1701 | // Set the position of the input record that this use corresponds to. |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1702 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1703 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1704 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1705 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1706 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1707 | |
| 1708 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1709 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1710 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1711 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1712 | |
| 1713 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1714 | }; |
| 1715 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1716 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1717 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1718 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1719 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1720 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1721 | // by the used instructions. |
| 1722 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1723 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1724 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1725 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1726 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1727 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1728 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1729 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1730 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1731 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1732 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1736 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1737 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1738 | |
| 1739 | private: |
| 1740 | // Instruction used by the user. |
| 1741 | HInstruction* instruction_; |
| 1742 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1743 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1744 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1745 | }; |
| 1746 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1747 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1748 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1749 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1750 | struct HInputExtractor { |
| 1751 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1752 | return record.GetInstruction(); |
| 1753 | } |
| 1754 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1755 | return record.GetInstruction(); |
| 1756 | } |
| 1757 | }; |
| 1758 | |
| 1759 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1760 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1761 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1762 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1763 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1764 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1765 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1766 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1767 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1768 | * modify the value of a reference field read [although it may modify the |
| 1769 | * reference fetch prior to reading the field, which is represented by its own |
| 1770 | * write/read dependence]). The analysis makes conservative points-to |
| 1771 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1772 | * the same, and any reference read depends on any reference read without |
| 1773 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1774 | * |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1775 | * kDependsOnGCBit is defined in the following way: instructions with kDependsOnGCBit must not be |
| 1776 | * alive across the point where garbage collection might happen. |
| 1777 | * |
| 1778 | * Note: Instructions with kCanTriggerGCBit do not depend on each other. |
| 1779 | * |
| 1780 | * kCanTriggerGCBit must be used for instructions for which GC might happen on the path across |
| 1781 | * those instructions from the compiler perspective (between this instruction and the next one |
| 1782 | * in the IR). |
| 1783 | * |
| 1784 | * Note: Instructions which can cause GC only on a fatal slow path do not need |
| 1785 | * kCanTriggerGCBit as the execution never returns to the instruction next to the exceptional |
| 1786 | * one. However the execution may return to compiled code if there is a catch block in the |
| 1787 | * current method; for this purpose the TryBoundary exit instruction has kCanTriggerGCBit |
| 1788 | * set. |
| 1789 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1790 | * The internal representation uses 38-bit and is described in the table below. |
| 1791 | * The first line indicates the side effect, and for field/array accesses the |
| 1792 | * 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] | 1793 | * DataType::Type enum). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1794 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1795 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1796 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1797 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1798 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1799 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1800 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1801 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1802 | * |
| 1803 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1804 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1805 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1806 | class SideEffects : public ValueObject { |
| 1807 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1808 | SideEffects() : flags_(0) {} |
| 1809 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1810 | static SideEffects None() { |
| 1811 | return SideEffects(0); |
| 1812 | } |
| 1813 | |
| 1814 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1815 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1816 | } |
| 1817 | |
| 1818 | static SideEffects AllChanges() { |
| 1819 | return SideEffects(kAllChangeBits); |
| 1820 | } |
| 1821 | |
| 1822 | static SideEffects AllDependencies() { |
| 1823 | return SideEffects(kAllDependOnBits); |
| 1824 | } |
| 1825 | |
| 1826 | static SideEffects AllExceptGCDependency() { |
| 1827 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1828 | } |
| 1829 | |
| 1830 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1831 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1832 | } |
| 1833 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1834 | static SideEffects AllWrites() { |
| 1835 | return SideEffects(kAllWrites); |
| 1836 | } |
| 1837 | |
| 1838 | static SideEffects AllReads() { |
| 1839 | return SideEffects(kAllReads); |
| 1840 | } |
| 1841 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1842 | static SideEffects FieldWriteOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1843 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1844 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1845 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1846 | } |
| 1847 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1848 | static SideEffects ArrayWriteOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1849 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1850 | } |
| 1851 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1852 | static SideEffects FieldReadOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1853 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1854 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1855 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1856 | } |
| 1857 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1858 | static SideEffects ArrayReadOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1859 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1862 | // Returns whether GC might happen across this instruction from the compiler perspective so |
| 1863 | // the next instruction in the IR would see that. |
| 1864 | // |
| 1865 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1866 | static SideEffects CanTriggerGC() { |
| 1867 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1868 | } |
| 1869 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1870 | // Returns whether the instruction must not be alive across a GC point. |
| 1871 | // |
| 1872 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1873 | static SideEffects DependsOnGC() { |
| 1874 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1875 | } |
| 1876 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1877 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1878 | SideEffects Union(SideEffects other) const { |
| 1879 | return SideEffects(flags_ | other.flags_); |
| 1880 | } |
| 1881 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1882 | SideEffects Exclusion(SideEffects other) const { |
| 1883 | return SideEffects(flags_ & ~other.flags_); |
| 1884 | } |
| 1885 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1886 | void Add(SideEffects other) { |
| 1887 | flags_ |= other.flags_; |
| 1888 | } |
| 1889 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1890 | bool Includes(SideEffects other) const { |
| 1891 | return (other.flags_ & flags_) == other.flags_; |
| 1892 | } |
| 1893 | |
| 1894 | bool HasSideEffects() const { |
| 1895 | return (flags_ & kAllChangeBits); |
| 1896 | } |
| 1897 | |
| 1898 | bool HasDependencies() const { |
| 1899 | return (flags_ & kAllDependOnBits); |
| 1900 | } |
| 1901 | |
| 1902 | // Returns true if there are no side effects or dependencies. |
| 1903 | bool DoesNothing() const { |
| 1904 | return flags_ == 0; |
| 1905 | } |
| 1906 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1907 | // Returns true if something is written. |
| 1908 | bool DoesAnyWrite() const { |
| 1909 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1910 | } |
| 1911 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1912 | // Returns true if something is read. |
| 1913 | bool DoesAnyRead() const { |
| 1914 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1915 | } |
| 1916 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1917 | // Returns true if potentially everything is written and read |
| 1918 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1919 | bool DoesAllReadWrite() const { |
| 1920 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1921 | } |
| 1922 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1923 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1924 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1927 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1928 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1929 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1930 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1934 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1935 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1936 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1937 | for (int s = kLastBit; s >= 0; s--) { |
| 1938 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1939 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1940 | // This is a bit for the GC side effect. |
| 1941 | if (current_bit_is_set) { |
| 1942 | flags += "GC"; |
| 1943 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1944 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1945 | } else { |
| 1946 | // This is a bit for the array/field analysis. |
| 1947 | // The underscore character stands for the 'can trigger GC' bit. |
| 1948 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1949 | if (current_bit_is_set) { |
| 1950 | flags += kDebug[s]; |
| 1951 | } |
| 1952 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1953 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1954 | flags += "|"; |
| 1955 | } |
| 1956 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1957 | } |
| 1958 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1959 | } |
| 1960 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1961 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1962 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1963 | private: |
| 1964 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1965 | |
| 1966 | static constexpr int kFieldWriteOffset = 0; |
| 1967 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1968 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1969 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1970 | |
| 1971 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1972 | |
| 1973 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1974 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1975 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1976 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1977 | |
| 1978 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1979 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1980 | |
| 1981 | // Aliases. |
| 1982 | |
| 1983 | static_assert(kChangeBits == kDependOnBits, |
| 1984 | "the 'change' bits should match the 'depend on' bits."); |
| 1985 | |
| 1986 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1987 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1988 | static constexpr uint64_t kAllWrites = |
| 1989 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1990 | static constexpr uint64_t kAllReads = |
| 1991 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1992 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1993 | // 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] | 1994 | static uint64_t TypeFlag(DataType::Type type, int offset) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1995 | int shift; |
| 1996 | switch (type) { |
| 1997 | case DataType::Type::kReference: shift = 0; break; |
| 1998 | case DataType::Type::kBool: shift = 1; break; |
| 1999 | case DataType::Type::kInt8: shift = 2; break; |
| 2000 | case DataType::Type::kUint16: shift = 3; break; |
| 2001 | case DataType::Type::kInt16: shift = 4; break; |
| 2002 | case DataType::Type::kInt32: shift = 5; break; |
| 2003 | case DataType::Type::kInt64: shift = 6; break; |
| 2004 | case DataType::Type::kFloat32: shift = 7; break; |
| 2005 | case DataType::Type::kFloat64: shift = 8; break; |
| 2006 | default: |
| 2007 | LOG(FATAL) << "Unexpected data type " << type; |
| 2008 | UNREACHABLE(); |
| 2009 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2010 | DCHECK_LE(kFieldWriteOffset, shift); |
| 2011 | DCHECK_LT(shift, kArrayWriteOffset); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2012 | return UINT64_C(1) << (shift + offset); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | // Private constructor on direct flags value. |
| 2016 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 2017 | |
| 2018 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2019 | }; |
| 2020 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2021 | // 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] | 2022 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2023 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2024 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 2025 | size_t number_of_vregs, |
| 2026 | ArtMethod* method, |
| 2027 | uint32_t dex_pc, |
| 2028 | HInstruction* holder) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2029 | : vregs_(number_of_vregs, allocator->Adapter(kArenaAllocEnvironmentVRegs)), |
| 2030 | locations_(allocator->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2031 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2032 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2033 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2034 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2035 | } |
| 2036 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2037 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
| 2038 | const HEnvironment& to_copy, |
| 2039 | HInstruction* holder) |
| 2040 | : HEnvironment(allocator, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2041 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2042 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2043 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2044 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2045 | |
Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 2046 | void AllocateLocations() { |
| 2047 | DCHECK(locations_.empty()); |
| 2048 | locations_.resize(vregs_.size()); |
| 2049 | } |
| 2050 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2051 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2052 | if (parent_ != nullptr) { |
| 2053 | parent_->SetAndCopyParentChain(allocator, parent); |
| 2054 | } else { |
| 2055 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 2056 | parent_->CopyFrom(parent); |
| 2057 | if (parent->GetParent() != nullptr) { |
| 2058 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 2059 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2060 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 2063 | void CopyFrom(ArrayRef<HInstruction* const> locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 2064 | void CopyFrom(HEnvironment* environment); |
| 2065 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2066 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 2067 | // input to the loop phi instead. This is for inserting instructions that |
| 2068 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 2069 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2070 | |
| 2071 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2072 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2076 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2079 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2080 | |
Artem Serov | ca210e3 | 2017-12-15 13:43:20 +0000 | [diff] [blame] | 2081 | // Replaces the input at the position 'index' with the replacement; the replacement and old |
| 2082 | // input instructions' env_uses_ lists are adjusted. The function works similar to |
| 2083 | // HInstruction::ReplaceInput. |
| 2084 | void ReplaceInput(HInstruction* replacement, size_t index); |
| 2085 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2086 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2087 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2088 | HEnvironment* GetParent() const { return parent_; } |
| 2089 | |
| 2090 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2091 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2095 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | uint32_t GetDexPc() const { |
| 2099 | return dex_pc_; |
| 2100 | } |
| 2101 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2102 | ArtMethod* GetMethod() const { |
| 2103 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2104 | } |
| 2105 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2106 | HInstruction* GetHolder() const { |
| 2107 | return holder_; |
| 2108 | } |
| 2109 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 2110 | |
| 2111 | bool IsFromInlinedInvoke() const { |
| 2112 | return GetParent() != nullptr; |
| 2113 | } |
| 2114 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2115 | class EnvInputSelector { |
| 2116 | public: |
| 2117 | explicit EnvInputSelector(const HEnvironment* e) : env_(e) {} |
| 2118 | HInstruction* operator()(size_t s) const { |
| 2119 | return env_->GetInstructionAt(s); |
| 2120 | } |
| 2121 | private: |
| 2122 | const HEnvironment* env_; |
| 2123 | }; |
| 2124 | |
| 2125 | using HConstEnvInputRef = TransformIterator<CountIter, EnvInputSelector>; |
| 2126 | IterationRange<HConstEnvInputRef> GetEnvInputs() const { |
| 2127 | IterationRange<CountIter> range(Range(Size())); |
| 2128 | return MakeIterationRange(MakeTransformIterator(range.begin(), EnvInputSelector(this)), |
| 2129 | MakeTransformIterator(range.end(), EnvInputSelector(this))); |
| 2130 | } |
| 2131 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2132 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2133 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 2134 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2135 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 2136 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2137 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2138 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 2139 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2140 | HInstruction* const holder_; |
| 2141 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 2142 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2143 | |
| 2144 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 2145 | }; |
| 2146 | |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 2147 | std::ostream& operator<<(std::ostream& os, const HInstruction& rhs); |
| 2148 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2149 | // Iterates over the Environments |
| 2150 | class HEnvironmentIterator : public ValueObject, |
| 2151 | public std::iterator<std::forward_iterator_tag, HEnvironment*> { |
| 2152 | public: |
| 2153 | explicit HEnvironmentIterator(HEnvironment* cur) : cur_(cur) {} |
| 2154 | |
| 2155 | HEnvironment* operator*() const { |
| 2156 | return cur_; |
| 2157 | } |
| 2158 | |
| 2159 | HEnvironmentIterator& operator++() { |
| 2160 | DCHECK(cur_ != nullptr); |
| 2161 | cur_ = cur_->GetParent(); |
| 2162 | return *this; |
| 2163 | } |
| 2164 | |
| 2165 | HEnvironmentIterator operator++(int) { |
| 2166 | HEnvironmentIterator prev(*this); |
| 2167 | ++(*this); |
| 2168 | return prev; |
| 2169 | } |
| 2170 | |
| 2171 | bool operator==(const HEnvironmentIterator& other) const { |
| 2172 | return other.cur_ == cur_; |
| 2173 | } |
| 2174 | |
| 2175 | bool operator!=(const HEnvironmentIterator& other) const { |
| 2176 | return !(*this == other); |
| 2177 | } |
| 2178 | |
| 2179 | private: |
| 2180 | HEnvironment* cur_; |
| 2181 | }; |
| 2182 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2183 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2184 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2185 | #define DECLARE_KIND(type, super) k##type, |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 2186 | enum InstructionKind { // private marker to avoid generate-operator-out.py from processing. |
Vladimir Marko | e394622 | 2018-05-04 14:18:47 +0100 | [diff] [blame] | 2187 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_KIND) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2188 | kLastInstructionKind |
| 2189 | }; |
| 2190 | #undef DECLARE_KIND |
| 2191 | |
| 2192 | HInstruction(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2193 | : HInstruction(kind, DataType::Type::kVoid, side_effects, dex_pc) {} |
| 2194 | |
| 2195 | 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] | 2196 | : previous_(nullptr), |
| 2197 | next_(nullptr), |
| 2198 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2199 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2200 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2201 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2202 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2203 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2204 | locations_(nullptr), |
| 2205 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2206 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 2207 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2208 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2209 | SetPackedField<InstructionKindField>(kind); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2210 | SetPackedField<TypeField>(type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2211 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 2212 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2213 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2214 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2215 | |
Vladimir Marko | c9fcfd0 | 2021-01-05 16:57:30 +0000 | [diff] [blame] | 2216 | std::ostream& Dump(std::ostream& os, bool dump_args = false); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2217 | |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 2218 | // Helper for dumping without argument information using operator<< |
| 2219 | struct NoArgsDump { |
| 2220 | const HInstruction* ins; |
| 2221 | }; |
| 2222 | NoArgsDump DumpWithoutArgs() const { |
| 2223 | return NoArgsDump{this}; |
| 2224 | } |
| 2225 | // Helper for dumping with argument information using operator<< |
| 2226 | struct ArgsDump { |
| 2227 | const HInstruction* ins; |
| 2228 | }; |
| 2229 | ArgsDump DumpWithArgs() const { |
| 2230 | return ArgsDump{this}; |
| 2231 | } |
| 2232 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2233 | HInstruction* GetNext() const { return next_; } |
| 2234 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2235 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2236 | HInstruction* GetNextDisregardingMoves() const; |
| 2237 | HInstruction* GetPreviousDisregardingMoves() const; |
| 2238 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2239 | HBasicBlock* GetBlock() const { return block_; } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2240 | ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2241 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 2242 | bool IsInBlock() const { return block_ != nullptr; } |
| 2243 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 2244 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 2245 | bool IsIrreducibleLoopHeaderPhi() const { |
| 2246 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 2247 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2248 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2249 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 2250 | |
| 2251 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 2252 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 2253 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 2254 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 2255 | } |
| 2256 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2257 | HInputsRef GetInputs() { |
| 2258 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2259 | } |
| 2260 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2261 | HConstInputsRef GetInputs() const { |
| 2262 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2266 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2267 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 2268 | bool HasInput(HInstruction* input) const { |
| 2269 | for (const HInstruction* i : GetInputs()) { |
| 2270 | if (i == input) { |
| 2271 | return true; |
| 2272 | } |
| 2273 | } |
| 2274 | return false; |
| 2275 | } |
| 2276 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2277 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 2278 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 2279 | } |
| 2280 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2281 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 2282 | virtual const char* DebugName() const = 0; |
| 2283 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2284 | DataType::Type GetType() const { |
| 2285 | return TypeField::Decode(GetPackedFields()); |
| 2286 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2287 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2288 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2289 | |
| 2290 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2291 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2292 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2293 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2294 | // Can the instruction throw? |
| 2295 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 2296 | // 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] | 2297 | virtual bool CanThrow() const { return false; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2298 | |
| 2299 | // Does the instruction always throw an exception unconditionally? |
| 2300 | virtual bool AlwaysThrows() const { return false; } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2301 | // Will this instruction only cause async exceptions if it causes any at all? |
| 2302 | virtual bool OnlyThrowsAsyncExceptions() const { |
| 2303 | return false; |
| 2304 | } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2305 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2306 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2307 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2308 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2309 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2310 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2311 | // Does not apply for all instructions, but having this at top level greatly |
| 2312 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 2313 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2314 | virtual bool CanBeNull() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2315 | DCHECK_EQ(GetType(), DataType::Type::kReference) << "CanBeNull only applies to reference types"; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2316 | return true; |
| 2317 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2318 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2319 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 2320 | return false; |
| 2321 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2322 | |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 2323 | // If this instruction will do an implicit null check, return the `HNullCheck` associated |
| 2324 | // with it. Otherwise return null. |
| 2325 | HNullCheck* GetImplicitNullCheck() const { |
Vladimir Marko | ee1f126 | 2019-06-26 14:37:17 +0100 | [diff] [blame] | 2326 | // Go over previous non-move instructions that are emitted at use site. |
| 2327 | HInstruction* prev_not_move = GetPreviousDisregardingMoves(); |
| 2328 | while (prev_not_move != nullptr && prev_not_move->IsEmittedAtUseSite()) { |
| 2329 | if (prev_not_move->IsNullCheck()) { |
| 2330 | return prev_not_move->AsNullCheck(); |
| 2331 | } |
| 2332 | prev_not_move = prev_not_move->GetPreviousDisregardingMoves(); |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 2333 | } |
| 2334 | return nullptr; |
| 2335 | } |
| 2336 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2337 | virtual bool IsActualObject() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2338 | return GetType() == DataType::Type::kReference; |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2339 | } |
| 2340 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 2341 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2342 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2343 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2344 | DCHECK_EQ(GetType(), DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2345 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 2346 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2347 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2348 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2349 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2350 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2351 | // Note: fixup_end remains valid across push_front(). |
| 2352 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
Vladimir Marko | 3224f38 | 2020-06-23 14:19:53 +0100 | [diff] [blame] | 2353 | ArenaAllocator* allocator = user->GetBlock()->GetGraph()->GetAllocator(); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2354 | HUseListNode<HInstruction*>* new_node = |
Vladimir Marko | 3224f38 | 2020-06-23 14:19:53 +0100 | [diff] [blame] | 2355 | new (allocator) HUseListNode<HInstruction*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2356 | uses_.push_front(*new_node); |
| 2357 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2360 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2361 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2362 | // Note: env_fixup_end remains valid across push_front(). |
| 2363 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2364 | HUseListNode<HEnvironment*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2365 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HEnvironment*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2366 | env_uses_.push_front(*new_node); |
| 2367 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2368 | } |
| 2369 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2370 | void RemoveAsUserOfInput(size_t input) { |
| 2371 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2372 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2373 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2374 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2375 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2376 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2377 | void RemoveAsUserOfAllInputs() { |
| 2378 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2379 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2380 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2381 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2382 | } |
| 2383 | } |
| 2384 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2385 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2386 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2387 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2388 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2389 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2390 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2391 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2392 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2393 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2394 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2395 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2396 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2397 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2398 | !CanThrow() && |
| 2399 | !IsSuspendCheck() && |
| 2400 | !IsControlFlow() && |
| 2401 | !IsNativeDebugInfo() && |
| 2402 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2403 | // If we added an explicit barrier then we should keep it. |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2404 | !IsMemoryBarrier() && |
| 2405 | !IsConstructorFence(); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2408 | bool IsDeadAndRemovable() const { |
| 2409 | return IsRemovable() && !HasUses(); |
| 2410 | } |
| 2411 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2412 | // Does this instruction strictly dominate `other_instruction`? |
| 2413 | // Returns false if this instruction and `other_instruction` are the same. |
| 2414 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2415 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2416 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2417 | int GetId() const { return id_; } |
| 2418 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2419 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2420 | int GetSsaIndex() const { return ssa_index_; } |
| 2421 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2422 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2423 | |
| 2424 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2425 | HEnvironment* GetEnvironment() const { return environment_; } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2426 | IterationRange<HEnvironmentIterator> GetAllEnvironments() const { |
| 2427 | return MakeIterationRange(HEnvironmentIterator(GetEnvironment()), |
| 2428 | HEnvironmentIterator(nullptr)); |
| 2429 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2430 | // Set the `environment_` field. Raw because this method does not |
| 2431 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2432 | void SetRawEnvironment(HEnvironment* environment) { |
| 2433 | DCHECK(environment_ == nullptr); |
| 2434 | DCHECK_EQ(environment->GetHolder(), this); |
| 2435 | environment_ = environment; |
| 2436 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2437 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2438 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2439 | DCHECK(environment_ != nullptr); |
| 2440 | DCHECK_EQ(environment->GetHolder(), this); |
| 2441 | DCHECK(environment->GetParent() == nullptr); |
| 2442 | environment->parent_ = environment_; |
| 2443 | environment_ = environment; |
| 2444 | } |
| 2445 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2446 | void RemoveEnvironment(); |
| 2447 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2448 | // Set the environment of this instruction, copying it from `environment`. While |
| 2449 | // copying, the uses lists are being updated. |
| 2450 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2451 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2452 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2453 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2454 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2455 | if (environment->GetParent() != nullptr) { |
| 2456 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2457 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2458 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2459 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2460 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2461 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2462 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2463 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2464 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2465 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2466 | if (environment->GetParent() != nullptr) { |
| 2467 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2468 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2471 | // Returns the number of entries in the environment. Typically, that is the |
| 2472 | // number of dex registers in a method. It could be more in case of inlining. |
| 2473 | size_t EnvironmentSize() const; |
| 2474 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2475 | LocationSummary* GetLocations() const { return locations_; } |
| 2476 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2477 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2478 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2479 | void ReplaceUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 8a62a4c | 2018-07-03 09:39:07 +0100 | [diff] [blame] | 2480 | void ReplaceEnvUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2481 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2482 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2483 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2484 | // uses of this instruction by `other` are *not* updated. |
| 2485 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2486 | ReplaceWith(other); |
| 2487 | other->ReplaceInput(this, use_index); |
| 2488 | } |
| 2489 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2490 | // Move `this` instruction before `cursor` |
| 2491 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2492 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2493 | // Move `this` before its first user and out of any loops. If there is no |
| 2494 | // out-of-loop user that dominates all other users, move the instruction |
| 2495 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2496 | // |
| 2497 | // This can be used only on non-throwing instructions with no side effects that |
| 2498 | // have at least one use but no environment uses. |
| 2499 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2500 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2501 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2502 | bool Is##type() const; |
| 2503 | |
| 2504 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2505 | #undef INSTRUCTION_TYPE_CHECK |
| 2506 | |
| 2507 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2508 | const H##type* As##type() const; \ |
| 2509 | H##type* As##type(); |
| 2510 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2511 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 2512 | #undef INSTRUCTION_TYPE_CAST |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2513 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2514 | // Return a clone of the instruction if it is clonable (shallow copy by default, custom copy |
| 2515 | // if a custom copy-constructor is provided for a particular type). If IsClonable() is false for |
| 2516 | // the instruction then the behaviour of this function is undefined. |
| 2517 | // |
| 2518 | // Note: It is semantically valid to create a clone of the instruction only until |
| 2519 | // prepare_for_register_allocator phase as lifetime, intervals and codegen info are not |
| 2520 | // copied. |
| 2521 | // |
| 2522 | // Note: HEnvironment and some other fields are not copied and are set to default values, see |
| 2523 | // 'explicit HInstruction(const HInstruction& other)' for details. |
| 2524 | virtual HInstruction* Clone(ArenaAllocator* arena ATTRIBUTE_UNUSED) const { |
| 2525 | LOG(FATAL) << "Cloning is not implemented for the instruction " << |
| 2526 | DebugName() << " " << GetId(); |
| 2527 | UNREACHABLE(); |
| 2528 | } |
| 2529 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2530 | virtual bool IsFieldAccess() const { |
| 2531 | return false; |
| 2532 | } |
| 2533 | |
| 2534 | virtual const FieldInfo& GetFieldInfo() const { |
| 2535 | CHECK(IsFieldAccess()) << "Only callable on field accessors not " << DebugName() << " " |
| 2536 | << *this; |
| 2537 | LOG(FATAL) << "Must be overridden by field accessors. Not implemented by " << *this; |
| 2538 | UNREACHABLE(); |
| 2539 | } |
| 2540 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2541 | // Return whether instruction can be cloned (copied). |
| 2542 | virtual bool IsClonable() const { return false; } |
| 2543 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2544 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2545 | // TODO: this method is used by LICM and GVN with possibly different |
| 2546 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2547 | virtual bool CanBeMoved() const { return false; } |
| 2548 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2549 | // Returns whether any data encoded in the two instructions is equal. |
| 2550 | // This method does not look at the inputs. Both instructions must be |
| 2551 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2552 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2553 | return false; |
| 2554 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2555 | |
| 2556 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2557 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2558 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2559 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2560 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2561 | InstructionKind GetKind() const { return GetPackedField<InstructionKindField>(); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2562 | |
| 2563 | virtual size_t ComputeHashCode() const { |
| 2564 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2565 | for (const HInstruction* input : GetInputs()) { |
| 2566 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2567 | } |
| 2568 | return result; |
| 2569 | } |
| 2570 | |
| 2571 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2572 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2573 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2574 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2575 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2576 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2577 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2578 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2579 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2580 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2581 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2582 | |
| 2583 | // Returns whether the code generation of the instruction will require to have access |
| 2584 | // to the current method. Such instructions are: |
| 2585 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2586 | // 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] | 2587 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2588 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2589 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2590 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2591 | } |
| 2592 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2593 | // Does this instruction have any use in an environment before |
| 2594 | // control flow hits 'other'? |
| 2595 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2596 | |
| 2597 | // Remove all references to environment uses of this instruction. |
| 2598 | // The caller must ensure that this is safe to do. |
| 2599 | void RemoveEnvironmentUsers(); |
| 2600 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2601 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2602 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2603 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2604 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2605 | // If set, the machine code for this instruction is assumed to be generated by |
| 2606 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2607 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2608 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2609 | static constexpr size_t kFieldInstructionKind = kFlagReferenceTypeIsExact + 1; |
| 2610 | static constexpr size_t kFieldInstructionKindSize = |
| 2611 | MinimumBitsToStore(static_cast<size_t>(InstructionKind::kLastInstructionKind - 1)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2612 | static constexpr size_t kFieldType = |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2613 | kFieldInstructionKind + kFieldInstructionKindSize; |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2614 | static constexpr size_t kFieldTypeSize = |
| 2615 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
| 2616 | static constexpr size_t kNumberOfGenericPackedBits = kFieldType + kFieldTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2617 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2618 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2619 | static_assert(kNumberOfGenericPackedBits <= kMaxNumberOfPackedBits, |
| 2620 | "Too many generic packed fields"); |
| 2621 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2622 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
| 2623 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2624 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2625 | return GetInputRecords()[i]; |
| 2626 | } |
| 2627 | |
| 2628 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2629 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2630 | input_records[index] = input; |
| 2631 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2632 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2633 | uint32_t GetPackedFields() const { |
| 2634 | return packed_fields_; |
| 2635 | } |
| 2636 | |
| 2637 | template <size_t flag> |
| 2638 | bool GetPackedFlag() const { |
| 2639 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2640 | } |
| 2641 | |
| 2642 | template <size_t flag> |
| 2643 | void SetPackedFlag(bool value = true) { |
| 2644 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2645 | } |
| 2646 | |
| 2647 | template <typename BitFieldType> |
| 2648 | typename BitFieldType::value_type GetPackedField() const { |
| 2649 | return BitFieldType::Decode(packed_fields_); |
| 2650 | } |
| 2651 | |
| 2652 | template <typename BitFieldType> |
| 2653 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2654 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2655 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2656 | } |
| 2657 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2658 | // Copy construction for the instruction (used for Clone function). |
| 2659 | // |
| 2660 | // Fields (e.g. lifetime, intervals and codegen info) associated with phases starting from |
| 2661 | // prepare_for_register_allocator are not copied (set to default values). |
| 2662 | // |
| 2663 | // Copy constructors must be provided for every HInstruction type; default copy constructor is |
| 2664 | // fine for most of them. However for some of the instructions a custom copy constructor must be |
| 2665 | // specified (when instruction has non-trivially copyable fields and must have a special behaviour |
| 2666 | // for copying them). |
| 2667 | explicit HInstruction(const HInstruction& other) |
| 2668 | : previous_(nullptr), |
| 2669 | next_(nullptr), |
| 2670 | block_(nullptr), |
| 2671 | dex_pc_(other.dex_pc_), |
| 2672 | id_(-1), |
| 2673 | ssa_index_(-1), |
| 2674 | packed_fields_(other.packed_fields_), |
| 2675 | environment_(nullptr), |
| 2676 | locations_(nullptr), |
| 2677 | live_interval_(nullptr), |
| 2678 | lifetime_position_(kNoLifetime), |
| 2679 | side_effects_(other.side_effects_), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2680 | reference_type_handle_(other.reference_type_handle_) { |
| 2681 | } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2682 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2683 | private: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2684 | using InstructionKindField = |
| 2685 | BitField<InstructionKind, kFieldInstructionKind, kFieldInstructionKindSize>; |
| 2686 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2687 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2688 | auto before_use_node = uses_.before_begin(); |
| 2689 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2690 | HInstruction* user = use_node->GetUser(); |
| 2691 | size_t input_index = use_node->GetIndex(); |
| 2692 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2693 | before_use_node = use_node; |
| 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2698 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2699 | if (next != uses_.end()) { |
| 2700 | HInstruction* next_user = next->GetUser(); |
| 2701 | size_t next_index = next->GetIndex(); |
| 2702 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2703 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2708 | auto before_env_use_node = env_uses_.before_begin(); |
| 2709 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2710 | HEnvironment* user = env_use_node->GetUser(); |
| 2711 | size_t input_index = env_use_node->GetIndex(); |
| 2712 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2713 | before_env_use_node = env_use_node; |
| 2714 | } |
| 2715 | } |
| 2716 | |
| 2717 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2718 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2719 | if (next != env_uses_.end()) { |
| 2720 | HEnvironment* next_user = next->GetUser(); |
| 2721 | size_t next_index = next->GetIndex(); |
| 2722 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2723 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2724 | } |
| 2725 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2726 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2727 | HInstruction* previous_; |
| 2728 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2729 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2730 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2731 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2732 | // An instruction gets an id when it is added to the graph. |
| 2733 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2734 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2735 | int id_; |
| 2736 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2737 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2738 | int ssa_index_; |
| 2739 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2740 | // Packed fields. |
| 2741 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2742 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2743 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2744 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2745 | |
| 2746 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2747 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2748 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2749 | // The environment associated with this instruction. Not null if the instruction |
| 2750 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2751 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2752 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2753 | // Set by the code generator. |
| 2754 | LocationSummary* locations_; |
| 2755 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2756 | // Set by the liveness analysis. |
| 2757 | LiveInterval* live_interval_; |
| 2758 | |
| 2759 | // Set by the liveness analysis, this is the position in a linear |
| 2760 | // order of blocks where this instruction's live interval start. |
| 2761 | size_t lifetime_position_; |
| 2762 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2763 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2764 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2765 | // The reference handle part of the reference type info. |
| 2766 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2767 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2768 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2769 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2770 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2771 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2772 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2773 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2774 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2775 | }; |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2776 | |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 2777 | std::ostream& operator<<(std::ostream& os, HInstruction::InstructionKind rhs); |
Alex Light | dc281e7 | 2021-01-06 12:35:31 -0800 | [diff] [blame] | 2778 | std::ostream& operator<<(std::ostream& os, const HInstruction::NoArgsDump rhs); |
| 2779 | std::ostream& operator<<(std::ostream& os, const HInstruction::ArgsDump rhs); |
| 2780 | std::ostream& operator<<(std::ostream& os, const HUseList<HInstruction*>& lst); |
| 2781 | std::ostream& operator<<(std::ostream& os, const HUseList<HEnvironment*>& lst); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2782 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2783 | // Forward declarations for friends |
| 2784 | template <typename InnerIter> struct HSTLInstructionIterator; |
| 2785 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2786 | // Iterates over the instructions, while preserving the next instruction |
| 2787 | // in case the current instruction gets removed from the list by the user |
| 2788 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2789 | class HInstructionIterator : public ValueObject { |
| 2790 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2791 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2792 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2793 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2794 | } |
| 2795 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2796 | bool Done() const { return instruction_ == nullptr; } |
| 2797 | HInstruction* Current() const { return instruction_; } |
| 2798 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2799 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2800 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | private: |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2804 | HInstructionIterator() : instruction_(nullptr), next_(nullptr) {} |
| 2805 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2806 | HInstruction* instruction_; |
| 2807 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2808 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2809 | friend struct HSTLInstructionIterator<HInstructionIterator>; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2810 | }; |
| 2811 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2812 | // Iterates over the instructions without saving the next instruction, |
| 2813 | // therefore handling changes in the graph potentially made by the user |
| 2814 | // of this iterator. |
| 2815 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2816 | public: |
| 2817 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2818 | : instruction_(instructions.first_instruction_) { |
| 2819 | } |
| 2820 | |
| 2821 | bool Done() const { return instruction_ == nullptr; } |
| 2822 | HInstruction* Current() const { return instruction_; } |
| 2823 | void Advance() { |
| 2824 | instruction_ = instruction_->GetNext(); |
| 2825 | } |
| 2826 | |
| 2827 | private: |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2828 | HInstructionIteratorHandleChanges() : instruction_(nullptr) {} |
| 2829 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2830 | HInstruction* instruction_; |
| 2831 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2832 | friend struct HSTLInstructionIterator<HInstructionIteratorHandleChanges>; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2833 | }; |
| 2834 | |
| 2835 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2836 | class HBackwardInstructionIterator : public ValueObject { |
| 2837 | public: |
| 2838 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2839 | : instruction_(instructions.last_instruction_) { |
| 2840 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2841 | } |
| 2842 | |
| 2843 | bool Done() const { return instruction_ == nullptr; } |
| 2844 | HInstruction* Current() const { return instruction_; } |
| 2845 | void Advance() { |
| 2846 | instruction_ = next_; |
| 2847 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2848 | } |
| 2849 | |
| 2850 | private: |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2851 | HBackwardInstructionIterator() : instruction_(nullptr), next_(nullptr) {} |
| 2852 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2853 | HInstruction* instruction_; |
| 2854 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2855 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2856 | friend struct HSTLInstructionIterator<HBackwardInstructionIterator>; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2857 | }; |
| 2858 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2859 | template <typename InnerIter> |
| 2860 | struct HSTLInstructionIterator : public ValueObject, |
| 2861 | public std::iterator<std::forward_iterator_tag, HInstruction*> { |
| 2862 | public: |
| 2863 | static_assert(std::is_same_v<InnerIter, HBackwardInstructionIterator> || |
| 2864 | std::is_same_v<InnerIter, HInstructionIterator> || |
| 2865 | std::is_same_v<InnerIter, HInstructionIteratorHandleChanges>, |
| 2866 | "Unknown wrapped iterator!"); |
| 2867 | |
| 2868 | explicit HSTLInstructionIterator(InnerIter inner) : inner_(inner) {} |
| 2869 | HInstruction* operator*() const { |
| 2870 | DCHECK(inner_.Current() != nullptr); |
| 2871 | return inner_.Current(); |
| 2872 | } |
| 2873 | |
| 2874 | HSTLInstructionIterator<InnerIter>& operator++() { |
| 2875 | DCHECK(*this != HSTLInstructionIterator<InnerIter>::EndIter()); |
| 2876 | inner_.Advance(); |
| 2877 | return *this; |
| 2878 | } |
| 2879 | |
| 2880 | HSTLInstructionIterator<InnerIter> operator++(int) { |
| 2881 | HSTLInstructionIterator<InnerIter> prev(*this); |
| 2882 | ++(*this); |
| 2883 | return prev; |
| 2884 | } |
| 2885 | |
| 2886 | bool operator==(const HSTLInstructionIterator<InnerIter>& other) const { |
| 2887 | return inner_.Current() == other.inner_.Current(); |
| 2888 | } |
| 2889 | |
| 2890 | bool operator!=(const HSTLInstructionIterator<InnerIter>& other) const { |
| 2891 | return !(*this == other); |
| 2892 | } |
| 2893 | |
| 2894 | static HSTLInstructionIterator<InnerIter> EndIter() { |
| 2895 | return HSTLInstructionIterator<InnerIter>(InnerIter()); |
| 2896 | } |
| 2897 | |
| 2898 | private: |
| 2899 | InnerIter inner_; |
| 2900 | }; |
| 2901 | |
| 2902 | template <typename InnerIter> |
| 2903 | IterationRange<HSTLInstructionIterator<InnerIter>> MakeSTLInstructionIteratorRange(InnerIter iter) { |
| 2904 | return MakeIterationRange(HSTLInstructionIterator<InnerIter>(iter), |
| 2905 | HSTLInstructionIterator<InnerIter>::EndIter()); |
| 2906 | } |
| 2907 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2908 | class HVariableInputSizeInstruction : public HInstruction { |
| 2909 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2910 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2911 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2912 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2913 | } |
| 2914 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2915 | void AddInput(HInstruction* input); |
| 2916 | void InsertInputAt(size_t index, HInstruction* input); |
| 2917 | void RemoveInputAt(size_t index); |
| 2918 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2919 | // Removes all the inputs. |
| 2920 | // Also removes this instructions from each input's use list |
| 2921 | // (for non-environment uses only). |
| 2922 | void RemoveAllInputs(); |
| 2923 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2924 | protected: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2925 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2926 | SideEffects side_effects, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2927 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2928 | ArenaAllocator* allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2929 | size_t number_of_inputs, |
| 2930 | ArenaAllocKind kind) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2931 | : HInstruction(inst_kind, side_effects, dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2932 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2933 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2934 | DataType::Type type, |
| 2935 | SideEffects side_effects, |
| 2936 | uint32_t dex_pc, |
| 2937 | ArenaAllocator* allocator, |
| 2938 | size_t number_of_inputs, |
| 2939 | ArenaAllocKind kind) |
| 2940 | : HInstruction(inst_kind, type, side_effects, dex_pc), |
| 2941 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2942 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2943 | DEFAULT_COPY_CONSTRUCTOR(VariableInputSizeInstruction); |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2944 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2945 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2946 | }; |
| 2947 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2948 | template<size_t N> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2949 | class HExpression : public HInstruction { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2950 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2951 | HExpression<N>(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2952 | : HInstruction(kind, side_effects, dex_pc), inputs_() {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2953 | HExpression<N>(InstructionKind kind, |
| 2954 | DataType::Type type, |
| 2955 | SideEffects side_effects, |
| 2956 | uint32_t dex_pc) |
| 2957 | : HInstruction(kind, type, side_effects, dex_pc), inputs_() {} |
| 2958 | virtual ~HExpression() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2959 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2960 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 2961 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2962 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2963 | } |
| 2964 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2965 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2966 | DEFAULT_COPY_CONSTRUCTOR(Expression<N>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2967 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2968 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2969 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2970 | |
| 2971 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2972 | }; |
| 2973 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2974 | // HExpression specialization for N=0. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2975 | template<> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2976 | class HExpression<0> : public HInstruction { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2977 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2978 | using HInstruction::HInstruction; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2979 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2980 | virtual ~HExpression() {} |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2981 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2982 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 2983 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2984 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2985 | } |
| 2986 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2987 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2988 | DEFAULT_COPY_CONSTRUCTOR(Expression<0>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2989 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2990 | private: |
| 2991 | friend class SsaBuilder; |
| 2992 | }; |
| 2993 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2994 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2995 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2996 | class HReturnVoid final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2997 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2998 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2999 | : HExpression(kReturnVoid, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3000 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 3001 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3002 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3003 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3004 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3005 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3006 | protected: |
| 3007 | DEFAULT_COPY_CONSTRUCTOR(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3008 | }; |
| 3009 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3010 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 3011 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3012 | class HReturn final : public HExpression<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3013 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3014 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3015 | : HExpression(kReturn, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3016 | SetRawInputAt(0, value); |
| 3017 | } |
| 3018 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3019 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 3020 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3021 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3022 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3023 | protected: |
| 3024 | DEFAULT_COPY_CONSTRUCTOR(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3025 | }; |
| 3026 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3027 | class HPhi final : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3028 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3029 | HPhi(ArenaAllocator* allocator, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3030 | uint32_t reg_number, |
| 3031 | size_t number_of_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3032 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3033 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3034 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3035 | kPhi, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3036 | ToPhiType(type), |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3037 | SideEffects::None(), |
| 3038 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3039 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 3040 | number_of_inputs, |
| 3041 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3042 | reg_number_(reg_number) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3043 | DCHECK_NE(GetType(), DataType::Type::kVoid); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3044 | // Phis are constructed live and marked dead if conflicting or unused. |
| 3045 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 3046 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 3047 | SetPackedFlag<kFlagIsLive>(true); |
| 3048 | SetPackedFlag<kFlagCanBeNull>(true); |
| 3049 | } |
| 3050 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3051 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3052 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3053 | // 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] | 3054 | static DataType::Type ToPhiType(DataType::Type type) { |
| 3055 | return DataType::Kind(type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 3059 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3060 | void SetType(DataType::Type new_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3061 | // Make sure that only valid type changes occur. The following are allowed: |
| 3062 | // (1) int -> float/ref (primitive type propagation), |
| 3063 | // (2) long -> double (primitive type propagation). |
| 3064 | DCHECK(GetType() == new_type || |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3065 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kFloat32) || |
| 3066 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kReference) || |
| 3067 | (GetType() == DataType::Type::kInt64 && new_type == DataType::Type::kFloat64)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3068 | SetPackedField<TypeField>(new_type); |
| 3069 | } |
| 3070 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3071 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3072 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 3073 | |
| 3074 | uint32_t GetRegNumber() const { return reg_number_; } |
| 3075 | |
| 3076 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 3077 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 3078 | bool IsDead() const { return !IsLive(); } |
| 3079 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 3080 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 3081 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3082 | return other != nullptr |
| 3083 | && other->IsPhi() |
| 3084 | && other->AsPhi()->GetBlock() == GetBlock() |
| 3085 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 3086 | } |
| 3087 | |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 3088 | bool HasEquivalentPhi() const { |
| 3089 | if (GetPrevious() != nullptr && GetPrevious()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 3090 | return true; |
| 3091 | } |
| 3092 | if (GetNext() != nullptr && GetNext()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 3093 | return true; |
| 3094 | } |
| 3095 | return false; |
| 3096 | } |
| 3097 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3098 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 3099 | // An equivalent phi is a phi having the same dex register and type. |
| 3100 | // It assumes that phis with the same dex register are adjacent. |
| 3101 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 3102 | HInstruction* next = GetNext(); |
| 3103 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 3104 | if (next->GetType() == GetType()) { |
| 3105 | return next->AsPhi(); |
| 3106 | } |
| 3107 | next = next->GetNext(); |
| 3108 | } |
| 3109 | return nullptr; |
| 3110 | } |
| 3111 | |
| 3112 | DECLARE_INSTRUCTION(Phi); |
| 3113 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3114 | protected: |
| 3115 | DEFAULT_COPY_CONSTRUCTOR(Phi); |
| 3116 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3117 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3118 | static constexpr size_t kFlagIsLive = HInstruction::kNumberOfGenericPackedBits; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3119 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 3120 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 3121 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3122 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3123 | const uint32_t reg_number_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3124 | }; |
| 3125 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3126 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3127 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3128 | // exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3129 | class HExit final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3130 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3131 | explicit HExit(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3132 | : HExpression(kExit, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3133 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 3134 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3135 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3136 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3137 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3138 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3139 | protected: |
| 3140 | DEFAULT_COPY_CONSTRUCTOR(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3141 | }; |
| 3142 | |
| 3143 | // Jumps from one block to another. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3144 | class HGoto final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3145 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3146 | explicit HGoto(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3147 | : HExpression(kGoto, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3148 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3149 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3150 | bool IsClonable() const override { return true; } |
| 3151 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3152 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3153 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3154 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3155 | } |
| 3156 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3157 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3158 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3159 | protected: |
| 3160 | DEFAULT_COPY_CONSTRUCTOR(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3161 | }; |
| 3162 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3163 | class HConstant : public HExpression<0> { |
| 3164 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3165 | explicit HConstant(InstructionKind kind, DataType::Type type, uint32_t dex_pc = kNoDexPc) |
| 3166 | : HExpression(kind, type, SideEffects::None(), dex_pc) { |
| 3167 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3168 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3169 | bool CanBeMoved() const override { return true; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3170 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3171 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3172 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3173 | // Is this constant 0 in the arithmetic sense? |
| 3174 | virtual bool IsArithmeticZero() const { return false; } |
| 3175 | // Is this constant a 0-bit pattern? |
| 3176 | virtual bool IsZeroBitPattern() const { return false; } |
| 3177 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3178 | virtual bool IsOne() const { return false; } |
| 3179 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3180 | virtual uint64_t GetValueAsUint64() const = 0; |
| 3181 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3182 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3183 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3184 | protected: |
| 3185 | DEFAULT_COPY_CONSTRUCTOR(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3186 | }; |
| 3187 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3188 | class HNullConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3189 | public: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3190 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3191 | return true; |
| 3192 | } |
| 3193 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3194 | uint64_t GetValueAsUint64() const override { return 0; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3195 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3196 | size_t ComputeHashCode() const override { return 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3197 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3198 | // The null constant representation is a 0-bit pattern. |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame] | 3199 | bool IsZeroBitPattern() const override { return true; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3200 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3201 | DECLARE_INSTRUCTION(NullConstant); |
| 3202 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3203 | protected: |
| 3204 | DEFAULT_COPY_CONSTRUCTOR(NullConstant); |
| 3205 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3206 | private: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3207 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3208 | : HConstant(kNullConstant, DataType::Type::kReference, dex_pc) { |
| 3209 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3210 | |
| 3211 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3212 | }; |
| 3213 | |
| 3214 | // Constants of the type int. Those can be from Dex instructions, or |
| 3215 | // synthesized (for example with the if-eqz instruction). |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3216 | class HIntConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3217 | public: |
| 3218 | int32_t GetValue() const { return value_; } |
| 3219 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3220 | uint64_t GetValueAsUint64() const override { |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 3221 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 3222 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3223 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3224 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3225 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3226 | return other->AsIntConstant()->value_ == value_; |
| 3227 | } |
| 3228 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3229 | size_t ComputeHashCode() const override { return GetValue(); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3230 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3231 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 3232 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 3233 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 3234 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3235 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3236 | // Integer constants are used to encode Boolean values as well, |
| 3237 | // where 1 means true and 0 means false. |
| 3238 | bool IsTrue() const { return GetValue() == 1; } |
| 3239 | bool IsFalse() const { return GetValue() == 0; } |
| 3240 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3241 | DECLARE_INSTRUCTION(IntConstant); |
| 3242 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3243 | protected: |
| 3244 | DEFAULT_COPY_CONSTRUCTOR(IntConstant); |
| 3245 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3246 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3247 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3248 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), value_(value) { |
| 3249 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3250 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3251 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), |
| 3252 | value_(value ? 1 : 0) { |
| 3253 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3254 | |
| 3255 | const int32_t value_; |
| 3256 | |
| 3257 | friend class HGraph; |
| 3258 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 3259 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3260 | }; |
| 3261 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3262 | class HLongConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3263 | public: |
| 3264 | int64_t GetValue() const { return value_; } |
| 3265 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3266 | uint64_t GetValueAsUint64() const override { return value_; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3267 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3268 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3269 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3270 | return other->AsLongConstant()->value_ == value_; |
| 3271 | } |
| 3272 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3273 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3274 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3275 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 3276 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 3277 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 3278 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3279 | |
| 3280 | DECLARE_INSTRUCTION(LongConstant); |
| 3281 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3282 | protected: |
| 3283 | DEFAULT_COPY_CONSTRUCTOR(LongConstant); |
| 3284 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3285 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3286 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3287 | : HConstant(kLongConstant, DataType::Type::kInt64, dex_pc), |
| 3288 | value_(value) { |
| 3289 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3290 | |
| 3291 | const int64_t value_; |
| 3292 | |
| 3293 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3294 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3295 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3296 | class HFloatConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3297 | public: |
| 3298 | float GetValue() const { return value_; } |
| 3299 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3300 | uint64_t GetValueAsUint64() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3301 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3302 | } |
| 3303 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3304 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3305 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 3306 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3307 | } |
| 3308 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3309 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3310 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3311 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3312 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 3313 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3314 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3315 | return std::fpclassify(value_) == FP_ZERO; |
| 3316 | } |
| 3317 | bool IsArithmeticPositiveZero() const { |
| 3318 | return IsArithmeticZero() && !std::signbit(value_); |
| 3319 | } |
| 3320 | bool IsArithmeticNegativeZero() const { |
| 3321 | return IsArithmeticZero() && std::signbit(value_); |
| 3322 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3323 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3324 | 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] | 3325 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3326 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3327 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3328 | } |
| 3329 | bool IsNaN() const { |
| 3330 | return std::isnan(value_); |
| 3331 | } |
| 3332 | |
| 3333 | DECLARE_INSTRUCTION(FloatConstant); |
| 3334 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3335 | protected: |
| 3336 | DEFAULT_COPY_CONSTRUCTOR(FloatConstant); |
| 3337 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3338 | private: |
| 3339 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3340 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3341 | value_(value) { |
| 3342 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3343 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3344 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3345 | value_(bit_cast<float, int32_t>(value)) { |
| 3346 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3347 | |
| 3348 | const float value_; |
| 3349 | |
| 3350 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3351 | friend class SsaBuilder; |
| 3352 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3353 | }; |
| 3354 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3355 | class HDoubleConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3356 | public: |
| 3357 | double GetValue() const { return value_; } |
| 3358 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3359 | uint64_t GetValueAsUint64() const override { return bit_cast<uint64_t, double>(value_); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3360 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3361 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3362 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 3363 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3364 | } |
| 3365 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3366 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3367 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3368 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3369 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 3370 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3371 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3372 | return std::fpclassify(value_) == FP_ZERO; |
| 3373 | } |
| 3374 | bool IsArithmeticPositiveZero() const { |
| 3375 | return IsArithmeticZero() && !std::signbit(value_); |
| 3376 | } |
| 3377 | bool IsArithmeticNegativeZero() const { |
| 3378 | return IsArithmeticZero() && std::signbit(value_); |
| 3379 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3380 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3381 | 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] | 3382 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3383 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3384 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3385 | } |
| 3386 | bool IsNaN() const { |
| 3387 | return std::isnan(value_); |
| 3388 | } |
| 3389 | |
| 3390 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3391 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3392 | protected: |
| 3393 | DEFAULT_COPY_CONSTRUCTOR(DoubleConstant); |
| 3394 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3395 | private: |
| 3396 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3397 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3398 | value_(value) { |
| 3399 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3400 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3401 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3402 | value_(bit_cast<double, int64_t>(value)) { |
| 3403 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3404 | |
| 3405 | const double value_; |
| 3406 | |
| 3407 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3408 | friend class SsaBuilder; |
| 3409 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3410 | }; |
| 3411 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3412 | // Conditional branch. A block ending with an HIf instruction must have |
| 3413 | // two successors. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3414 | class HIf final : public HExpression<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3415 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3416 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3417 | : HExpression(kIf, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3418 | SetRawInputAt(0, input); |
| 3419 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3420 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3421 | bool IsClonable() const override { return true; } |
| 3422 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3423 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3424 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3425 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3426 | } |
| 3427 | |
| 3428 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3429 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3430 | } |
| 3431 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3432 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3433 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3434 | protected: |
| 3435 | DEFAULT_COPY_CONSTRUCTOR(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3436 | }; |
| 3437 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3438 | |
| 3439 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 3440 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 3441 | // non-exceptional control flow. |
| 3442 | // Normal-flow successor is stored at index zero, exception handlers under |
| 3443 | // higher indices in no particular order. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3444 | class HTryBoundary final : public HExpression<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3445 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3446 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3447 | kEntry, |
| 3448 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3449 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3450 | }; |
| 3451 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3452 | // SideEffects::CanTriggerGC prevents instructions with SideEffects::DependOnGC to be alive |
| 3453 | // across the catch block entering edges as GC might happen during throwing an exception. |
| 3454 | // TryBoundary with BoundaryKind::kExit is conservatively used for that as there is no |
| 3455 | // HInstruction which a catch block must start from. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3456 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3457 | : HExpression(kTryBoundary, |
| 3458 | (kind == BoundaryKind::kExit) ? SideEffects::CanTriggerGC() |
| 3459 | : SideEffects::None(), |
| 3460 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3461 | SetPackedField<BoundaryKindField>(kind); |
| 3462 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3463 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3464 | bool IsControlFlow() const override { return true; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3465 | |
| 3466 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3467 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3468 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 3469 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 3470 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 3471 | } |
| 3472 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3473 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 3474 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3475 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 3476 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 3477 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | // If not present already, adds `handler` to its block's list of exception |
| 3481 | // handlers. |
| 3482 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3483 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3484 | GetBlock()->AddSuccessor(handler); |
| 3485 | } |
| 3486 | } |
| 3487 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3488 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 3489 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3490 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3491 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 3492 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3493 | DECLARE_INSTRUCTION(TryBoundary); |
| 3494 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3495 | protected: |
| 3496 | DEFAULT_COPY_CONSTRUCTOR(TryBoundary); |
| 3497 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3498 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3499 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 3500 | static constexpr size_t kFieldBoundaryKindSize = |
| 3501 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 3502 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 3503 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 3504 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 3505 | "Too many packed fields."); |
| 3506 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3507 | }; |
| 3508 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3509 | // Deoptimize to interpreter, upon checking a condition. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3510 | class HDeoptimize final : public HVariableInputSizeInstruction { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3511 | public: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3512 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 3513 | // across. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3514 | HDeoptimize(ArenaAllocator* allocator, |
| 3515 | HInstruction* cond, |
| 3516 | DeoptimizationKind kind, |
| 3517 | uint32_t dex_pc) |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3518 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3519 | kDeoptimize, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3520 | SideEffects::All(), |
| 3521 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3522 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3523 | /* number_of_inputs= */ 1, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3524 | kArenaAllocMisc) { |
| 3525 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 3526 | SetPackedField<DeoptimizeKindField>(kind); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3527 | SetRawInputAt(0, cond); |
| 3528 | } |
| 3529 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3530 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3531 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3532 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3533 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3534 | // instead of `guard`. |
| 3535 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3536 | // at the point of the `HDeoptimize`. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3537 | HDeoptimize(ArenaAllocator* allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3538 | HInstruction* cond, |
| 3539 | HInstruction* guard, |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3540 | DeoptimizationKind kind, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3541 | uint32_t dex_pc) |
| 3542 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3543 | kDeoptimize, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3544 | guard->GetType(), |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3545 | SideEffects::CanTriggerGC(), |
| 3546 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3547 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3548 | /* number_of_inputs= */ 2, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3549 | kArenaAllocMisc) { |
| 3550 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3551 | SetPackedField<DeoptimizeKindField>(kind); |
| 3552 | SetRawInputAt(0, cond); |
| 3553 | SetRawInputAt(1, guard); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3554 | } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3555 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3556 | bool CanBeMoved() const override { return GetPackedFlag<kFieldCanBeMoved>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3557 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3558 | bool InstructionDataEquals(const HInstruction* other) const override { |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3559 | return (other->CanBeMoved() == CanBeMoved()) && (other->AsDeoptimize()->GetKind() == GetKind()); |
| 3560 | } |
| 3561 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3562 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3563 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3564 | bool CanThrow() const override { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3565 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3566 | DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3567 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3568 | bool GuardsAnInput() const { |
| 3569 | return InputCount() == 2; |
| 3570 | } |
| 3571 | |
| 3572 | HInstruction* GuardedInput() const { |
| 3573 | DCHECK(GuardsAnInput()); |
| 3574 | return InputAt(1); |
| 3575 | } |
| 3576 | |
| 3577 | void RemoveGuard() { |
| 3578 | RemoveInputAt(1); |
| 3579 | } |
| 3580 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3581 | DECLARE_INSTRUCTION(Deoptimize); |
| 3582 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3583 | protected: |
| 3584 | DEFAULT_COPY_CONSTRUCTOR(Deoptimize); |
| 3585 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3586 | private: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3587 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3588 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3589 | static constexpr size_t kFieldDeoptimizeKindSize = |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3590 | MinimumBitsToStore(static_cast<size_t>(DeoptimizationKind::kLast)); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3591 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3592 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3593 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3594 | "Too many packed fields."); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3595 | using DeoptimizeKindField = |
| 3596 | BitField<DeoptimizationKind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3597 | }; |
| 3598 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3599 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3600 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3601 | // if it's true, starts to do deoptimization. |
| 3602 | // It has a 4-byte slot on stack. |
| 3603 | // TODO: allocate a register for this flag. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3604 | class HShouldDeoptimizeFlag final : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3605 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3606 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3607 | // with regard to other passes. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3608 | HShouldDeoptimizeFlag(ArenaAllocator* allocator, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3609 | : HVariableInputSizeInstruction(kShouldDeoptimizeFlag, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3610 | DataType::Type::kInt32, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3611 | SideEffects::None(), |
| 3612 | dex_pc, |
| 3613 | allocator, |
| 3614 | 0, |
| 3615 | kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3618 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3619 | // further guard elimination/motion since a guard might have been used for justification |
| 3620 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3621 | // to avoid other optimizations trying to move it. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3622 | bool CanBeMoved() const override { return false; } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3623 | |
| 3624 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3625 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3626 | protected: |
| 3627 | DEFAULT_COPY_CONSTRUCTOR(ShouldDeoptimizeFlag); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3628 | }; |
| 3629 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3630 | // Represents the ArtMethod that was passed as a first argument to |
| 3631 | // the method. It is used by instructions that depend on it, like |
| 3632 | // instructions that work with the dex cache. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3633 | class HCurrentMethod final : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3634 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3635 | explicit HCurrentMethod(DataType::Type type, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3636 | : HExpression(kCurrentMethod, type, SideEffects::None(), dex_pc) { |
| 3637 | } |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3638 | |
| 3639 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3640 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3641 | protected: |
| 3642 | DEFAULT_COPY_CONSTRUCTOR(CurrentMethod); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3643 | }; |
| 3644 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3645 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3646 | // of a class. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3647 | class HClassTableGet final : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3648 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3649 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3650 | kVTable, |
| 3651 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3652 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3653 | }; |
| 3654 | HClassTableGet(HInstruction* cls, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3655 | DataType::Type type, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3656 | TableKind kind, |
| 3657 | size_t index, |
| 3658 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3659 | : HExpression(kClassTableGet, type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3660 | index_(index) { |
| 3661 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3662 | SetRawInputAt(0, cls); |
| 3663 | } |
| 3664 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3665 | bool IsClonable() const override { return true; } |
| 3666 | bool CanBeMoved() const override { return true; } |
| 3667 | bool InstructionDataEquals(const HInstruction* other) const override { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3668 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3669 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3670 | } |
| 3671 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3672 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3673 | size_t GetIndex() const { return index_; } |
| 3674 | |
| 3675 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3676 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3677 | protected: |
| 3678 | DEFAULT_COPY_CONSTRUCTOR(ClassTableGet); |
| 3679 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3680 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3681 | static constexpr size_t kFieldTableKind = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3682 | static constexpr size_t kFieldTableKindSize = |
| 3683 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3684 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3685 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3686 | "Too many packed fields."); |
| 3687 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3688 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3689 | // The index of the ArtMethod in the table. |
| 3690 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3691 | }; |
| 3692 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3693 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3694 | // have one successor for each entry in the switch table, and the final successor |
| 3695 | // will be the block containing the next Dex opcode. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3696 | class HPackedSwitch final : public HExpression<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3697 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3698 | HPackedSwitch(int32_t start_value, |
| 3699 | uint32_t num_entries, |
| 3700 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3701 | uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3702 | : HExpression(kPackedSwitch, SideEffects::None(), dex_pc), |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3703 | start_value_(start_value), |
| 3704 | num_entries_(num_entries) { |
| 3705 | SetRawInputAt(0, input); |
| 3706 | } |
| 3707 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3708 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3709 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3710 | bool IsControlFlow() const override { return true; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3711 | |
| 3712 | int32_t GetStartValue() const { return start_value_; } |
| 3713 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3714 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3715 | |
| 3716 | HBasicBlock* GetDefaultBlock() const { |
| 3717 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3718 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3719 | } |
| 3720 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3721 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3722 | protected: |
| 3723 | DEFAULT_COPY_CONSTRUCTOR(PackedSwitch); |
| 3724 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3725 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3726 | const int32_t start_value_; |
| 3727 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3728 | }; |
| 3729 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3730 | class HUnaryOperation : public HExpression<1> { |
| 3731 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3732 | HUnaryOperation(InstructionKind kind, |
| 3733 | DataType::Type result_type, |
| 3734 | HInstruction* input, |
| 3735 | uint32_t dex_pc = kNoDexPc) |
| 3736 | : HExpression(kind, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3737 | SetRawInputAt(0, input); |
| 3738 | } |
| 3739 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3740 | // All of the UnaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3741 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3742 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3743 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3744 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3745 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3746 | bool CanBeMoved() const override { return true; } |
| 3747 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3748 | return true; |
| 3749 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3750 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3751 | // Try to statically evaluate `this` and return a HConstant |
| 3752 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3753 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3754 | HConstant* TryStaticEvaluation() const; |
| 3755 | |
| 3756 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3757 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3758 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3759 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3760 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3761 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3762 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3763 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3764 | protected: |
| 3765 | DEFAULT_COPY_CONSTRUCTOR(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3766 | }; |
| 3767 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3768 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3769 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3770 | HBinaryOperation(InstructionKind kind, |
| 3771 | DataType::Type result_type, |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3772 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3773 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3774 | SideEffects side_effects = SideEffects::None(), |
| 3775 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3776 | : HExpression(kind, result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3777 | SetRawInputAt(0, left); |
| 3778 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3779 | } |
| 3780 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3781 | // All of the BinaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3782 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3783 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3784 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3785 | HInstruction* GetRight() const { return InputAt(1); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3786 | DataType::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3787 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3788 | virtual bool IsCommutative() const { return false; } |
| 3789 | |
| 3790 | // Put constant on the right. |
| 3791 | // Returns whether order is changed. |
| 3792 | bool OrderInputsWithConstantOnTheRight() { |
| 3793 | HInstruction* left = InputAt(0); |
| 3794 | HInstruction* right = InputAt(1); |
| 3795 | if (left->IsConstant() && !right->IsConstant()) { |
| 3796 | ReplaceInput(right, 0); |
| 3797 | ReplaceInput(left, 1); |
| 3798 | return true; |
| 3799 | } |
| 3800 | return false; |
| 3801 | } |
| 3802 | |
| 3803 | // Order inputs by instruction id, but favor constant on the right side. |
| 3804 | // This helps GVN for commutative ops. |
| 3805 | void OrderInputs() { |
| 3806 | DCHECK(IsCommutative()); |
| 3807 | HInstruction* left = InputAt(0); |
| 3808 | HInstruction* right = InputAt(1); |
| 3809 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3810 | return; |
| 3811 | } |
| 3812 | if (OrderInputsWithConstantOnTheRight()) { |
| 3813 | return; |
| 3814 | } |
| 3815 | // Order according to instruction id. |
| 3816 | if (left->GetId() > right->GetId()) { |
| 3817 | ReplaceInput(right, 0); |
| 3818 | ReplaceInput(left, 1); |
| 3819 | } |
| 3820 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3821 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3822 | bool CanBeMoved() const override { return true; } |
| 3823 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3824 | return true; |
| 3825 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3826 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3827 | // Try to statically evaluate `this` and return a HConstant |
| 3828 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3829 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3830 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3831 | |
| 3832 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3833 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3834 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3835 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3836 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3837 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3838 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3839 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3840 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3841 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3842 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3843 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3844 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3845 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3846 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3847 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3848 | // 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] | 3849 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3850 | HConstant* GetConstantRight() const; |
| 3851 | |
| 3852 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3853 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3854 | HInstruction* GetLeastConstantLeft() const; |
| 3855 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3856 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3857 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3858 | protected: |
| 3859 | DEFAULT_COPY_CONSTRUCTOR(BinaryOperation); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3860 | }; |
| 3861 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3862 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3863 | // comparisons are treated: |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 3864 | 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] | 3865 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3866 | kGtBias, // return 1 for NaN comparisons |
| 3867 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3868 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3869 | }; |
| 3870 | |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 3871 | std::ostream& operator<<(std::ostream& os, ComparisonBias rhs); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3872 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3873 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3874 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3875 | HCondition(InstructionKind kind, |
| 3876 | HInstruction* first, |
| 3877 | HInstruction* second, |
| 3878 | uint32_t dex_pc = kNoDexPc) |
| 3879 | : HBinaryOperation(kind, |
| 3880 | DataType::Type::kBool, |
| 3881 | first, |
| 3882 | second, |
| 3883 | SideEffects::None(), |
| 3884 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3885 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3886 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3887 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3888 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3889 | // `instruction`, and disregard moves in between. |
| 3890 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3891 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3892 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3893 | |
| 3894 | virtual IfCondition GetCondition() const = 0; |
| 3895 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3896 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3897 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3898 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3899 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3900 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3901 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3902 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3903 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3904 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3905 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3906 | } |
| 3907 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3908 | bool IsFPConditionTrueIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3909 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3910 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3911 | if (if_cond == kCondNE) { |
| 3912 | return true; |
| 3913 | } else if (if_cond == kCondEQ) { |
| 3914 | return false; |
| 3915 | } |
| 3916 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | bool IsFPConditionFalseIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3920 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3921 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3922 | if (if_cond == kCondEQ) { |
| 3923 | return true; |
| 3924 | } else if (if_cond == kCondNE) { |
| 3925 | return false; |
| 3926 | } |
| 3927 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3928 | } |
| 3929 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3930 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3931 | // Needed if we merge a HCompare into a HCondition. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3932 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3933 | static constexpr size_t kFieldComparisonBiasSize = |
| 3934 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3935 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3936 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3937 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3938 | using ComparisonBiasField = |
| 3939 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3940 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3941 | template <typename T> |
| 3942 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3943 | |
| 3944 | template <typename T> |
| 3945 | int32_t CompareFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3946 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3947 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3948 | // Handle the bias. |
| 3949 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3950 | } |
| 3951 | |
| 3952 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3953 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3954 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3955 | } |
| 3956 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3957 | DEFAULT_COPY_CONSTRUCTOR(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3958 | }; |
| 3959 | |
| 3960 | // Instruction to check if two inputs are equal to each other. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3961 | class HEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3962 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3963 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3964 | : HCondition(kEqual, first, second, dex_pc) { |
| 3965 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3966 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3967 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3968 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3969 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3970 | HNullConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3971 | return MakeConstantCondition(true, GetDexPc()); |
| 3972 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3973 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3974 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3975 | } |
| 3976 | // In the following Evaluate methods, a HCompare instruction has |
| 3977 | // been merged into this HEqual instruction; evaluate it as |
| 3978 | // `Compare(x, y) == 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3979 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3980 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3981 | GetDexPc()); |
| 3982 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3983 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3984 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3985 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3986 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3987 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3988 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3989 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3990 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3991 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3992 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3993 | return kCondEQ; |
| 3994 | } |
| 3995 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3996 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3997 | return kCondNE; |
| 3998 | } |
| 3999 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4000 | protected: |
| 4001 | DEFAULT_COPY_CONSTRUCTOR(Equal); |
| 4002 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 4003 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4004 | 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] | 4005 | }; |
| 4006 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4007 | class HNotEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4008 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4009 | HNotEqual(HInstruction* first, HInstruction* second, |
| 4010 | uint32_t dex_pc = kNoDexPc) |
| 4011 | : HCondition(kNotEqual, first, second, dex_pc) { |
| 4012 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4013 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4014 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4015 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 4016 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4017 | HNullConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4018 | return MakeConstantCondition(false, GetDexPc()); |
| 4019 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4020 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4021 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4022 | } |
| 4023 | // In the following Evaluate methods, a HCompare instruction has |
| 4024 | // been merged into this HNotEqual instruction; evaluate it as |
| 4025 | // `Compare(x, y) != 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4026 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4027 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4028 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4029 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4030 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4031 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4032 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4033 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 4034 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4035 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4036 | DECLARE_INSTRUCTION(NotEqual); |
| 4037 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4038 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4039 | return kCondNE; |
| 4040 | } |
| 4041 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4042 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4043 | return kCondEQ; |
| 4044 | } |
| 4045 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4046 | protected: |
| 4047 | DEFAULT_COPY_CONSTRUCTOR(NotEqual); |
| 4048 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4049 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4050 | 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] | 4051 | }; |
| 4052 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4053 | class HLessThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4054 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4055 | HLessThan(HInstruction* first, HInstruction* second, |
| 4056 | uint32_t dex_pc = kNoDexPc) |
| 4057 | : HCondition(kLessThan, first, second, dex_pc) { |
| 4058 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4059 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4060 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4061 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4062 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4063 | // In the following Evaluate methods, a HCompare instruction has |
| 4064 | // been merged into this HLessThan instruction; evaluate it as |
| 4065 | // `Compare(x, y) < 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4066 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4067 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4068 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4069 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4070 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4071 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4072 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4073 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4074 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4075 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4076 | DECLARE_INSTRUCTION(LessThan); |
| 4077 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4078 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4079 | return kCondLT; |
| 4080 | } |
| 4081 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4082 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4083 | return kCondGE; |
| 4084 | } |
| 4085 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4086 | protected: |
| 4087 | DEFAULT_COPY_CONSTRUCTOR(LessThan); |
| 4088 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4089 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4090 | 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] | 4091 | }; |
| 4092 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4093 | class HLessThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4094 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4095 | HLessThanOrEqual(HInstruction* first, HInstruction* second, |
| 4096 | uint32_t dex_pc = kNoDexPc) |
| 4097 | : HCondition(kLessThanOrEqual, first, second, dex_pc) { |
| 4098 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4099 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4100 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4101 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4102 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4103 | // In the following Evaluate methods, a HCompare instruction has |
| 4104 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 4105 | // `Compare(x, y) <= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4106 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4107 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4108 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4109 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4110 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4111 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4112 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4113 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4114 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4115 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4116 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 4117 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4118 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4119 | return kCondLE; |
| 4120 | } |
| 4121 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4122 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4123 | return kCondGT; |
| 4124 | } |
| 4125 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4126 | protected: |
| 4127 | DEFAULT_COPY_CONSTRUCTOR(LessThanOrEqual); |
| 4128 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4129 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4130 | 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] | 4131 | }; |
| 4132 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4133 | class HGreaterThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4134 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4135 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4136 | : HCondition(kGreaterThan, first, second, dex_pc) { |
| 4137 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4138 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4139 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4140 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4141 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4142 | // In the following Evaluate methods, a HCompare instruction has |
| 4143 | // been merged into this HGreaterThan instruction; evaluate it as |
| 4144 | // `Compare(x, y) > 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4145 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4146 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4147 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4148 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4149 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4150 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4151 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4152 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4153 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4154 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4155 | DECLARE_INSTRUCTION(GreaterThan); |
| 4156 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4157 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4158 | return kCondGT; |
| 4159 | } |
| 4160 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4161 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4162 | return kCondLE; |
| 4163 | } |
| 4164 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4165 | protected: |
| 4166 | DEFAULT_COPY_CONSTRUCTOR(GreaterThan); |
| 4167 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4168 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4169 | 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] | 4170 | }; |
| 4171 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4172 | class HGreaterThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4173 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4174 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4175 | : HCondition(kGreaterThanOrEqual, first, second, dex_pc) { |
| 4176 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4177 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4178 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4179 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4180 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4181 | // In the following Evaluate methods, a HCompare instruction has |
| 4182 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 4183 | // `Compare(x, y) >= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4184 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4185 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4186 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4187 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4188 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 4189 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4190 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4191 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4192 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4193 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4194 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 4195 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4196 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4197 | return kCondGE; |
| 4198 | } |
| 4199 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4200 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4201 | return kCondLT; |
| 4202 | } |
| 4203 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4204 | protected: |
| 4205 | DEFAULT_COPY_CONSTRUCTOR(GreaterThanOrEqual); |
| 4206 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4207 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4208 | 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] | 4209 | }; |
| 4210 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4211 | class HBelow final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4212 | public: |
| 4213 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4214 | : HCondition(kBelow, first, second, dex_pc) { |
| 4215 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4216 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4217 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4218 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4219 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4220 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4221 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4222 | } |
| 4223 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4224 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4225 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4226 | UNREACHABLE(); |
| 4227 | } |
| 4228 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4229 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4230 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4231 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | DECLARE_INSTRUCTION(Below); |
| 4235 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4236 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4237 | return kCondB; |
| 4238 | } |
| 4239 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4240 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4241 | return kCondAE; |
| 4242 | } |
| 4243 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4244 | protected: |
| 4245 | DEFAULT_COPY_CONSTRUCTOR(Below); |
| 4246 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4247 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4248 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4249 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 4250 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4251 | }; |
| 4252 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4253 | class HBelowOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4254 | public: |
| 4255 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4256 | : HCondition(kBelowOrEqual, first, second, dex_pc) { |
| 4257 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4258 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4259 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4260 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4261 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4262 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4263 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4264 | } |
| 4265 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4266 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4267 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4268 | UNREACHABLE(); |
| 4269 | } |
| 4270 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4271 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4272 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4273 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4274 | } |
| 4275 | |
| 4276 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 4277 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4278 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4279 | return kCondBE; |
| 4280 | } |
| 4281 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4282 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4283 | return kCondA; |
| 4284 | } |
| 4285 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4286 | protected: |
| 4287 | DEFAULT_COPY_CONSTRUCTOR(BelowOrEqual); |
| 4288 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4289 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4290 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4291 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 4292 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4293 | }; |
| 4294 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4295 | class HAbove final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4296 | public: |
| 4297 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4298 | : HCondition(kAbove, first, second, dex_pc) { |
| 4299 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4300 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4301 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4302 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4303 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4304 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4305 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4306 | } |
| 4307 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4308 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4309 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4310 | UNREACHABLE(); |
| 4311 | } |
| 4312 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4313 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4314 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4315 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | DECLARE_INSTRUCTION(Above); |
| 4319 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4320 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4321 | return kCondA; |
| 4322 | } |
| 4323 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4324 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4325 | return kCondBE; |
| 4326 | } |
| 4327 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4328 | protected: |
| 4329 | DEFAULT_COPY_CONSTRUCTOR(Above); |
| 4330 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4331 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4332 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4333 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 4334 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4335 | }; |
| 4336 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4337 | class HAboveOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4338 | public: |
| 4339 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4340 | : HCondition(kAboveOrEqual, first, second, dex_pc) { |
| 4341 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4342 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4343 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4344 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4345 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4346 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4347 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4348 | } |
| 4349 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4350 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4351 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4352 | UNREACHABLE(); |
| 4353 | } |
| 4354 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4355 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4356 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4357 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 4361 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4362 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4363 | return kCondAE; |
| 4364 | } |
| 4365 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4366 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4367 | return kCondB; |
| 4368 | } |
| 4369 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4370 | protected: |
| 4371 | DEFAULT_COPY_CONSTRUCTOR(AboveOrEqual); |
| 4372 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4373 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4374 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4375 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 4376 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4377 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4378 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4379 | // Instruction to check how two inputs compare to each other. |
| 4380 | // 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] | 4381 | class HCompare final : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4382 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4383 | // Note that `comparison_type` is the type of comparison performed |
| 4384 | // between the comparison's inputs, not the type of the instantiated |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4385 | // HCompare instruction (which is always DataType::Type::kInt). |
| 4386 | HCompare(DataType::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4387 | HInstruction* first, |
| 4388 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4389 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4390 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4391 | : HBinaryOperation(kCompare, |
| 4392 | DataType::Type::kInt32, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4393 | first, |
| 4394 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4395 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4396 | dex_pc) { |
| 4397 | SetPackedField<ComparisonBiasField>(bias); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4398 | } |
| 4399 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4400 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4401 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 4402 | |
| 4403 | template <typename T> |
| 4404 | int32_t ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4405 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4406 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 4407 | // Handle the bias. |
| 4408 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 4409 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4410 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4411 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4412 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 4413 | // reach this code path when processing a freshly built HIR |
| 4414 | // graph. However HCompare integer instructions can be synthesized |
| 4415 | // by the instruction simplifier to implement IntegerCompare and |
| 4416 | // IntegerSignum intrinsics, so we have to handle this case. |
| 4417 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4418 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4419 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4420 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4421 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4422 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4423 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4424 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4425 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4426 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4427 | } |
| 4428 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4429 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4430 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4431 | } |
| 4432 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4433 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4434 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4435 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4436 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4437 | bool IsGtBias() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4438 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4439 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4440 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4441 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4442 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type type ATTRIBUTE_UNUSED) { |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 4443 | // Comparisons do not require a runtime call in any back end. |
| 4444 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4445 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4446 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4447 | DECLARE_INSTRUCTION(Compare); |
| 4448 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4449 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4450 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4451 | static constexpr size_t kFieldComparisonBiasSize = |
| 4452 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 4453 | static constexpr size_t kNumberOfComparePackedBits = |
| 4454 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 4455 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4456 | using ComparisonBiasField = |
| 4457 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 4458 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4459 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 4460 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 4461 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 4462 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 4463 | } |
| 4464 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4465 | DEFAULT_COPY_CONSTRUCTOR(Compare); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4466 | }; |
| 4467 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4468 | class HNewInstance final : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4469 | public: |
| 4470 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4471 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4472 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4473 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4474 | bool finalizable, |
| 4475 | QuickEntrypointEnum entrypoint) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4476 | : HExpression(kNewInstance, |
| 4477 | DataType::Type::kReference, |
| 4478 | SideEffects::CanTriggerGC(), |
| 4479 | dex_pc), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4480 | type_index_(type_index), |
| 4481 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4482 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4483 | SetPackedFlag<kFlagFinalizable>(finalizable); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4484 | SetPackedFlag<kFlagPartialMaterialization>(false); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4485 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4486 | } |
| 4487 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4488 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4489 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4490 | void SetPartialMaterialization() { |
| 4491 | SetPackedFlag<kFlagPartialMaterialization>(true); |
| 4492 | } |
| 4493 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4494 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4495 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4496 | |
| 4497 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4498 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4499 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4500 | // 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] | 4501 | bool CanThrow() const override { return true; } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4502 | bool OnlyThrowsAsyncExceptions() const override { |
| 4503 | return !IsFinalizable() && !NeedsChecks(); |
| 4504 | } |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4505 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4506 | bool NeedsChecks() const { |
| 4507 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 4508 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4509 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4510 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4511 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4512 | bool CanBeNull() const override { return false; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4513 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4514 | bool IsPartialMaterialization() const { |
| 4515 | return GetPackedFlag<kFlagPartialMaterialization>(); |
| 4516 | } |
| 4517 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4518 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4519 | |
| 4520 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 4521 | entrypoint_ = entrypoint; |
| 4522 | } |
| 4523 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4524 | HLoadClass* GetLoadClass() const { |
| 4525 | HInstruction* input = InputAt(0); |
| 4526 | if (input->IsClinitCheck()) { |
| 4527 | input = input->InputAt(0); |
| 4528 | } |
| 4529 | DCHECK(input->IsLoadClass()); |
| 4530 | return input->AsLoadClass(); |
| 4531 | } |
| 4532 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4533 | bool IsStringAlloc() const; |
| 4534 | |
| 4535 | DECLARE_INSTRUCTION(NewInstance); |
| 4536 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4537 | protected: |
| 4538 | DEFAULT_COPY_CONSTRUCTOR(NewInstance); |
| 4539 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4540 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4541 | static constexpr size_t kFlagFinalizable = kNumberOfGenericPackedBits; |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4542 | static constexpr size_t kFlagPartialMaterialization = kFlagFinalizable + 1; |
| 4543 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagPartialMaterialization + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4544 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 4545 | "Too many packed fields."); |
| 4546 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4547 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4548 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4549 | QuickEntrypointEnum entrypoint_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4550 | }; |
| 4551 | |
Nicolas Geoffray | 8f2eb25 | 2020-11-06 13:39:54 +0000 | [diff] [blame] | 4552 | enum IntrinsicNeedsEnvironment { |
| 4553 | kNoEnvironment, // Intrinsic does not require an environment. |
| 4554 | kNeedsEnvironment // Intrinsic requires an environment. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4555 | }; |
| 4556 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4557 | enum IntrinsicSideEffects { |
| 4558 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 4559 | kReadSideEffects, // Intrinsic may read heap memory. |
| 4560 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 4561 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 4562 | }; |
| 4563 | |
| 4564 | enum IntrinsicExceptions { |
| 4565 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 4566 | kCanThrow // Intrinsic may throw exceptions. |
| 4567 | }; |
| 4568 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4569 | // Determines how to load an ArtMethod*. |
| 4570 | enum class MethodLoadKind { |
| 4571 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4572 | kStringInit, |
| 4573 | |
| 4574 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4575 | kRecursive, |
| 4576 | |
| 4577 | // Use PC-relative boot image ArtMethod* address that will be known at link time. |
| 4578 | // Used for boot image methods referenced by boot image code. |
| 4579 | kBootImageLinkTimePcRelative, |
| 4580 | |
| 4581 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| 4582 | // Used for app->boot calls with relocatable image. |
| 4583 | kBootImageRelRo, |
| 4584 | |
| 4585 | // Load from an entry in the .bss section using a PC-relative load. |
| 4586 | // Used for methods outside boot image referenced by AOT-compiled app and boot image code. |
| 4587 | kBssEntry, |
| 4588 | |
| 4589 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4590 | // Used for for JIT-compiled calls. |
| 4591 | kJitDirectAddress, |
| 4592 | |
| 4593 | // Make a runtime call to resolve and call the method. This is the last-resort-kind |
| 4594 | // used when other kinds are unimplemented on a particular architecture. |
| 4595 | kRuntimeCall, |
| 4596 | }; |
| 4597 | |
| 4598 | // Determines the location of the code pointer of an invoke. |
| 4599 | enum class CodePtrLocation { |
| 4600 | // Recursive call, use local PC-relative call instruction. |
| 4601 | kCallSelf, |
| 4602 | |
| 4603 | // Use native pointer from the Artmethod*. |
| 4604 | // Used for @CriticalNative to avoid going through the compiled stub. This call goes through |
| 4605 | // a special resolution stub if the class is not initialized or no native code is registered. |
| 4606 | kCallCriticalNative, |
| 4607 | |
| 4608 | // Use code pointer from the ArtMethod*. |
| 4609 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4610 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4611 | kCallArtMethod, |
| 4612 | }; |
| 4613 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4614 | static inline bool IsPcRelativeMethodLoadKind(MethodLoadKind load_kind) { |
| 4615 | return load_kind == MethodLoadKind::kBootImageLinkTimePcRelative || |
| 4616 | load_kind == MethodLoadKind::kBootImageRelRo || |
| 4617 | load_kind == MethodLoadKind::kBssEntry; |
| 4618 | } |
| 4619 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4620 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4621 | public: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4622 | bool NeedsEnvironment() const override; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4623 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 4624 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4625 | SetRawInputAt(index, argument); |
| 4626 | } |
| 4627 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4628 | // Return the number of arguments. This number can be lower than |
| 4629 | // the number of inputs returned by InputCount(), as some invoke |
| 4630 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 4631 | // inputs at the end of their list of inputs. |
| 4632 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 4633 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4634 | InvokeType GetInvokeType() const { |
| 4635 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4636 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4637 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 4638 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4639 | return intrinsic_; |
| 4640 | } |
| 4641 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4642 | void SetIntrinsic(Intrinsics intrinsic, |
Nicolas Geoffray | 8f2eb25 | 2020-11-06 13:39:54 +0000 | [diff] [blame] | 4643 | IntrinsicNeedsEnvironment needs_env, |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4644 | IntrinsicSideEffects side_effects, |
| 4645 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4646 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4647 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4648 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4649 | } |
| 4650 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4651 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4652 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4653 | bool CanThrow() const override { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4654 | |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4655 | void SetAlwaysThrows(bool always_throws) { SetPackedFlag<kFlagAlwaysThrows>(always_throws); } |
| 4656 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4657 | bool AlwaysThrows() const override { return GetPackedFlag<kFlagAlwaysThrows>(); } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4658 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4659 | bool CanBeMoved() const override { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4660 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4661 | bool InstructionDataEquals(const HInstruction* other) const override { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4662 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 4663 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4664 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4665 | uint32_t* GetIntrinsicOptimizations() { |
| 4666 | return &intrinsic_optimizations_; |
| 4667 | } |
| 4668 | |
| 4669 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4670 | return &intrinsic_optimizations_; |
| 4671 | } |
| 4672 | |
| 4673 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4674 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4675 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4676 | void SetResolvedMethod(ArtMethod* method); |
| 4677 | |
| 4678 | MethodReference GetMethodReference() const { return method_reference_; } |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4679 | |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4680 | const MethodReference GetResolvedMethodReference() const { |
| 4681 | return resolved_method_reference_; |
| 4682 | } |
| 4683 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4684 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4685 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4686 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4687 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4688 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4689 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4690 | static constexpr size_t kFlagCanThrow = kFieldInvokeType + kFieldInvokeTypeSize; |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4691 | static constexpr size_t kFlagAlwaysThrows = kFlagCanThrow + 1; |
| 4692 | static constexpr size_t kNumberOfInvokePackedBits = kFlagAlwaysThrows + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4693 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4694 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4695 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4696 | HInvoke(InstructionKind kind, |
| 4697 | ArenaAllocator* allocator, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4698 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4699 | uint32_t number_of_other_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4700 | DataType::Type return_type, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4701 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4702 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4703 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4704 | MethodReference resolved_method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4705 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4706 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4707 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4708 | return_type, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4709 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4710 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4711 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4712 | number_of_arguments + number_of_other_inputs, |
| 4713 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4714 | number_of_arguments_(number_of_arguments), |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4715 | method_reference_(method_reference), |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4716 | resolved_method_reference_(resolved_method_reference), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4717 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4718 | intrinsic_optimizations_(0) { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4719 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4720 | SetPackedFlag<kFlagCanThrow>(true); |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 4721 | SetResolvedMethod(resolved_method); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4722 | } |
| 4723 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4724 | DEFAULT_COPY_CONSTRUCTOR(Invoke); |
| 4725 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4726 | uint32_t number_of_arguments_; |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4727 | ArtMethod* resolved_method_; |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4728 | const MethodReference method_reference_; |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4729 | // Cached values of the resolved method, to avoid needing the mutator lock. |
| 4730 | const MethodReference resolved_method_reference_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4731 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4732 | |
| 4733 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4734 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4735 | }; |
| 4736 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4737 | class HInvokeUnresolved final : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4738 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4739 | HInvokeUnresolved(ArenaAllocator* allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4740 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4741 | DataType::Type return_type, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4742 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4743 | MethodReference method_reference, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4744 | InvokeType invoke_type) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4745 | : HInvoke(kInvokeUnresolved, |
| 4746 | allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4747 | number_of_arguments, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4748 | /* number_of_other_inputs= */ 0u, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4749 | return_type, |
| 4750 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4751 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4752 | nullptr, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4753 | MethodReference(nullptr, 0u), |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4754 | invoke_type) { |
| 4755 | } |
| 4756 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4757 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4758 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4759 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4760 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4761 | protected: |
| 4762 | DEFAULT_COPY_CONSTRUCTOR(InvokeUnresolved); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4763 | }; |
| 4764 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4765 | class HInvokePolymorphic final : public HInvoke { |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4766 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4767 | HInvokePolymorphic(ArenaAllocator* allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4768 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4769 | DataType::Type return_type, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4770 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4771 | MethodReference method_reference, |
Andra Danciu | b931b8c | 2020-07-27 13:16:37 +0000 | [diff] [blame] | 4772 | // resolved_method is the ArtMethod object corresponding to the polymorphic |
| 4773 | // method (e.g. VarHandle.get), resolved using the class linker. It is needed |
| 4774 | // to pass intrinsic information to the HInvokePolymorphic node. |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4775 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4776 | MethodReference resolved_method_reference, |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4777 | dex::ProtoIndex proto_idx) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4778 | : HInvoke(kInvokePolymorphic, |
| 4779 | allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4780 | number_of_arguments, |
Andra Danciu | 49a19f3 | 2020-08-27 12:44:25 +0000 | [diff] [blame] | 4781 | /* number_of_other_inputs= */ 0u, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4782 | return_type, |
| 4783 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4784 | method_reference, |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4785 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4786 | resolved_method_reference, |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4787 | kPolymorphic), |
| 4788 | proto_idx_(proto_idx) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4789 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4790 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4791 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4792 | |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4793 | dex::ProtoIndex GetProtoIndex() { return proto_idx_; } |
| 4794 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4795 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4796 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4797 | protected: |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 4798 | dex::ProtoIndex proto_idx_; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4799 | DEFAULT_COPY_CONSTRUCTOR(InvokePolymorphic); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4800 | }; |
| 4801 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4802 | class HInvokeCustom final : public HInvoke { |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4803 | public: |
| 4804 | HInvokeCustom(ArenaAllocator* allocator, |
| 4805 | uint32_t number_of_arguments, |
| 4806 | uint32_t call_site_index, |
| 4807 | DataType::Type return_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4808 | uint32_t dex_pc, |
| 4809 | MethodReference method_reference) |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4810 | : HInvoke(kInvokeCustom, |
| 4811 | allocator, |
| 4812 | number_of_arguments, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4813 | /* number_of_other_inputs= */ 0u, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4814 | return_type, |
| 4815 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4816 | method_reference, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4817 | /* resolved_method= */ nullptr, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4818 | MethodReference(nullptr, 0u), |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4819 | kStatic), |
| 4820 | call_site_index_(call_site_index) { |
| 4821 | } |
| 4822 | |
| 4823 | uint32_t GetCallSiteIndex() const { return call_site_index_; } |
| 4824 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4825 | bool IsClonable() const override { return true; } |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4826 | |
| 4827 | DECLARE_INSTRUCTION(InvokeCustom); |
| 4828 | |
| 4829 | protected: |
| 4830 | DEFAULT_COPY_CONSTRUCTOR(InvokeCustom); |
| 4831 | |
| 4832 | private: |
| 4833 | uint32_t call_site_index_; |
| 4834 | }; |
| 4835 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4836 | class HInvokeStaticOrDirect final : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4837 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4838 | // Requirements of this method call regarding the class |
| 4839 | // initialization (clinit) check of its declaring class. |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 4840 | 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] | 4841 | kNone, // Class already initialized. |
| 4842 | kExplicit, // Static call having explicit clinit check as last input. |
| 4843 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4844 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4845 | }; |
| 4846 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4847 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4848 | MethodLoadKind method_load_kind; |
| 4849 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4850 | // The method load data holds |
| 4851 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4852 | // Note that there are multiple string init methods, each having its own offset. |
| 4853 | // - the method address for kDirectAddress |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4854 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4855 | }; |
| 4856 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4857 | HInvokeStaticOrDirect(ArenaAllocator* allocator, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4858 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4859 | DataType::Type return_type, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4860 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4861 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4862 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4863 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4864 | InvokeType invoke_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4865 | MethodReference resolved_method_reference, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4866 | ClinitCheckRequirement clinit_check_requirement) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4867 | : HInvoke(kInvokeStaticOrDirect, |
| 4868 | allocator, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4869 | number_of_arguments, |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4870 | // There is potentially one extra argument for the HCurrentMethod input, |
| 4871 | // and one other if the clinit check is explicit. These can be removed later. |
| 4872 | (NeedsCurrentMethodInput(dispatch_info) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4873 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4874 | return_type, |
| 4875 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4876 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4877 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 4878 | resolved_method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4879 | invoke_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4880 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4881 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4882 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4883 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4884 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4885 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4886 | void SetDispatchInfo(DispatchInfo dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4887 | bool had_current_method_input = HasCurrentMethodInput(); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4888 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4889 | |
| 4890 | // Using the current method is the default and once we find a better |
| 4891 | // method load kind, we should not go back to using the current method. |
| 4892 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4893 | |
| 4894 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4895 | DCHECK_EQ(InputAt(GetCurrentMethodIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4896 | RemoveInputAt(GetCurrentMethodIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4897 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4898 | dispatch_info_ = dispatch_info; |
| 4899 | } |
| 4900 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 4901 | DispatchInfo GetDispatchInfo() const { |
| 4902 | return dispatch_info_; |
| 4903 | } |
| 4904 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4905 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4906 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4907 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4908 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4909 | DCHECK(!input_records.empty()); |
| 4910 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4911 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4912 | // Note: `last_input` may be null during arguments setup. |
| 4913 | if (last_input != nullptr) { |
| 4914 | // `last_input` is the last input of a static invoke marked as having |
| 4915 | // an explicit clinit check. It must either be: |
| 4916 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4917 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4918 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4919 | } |
| 4920 | } |
| 4921 | return input_records; |
| 4922 | } |
| 4923 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4924 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4925 | // 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] | 4926 | // TODO: for intrinsics we can generate implicit null checks. |
| 4927 | return false; |
| 4928 | } |
| 4929 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4930 | bool CanBeNull() const override { |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4931 | return GetType() == DataType::Type::kReference && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4932 | } |
| 4933 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4934 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
Nicolas Geoffray | 282795c | 2021-09-24 18:16:41 +0100 | [diff] [blame] | 4935 | CodePtrLocation GetCodePtrLocation() const { |
| 4936 | // We do CHA analysis after sharpening. When a method has CHA inlining, it |
| 4937 | // cannot call itself, as if the CHA optmization is invalid we want to make |
| 4938 | // sure the method is never executed again. So, while sharpening can return |
| 4939 | // kCallSelf, we bypass it here if there is a CHA optimization. |
| 4940 | if (dispatch_info_.code_ptr_location == CodePtrLocation::kCallSelf && |
| 4941 | GetBlock()->GetGraph()->HasShouldDeoptimizeFlag()) { |
| 4942 | return CodePtrLocation::kCallArtMethod; |
| 4943 | } else { |
| 4944 | return dispatch_info_.code_ptr_location; |
| 4945 | } |
| 4946 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4947 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4948 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4949 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kJitDirectAddress; } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4950 | bool HasPcRelativeMethodLoadKind() const { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4951 | return IsPcRelativeMethodLoadKind(GetMethodLoadKind()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4952 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4953 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4954 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4955 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4956 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4957 | } |
| 4958 | |
| 4959 | uint64_t GetMethodAddress() const { |
| 4960 | DCHECK(HasMethodAddress()); |
| 4961 | return dispatch_info_.method_load_data; |
| 4962 | } |
| 4963 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4964 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4965 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4966 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4967 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4968 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4969 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4970 | // Is this instruction a call to a static method? |
| 4971 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4972 | return GetInvokeType() == kStatic; |
| 4973 | } |
| 4974 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4975 | // Does this method load kind need the current method as an input? |
| 4976 | static bool NeedsCurrentMethodInput(DispatchInfo dispatch_info) { |
| 4977 | return dispatch_info.method_load_kind == MethodLoadKind::kRecursive || |
| 4978 | dispatch_info.method_load_kind == MethodLoadKind::kRuntimeCall || |
| 4979 | dispatch_info.code_ptr_location == CodePtrLocation::kCallCriticalNative; |
| 4980 | } |
| 4981 | |
| 4982 | // Get the index of the current method input. |
| 4983 | size_t GetCurrentMethodIndex() const { |
| 4984 | DCHECK(HasCurrentMethodInput()); |
| 4985 | return GetCurrentMethodIndexUnchecked(); |
| 4986 | } |
| 4987 | size_t GetCurrentMethodIndexUnchecked() const { |
| 4988 | return GetNumberOfArguments(); |
| 4989 | } |
| 4990 | |
| 4991 | // Check if the method has a current method input. |
| 4992 | bool HasCurrentMethodInput() const { |
| 4993 | if (NeedsCurrentMethodInput(GetDispatchInfo())) { |
| 4994 | DCHECK(InputAt(GetCurrentMethodIndexUnchecked()) == nullptr || // During argument setup. |
| 4995 | InputAt(GetCurrentMethodIndexUnchecked())->IsCurrentMethod()); |
| 4996 | return true; |
| 4997 | } else { |
| 4998 | DCHECK(InputCount() == GetCurrentMethodIndexUnchecked() || |
| 4999 | InputAt(GetCurrentMethodIndexUnchecked()) == nullptr || // During argument setup. |
| 5000 | !InputAt(GetCurrentMethodIndexUnchecked())->IsCurrentMethod()); |
| 5001 | return false; |
| 5002 | } |
| 5003 | } |
| 5004 | |
| 5005 | // Get the index of the special input. |
| 5006 | size_t GetSpecialInputIndex() const { |
| 5007 | DCHECK(HasSpecialInput()); |
| 5008 | return GetSpecialInputIndexUnchecked(); |
| 5009 | } |
| 5010 | size_t GetSpecialInputIndexUnchecked() const { |
| 5011 | return GetNumberOfArguments() + (HasCurrentMethodInput() ? 1u : 0u); |
| 5012 | } |
| 5013 | |
| 5014 | // Check if the method has a special input. |
| 5015 | bool HasSpecialInput() const { |
| 5016 | size_t other_inputs = |
| 5017 | GetSpecialInputIndexUnchecked() + (IsStaticWithExplicitClinitCheck() ? 1u : 0u); |
| 5018 | size_t input_count = InputCount(); |
| 5019 | DCHECK_LE(input_count - other_inputs, 1u) << other_inputs << " " << input_count; |
| 5020 | return other_inputs != input_count; |
| 5021 | } |
| 5022 | |
| 5023 | void AddSpecialInput(HInstruction* input) { |
| 5024 | // We allow only one special input. |
| 5025 | DCHECK(!HasSpecialInput()); |
| 5026 | InsertInputAt(GetSpecialInputIndexUnchecked(), input); |
| 5027 | } |
| 5028 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 5029 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 5030 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 5031 | // instruction; only relevant for static calls with explicit clinit check. |
| 5032 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5033 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5034 | size_t last_input_index = inputs_.size() - 1u; |
| 5035 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5036 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 5037 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5038 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5039 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5040 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 5041 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | // 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] | 5045 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5046 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5047 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | // Is this a call to a static method whose declaring class has an |
| 5051 | // implicit intialization check requirement? |
| 5052 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5053 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5054 | } |
| 5055 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 5056 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 5057 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5058 | protected: |
| 5059 | DEFAULT_COPY_CONSTRUCTOR(InvokeStaticOrDirect); |
| 5060 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 5061 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5062 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5063 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 5064 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 5065 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 5066 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 5067 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 5068 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5069 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 5070 | kFieldClinitCheckRequirement, |
| 5071 | kFieldClinitCheckRequirementSize>; |
| 5072 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5073 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 5074 | }; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5075 | std::ostream& operator<<(std::ostream& os, MethodLoadKind rhs); |
| 5076 | std::ostream& operator<<(std::ostream& os, CodePtrLocation rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 5077 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 5078 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5079 | class HInvokeVirtual final : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5080 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 5081 | HInvokeVirtual(ArenaAllocator* allocator, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5082 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5083 | DataType::Type return_type, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5084 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5085 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5086 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 5087 | MethodReference resolved_method_reference, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5088 | uint32_t vtable_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5089 | : HInvoke(kInvokeVirtual, |
| 5090 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5091 | number_of_arguments, |
| 5092 | 0u, |
| 5093 | return_type, |
| 5094 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5095 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5096 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 5097 | resolved_method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5098 | kVirtual), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5099 | vtable_index_(vtable_index) { |
| 5100 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5101 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5102 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5103 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5104 | bool CanBeNull() const override { |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 5105 | switch (GetIntrinsic()) { |
| 5106 | case Intrinsics::kThreadCurrentThread: |
| 5107 | case Intrinsics::kStringBufferAppend: |
| 5108 | case Intrinsics::kStringBufferToString: |
Vladimir Marko | d456117 | 2017-10-30 17:48:25 +0000 | [diff] [blame] | 5109 | case Intrinsics::kStringBuilderAppendObject: |
| 5110 | case Intrinsics::kStringBuilderAppendString: |
| 5111 | case Intrinsics::kStringBuilderAppendCharSequence: |
| 5112 | case Intrinsics::kStringBuilderAppendCharArray: |
| 5113 | case Intrinsics::kStringBuilderAppendBoolean: |
| 5114 | case Intrinsics::kStringBuilderAppendChar: |
| 5115 | case Intrinsics::kStringBuilderAppendInt: |
| 5116 | case Intrinsics::kStringBuilderAppendLong: |
| 5117 | case Intrinsics::kStringBuilderAppendFloat: |
| 5118 | case Intrinsics::kStringBuilderAppendDouble: |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 5119 | case Intrinsics::kStringBuilderToString: |
| 5120 | return false; |
| 5121 | default: |
| 5122 | return HInvoke::CanBeNull(); |
| 5123 | } |
| 5124 | } |
| 5125 | |
Vladimir Marko | ac27ac0 | 2021-02-01 09:31:02 +0000 | [diff] [blame] | 5126 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5127 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5128 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 5129 | |
| 5130 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 5131 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5132 | protected: |
| 5133 | DEFAULT_COPY_CONSTRUCTOR(InvokeVirtual); |
| 5134 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5135 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5136 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5137 | const uint32_t vtable_index_; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 5138 | }; |
| 5139 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5140 | class HInvokeInterface final : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5141 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 5142 | HInvokeInterface(ArenaAllocator* allocator, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5143 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5144 | DataType::Type return_type, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5145 | uint32_t dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5146 | MethodReference method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5147 | ArtMethod* resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 5148 | MethodReference resolved_method_reference, |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5149 | uint32_t imt_index, |
| 5150 | MethodLoadKind load_kind) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5151 | : HInvoke(kInvokeInterface, |
| 5152 | allocator, |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5153 | number_of_arguments + (NeedsCurrentMethod(load_kind) ? 1 : 0), |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5154 | 0u, |
| 5155 | return_type, |
| 5156 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5157 | method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5158 | resolved_method, |
Nicolas Geoffray | b0f405e | 2020-09-24 15:10:35 +0100 | [diff] [blame] | 5159 | resolved_method_reference, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5160 | kInterface), |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5161 | imt_index_(imt_index), |
| 5162 | hidden_argument_load_kind_(load_kind) { |
| 5163 | } |
| 5164 | |
| 5165 | static bool NeedsCurrentMethod(MethodLoadKind load_kind) { |
| 5166 | return load_kind == MethodLoadKind::kRecursive; |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5167 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5168 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5169 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5170 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5171 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5172 | // TODO: Add implicit null checks in intrinsics. |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 5173 | return (obj == InputAt(0)) && !IsIntrinsic(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5174 | } |
| 5175 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5176 | size_t GetSpecialInputIndex() const { |
| 5177 | return GetNumberOfArguments(); |
| 5178 | } |
| 5179 | |
| 5180 | void AddSpecialInput(HInstruction* input) { |
| 5181 | InsertInputAt(GetSpecialInputIndex(), input); |
| 5182 | } |
| 5183 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5184 | uint32_t GetImtIndex() const { return imt_index_; } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5185 | MethodLoadKind GetHiddenArgumentLoadKind() const { return hidden_argument_load_kind_; } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5186 | |
| 5187 | DECLARE_INSTRUCTION(InvokeInterface); |
| 5188 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5189 | protected: |
| 5190 | DEFAULT_COPY_CONSTRUCTOR(InvokeInterface); |
| 5191 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5192 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 5193 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5194 | const uint32_t imt_index_; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5195 | |
| 5196 | // How the hidden argument (the interface method) is being loaded. |
| 5197 | const MethodLoadKind hidden_argument_load_kind_; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 5198 | }; |
| 5199 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5200 | class HNeg final : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5201 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5202 | 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] | 5203 | : HUnaryOperation(kNeg, result_type, input, dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5204 | DCHECK_EQ(result_type, DataType::Kind(input->GetType())); |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 5205 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5206 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5207 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5208 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5209 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5210 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5211 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5212 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5213 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5214 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5215 | HConstant* Evaluate(HFloatConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5216 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 5217 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5218 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5219 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 5220 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 5221 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5222 | DECLARE_INSTRUCTION(Neg); |
| 5223 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5224 | protected: |
| 5225 | DEFAULT_COPY_CONSTRUCTOR(Neg); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 5226 | }; |
| 5227 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5228 | class HNewArray final : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5229 | public: |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5230 | 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] | 5231 | : HExpression(kNewArray, DataType::Type::kReference, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5232 | SetRawInputAt(0, cls); |
| 5233 | SetRawInputAt(1, length); |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5234 | SetPackedField<ComponentSizeShiftField>(component_size_shift); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5235 | } |
| 5236 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5237 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5238 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5239 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5240 | bool NeedsEnvironment() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5241 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 5242 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5243 | bool CanThrow() const override { return true; } |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 5244 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5245 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5246 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5247 | HLoadClass* GetLoadClass() const { |
| 5248 | DCHECK(InputAt(0)->IsLoadClass()); |
| 5249 | return InputAt(0)->AsLoadClass(); |
| 5250 | } |
| 5251 | |
| 5252 | HInstruction* GetLength() const { |
| 5253 | return InputAt(1); |
| 5254 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 5255 | |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5256 | size_t GetComponentSizeShift() { |
| 5257 | return GetPackedField<ComponentSizeShiftField>(); |
| 5258 | } |
| 5259 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5260 | DECLARE_INSTRUCTION(NewArray); |
| 5261 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5262 | protected: |
| 5263 | DEFAULT_COPY_CONSTRUCTOR(NewArray); |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5264 | |
| 5265 | private: |
| 5266 | static constexpr size_t kFieldComponentSizeShift = kNumberOfGenericPackedBits; |
| 5267 | static constexpr size_t kFieldComponentSizeShiftSize = MinimumBitsToStore(3u); |
| 5268 | static constexpr size_t kNumberOfNewArrayPackedBits = |
| 5269 | kFieldComponentSizeShift + kFieldComponentSizeShiftSize; |
| 5270 | static_assert(kNumberOfNewArrayPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5271 | using ComponentSizeShiftField = |
| 5272 | BitField<size_t, kFieldComponentSizeShift, kFieldComponentSizeShift>; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5273 | }; |
| 5274 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5275 | class HAdd final : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5276 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5277 | HAdd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5278 | HInstruction* left, |
| 5279 | HInstruction* right, |
| 5280 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5281 | : HBinaryOperation(kAdd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5282 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5283 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5284 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5285 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5286 | 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] | 5287 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5288 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5289 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5290 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5291 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5292 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5293 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5294 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5295 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5296 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5297 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5298 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5299 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5300 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5301 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5302 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5303 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 5304 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5305 | DECLARE_INSTRUCTION(Add); |
| 5306 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5307 | protected: |
| 5308 | DEFAULT_COPY_CONSTRUCTOR(Add); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 5309 | }; |
| 5310 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5311 | class HSub final : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5312 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5313 | HSub(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5314 | HInstruction* left, |
| 5315 | HInstruction* right, |
| 5316 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5317 | : HBinaryOperation(kSub, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5318 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +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, T y) { return x - y; } |
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, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5323 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5324 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5325 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5326 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5327 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5328 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 5329 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5330 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5331 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5332 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5333 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5334 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5335 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5336 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5337 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 5338 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5339 | DECLARE_INSTRUCTION(Sub); |
| 5340 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5341 | protected: |
| 5342 | DEFAULT_COPY_CONSTRUCTOR(Sub); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5343 | }; |
| 5344 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5345 | class HMul final : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5346 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5347 | HMul(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5348 | HInstruction* left, |
| 5349 | HInstruction* right, |
| 5350 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5351 | : HBinaryOperation(kMul, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5352 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5353 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5354 | bool IsCommutative() const override { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5355 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5356 | 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] | 5357 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5358 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5359 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5360 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5361 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5362 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5363 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5364 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5365 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5366 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5367 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5368 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5369 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5370 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5371 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5372 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5373 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5374 | |
| 5375 | DECLARE_INSTRUCTION(Mul); |
| 5376 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5377 | protected: |
| 5378 | DEFAULT_COPY_CONSTRUCTOR(Mul); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 5379 | }; |
| 5380 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5381 | class HDiv final : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5382 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5383 | HDiv(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5384 | HInstruction* left, |
| 5385 | HInstruction* right, |
| 5386 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5387 | : HBinaryOperation(kDiv, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5388 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5389 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5390 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5391 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5392 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5393 | // Our graph structure ensures we never have 0 for `y` during |
| 5394 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5395 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5396 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5397 | return (y == -1) ? -x : x / y; |
| 5398 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5399 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5400 | template <typename T> |
| 5401 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5402 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5403 | return x / y; |
| 5404 | } |
| 5405 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5406 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5407 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5408 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5409 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5410 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5411 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5412 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5413 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5414 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5415 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5416 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5417 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5418 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5419 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5420 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5421 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5422 | |
| 5423 | DECLARE_INSTRUCTION(Div); |
| 5424 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5425 | protected: |
| 5426 | DEFAULT_COPY_CONSTRUCTOR(Div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5427 | }; |
| 5428 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5429 | class HRem final : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5430 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5431 | HRem(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5432 | HInstruction* left, |
| 5433 | HInstruction* right, |
| 5434 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5435 | : HBinaryOperation(kRem, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5436 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5437 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5438 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5439 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5440 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5441 | // Our graph structure ensures we never have 0 for `y` during |
| 5442 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5443 | DCHECK_NE(y, 0); |
| 5444 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 5445 | return (y == -1) ? 0 : x % y; |
| 5446 | } |
| 5447 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5448 | template <typename T> |
| 5449 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5450 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5451 | return std::fmod(x, y); |
| 5452 | } |
| 5453 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5454 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5455 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5456 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5457 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5458 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5459 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5460 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5461 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5462 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5463 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5464 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5465 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5466 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5467 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5468 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5469 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5470 | |
| 5471 | DECLARE_INSTRUCTION(Rem); |
| 5472 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5473 | protected: |
| 5474 | DEFAULT_COPY_CONSTRUCTOR(Rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5475 | }; |
| 5476 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5477 | class HMin final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5478 | public: |
| 5479 | HMin(DataType::Type result_type, |
| 5480 | HInstruction* left, |
| 5481 | HInstruction* right, |
| 5482 | uint32_t dex_pc) |
| 5483 | : HBinaryOperation(kMin, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5484 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5485 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5486 | |
| 5487 | // Evaluation for integral values. |
| 5488 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5489 | return (x <= y) ? x : y; |
| 5490 | } |
| 5491 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5492 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5493 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5494 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5495 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5496 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5497 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5498 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5499 | } |
| 5500 | // TODO: Evaluation for floating-point values. |
| 5501 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5502 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5503 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5504 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5505 | |
| 5506 | DECLARE_INSTRUCTION(Min); |
| 5507 | |
| 5508 | protected: |
| 5509 | DEFAULT_COPY_CONSTRUCTOR(Min); |
| 5510 | }; |
| 5511 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5512 | class HMax final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5513 | public: |
| 5514 | HMax(DataType::Type result_type, |
| 5515 | HInstruction* left, |
| 5516 | HInstruction* right, |
| 5517 | uint32_t dex_pc) |
| 5518 | : HBinaryOperation(kMax, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5519 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5520 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5521 | |
| 5522 | // Evaluation for integral values. |
| 5523 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5524 | return (x >= y) ? x : y; |
| 5525 | } |
| 5526 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5527 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5528 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5529 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5530 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5531 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5532 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5533 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5534 | } |
| 5535 | // TODO: Evaluation for floating-point values. |
| 5536 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5537 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5538 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5539 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5540 | |
| 5541 | DECLARE_INSTRUCTION(Max); |
| 5542 | |
| 5543 | protected: |
| 5544 | DEFAULT_COPY_CONSTRUCTOR(Max); |
| 5545 | }; |
| 5546 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5547 | class HAbs final : public HUnaryOperation { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5548 | public: |
| 5549 | HAbs(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5550 | : HUnaryOperation(kAbs, result_type, input, dex_pc) {} |
| 5551 | |
| 5552 | // Evaluation for integral values. |
| 5553 | template <typename T> static T ComputeIntegral(T x) { |
| 5554 | return x < 0 ? -x : x; |
| 5555 | } |
| 5556 | |
| 5557 | // Evaluation for floating-point values. |
| 5558 | // Note, as a "quality of implementation", rather than pure "spec compliance", |
| 5559 | // we require that Math.abs() clears the sign bit (but changes nothing else) |
| 5560 | // for all floating-point numbers, including NaN (signaling NaN may become quiet though). |
| 5561 | // http://b/30758343 |
| 5562 | template <typename T, typename S> static T ComputeFP(T x) { |
| 5563 | S bits = bit_cast<S, T>(x); |
| 5564 | return bit_cast<T, S>(bits & std::numeric_limits<S>::max()); |
| 5565 | } |
| 5566 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5567 | HConstant* Evaluate(HIntConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5568 | return GetBlock()->GetGraph()->GetIntConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5569 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5570 | HConstant* Evaluate(HLongConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5571 | return GetBlock()->GetGraph()->GetLongConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5572 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5573 | HConstant* Evaluate(HFloatConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5574 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5575 | ComputeFP<float, int32_t>(x->GetValue()), GetDexPc()); |
| 5576 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5577 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5578 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5579 | ComputeFP<double, int64_t>(x->GetValue()), GetDexPc()); |
| 5580 | } |
| 5581 | |
| 5582 | DECLARE_INSTRUCTION(Abs); |
| 5583 | |
| 5584 | protected: |
| 5585 | DEFAULT_COPY_CONSTRUCTOR(Abs); |
| 5586 | }; |
| 5587 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5588 | class HDivZeroCheck final : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5589 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 5590 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5591 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5592 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5593 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5594 | : HExpression(kDivZeroCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5595 | SetRawInputAt(0, value); |
| 5596 | } |
| 5597 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5598 | bool IsClonable() const override { return true; } |
| 5599 | bool CanBeMoved() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5600 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5601 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5602 | return true; |
| 5603 | } |
| 5604 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5605 | bool NeedsEnvironment() const override { return true; } |
| 5606 | bool CanThrow() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5607 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5608 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 5609 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5610 | protected: |
| 5611 | DEFAULT_COPY_CONSTRUCTOR(DivZeroCheck); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5612 | }; |
| 5613 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5614 | class HShl final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5615 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5616 | HShl(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5617 | HInstruction* value, |
| 5618 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5619 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5620 | : HBinaryOperation(kShl, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5621 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5622 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5623 | } |
| 5624 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5625 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5626 | 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] | 5627 | return value << (distance & max_shift_distance); |
| 5628 | } |
| 5629 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5630 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5631 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5632 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5633 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5634 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5635 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5636 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5637 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5638 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5639 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5640 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5641 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5642 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5643 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5644 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5645 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5646 | UNREACHABLE(); |
| 5647 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5648 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5649 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5650 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5651 | UNREACHABLE(); |
| 5652 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5653 | |
| 5654 | DECLARE_INSTRUCTION(Shl); |
| 5655 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5656 | protected: |
| 5657 | DEFAULT_COPY_CONSTRUCTOR(Shl); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5658 | }; |
| 5659 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5660 | class HShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5661 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5662 | HShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5663 | HInstruction* value, |
| 5664 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5665 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5666 | : HBinaryOperation(kShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5667 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5668 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5669 | } |
| 5670 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5671 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5672 | 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] | 5673 | return value >> (distance & max_shift_distance); |
| 5674 | } |
| 5675 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5676 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5677 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5678 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5679 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5680 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5681 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5682 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5683 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5684 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5685 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5686 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5687 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5688 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5689 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5690 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5691 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5692 | UNREACHABLE(); |
| 5693 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5694 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5695 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5696 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5697 | UNREACHABLE(); |
| 5698 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5699 | |
| 5700 | DECLARE_INSTRUCTION(Shr); |
| 5701 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5702 | protected: |
| 5703 | DEFAULT_COPY_CONSTRUCTOR(Shr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5704 | }; |
| 5705 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5706 | class HUShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5707 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5708 | HUShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5709 | HInstruction* value, |
| 5710 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5711 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5712 | : HBinaryOperation(kUShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5713 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5714 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5715 | } |
| 5716 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5717 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5718 | 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] | 5719 | using V = std::make_unsigned_t<T>; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5720 | V ux = static_cast<V>(value); |
| 5721 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 5722 | } |
| 5723 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5724 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5725 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5726 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5727 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5728 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5729 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5730 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5731 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5732 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5733 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5734 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5735 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5736 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5737 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5738 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5739 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5740 | UNREACHABLE(); |
| 5741 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5742 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5743 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5744 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5745 | UNREACHABLE(); |
| 5746 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5747 | |
| 5748 | DECLARE_INSTRUCTION(UShr); |
| 5749 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5750 | protected: |
| 5751 | DEFAULT_COPY_CONSTRUCTOR(UShr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5752 | }; |
| 5753 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5754 | class HAnd final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5755 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5756 | HAnd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5757 | HInstruction* left, |
| 5758 | HInstruction* right, |
| 5759 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5760 | : HBinaryOperation(kAnd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5761 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5762 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5763 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5764 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5765 | 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] | 5766 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5767 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5768 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5769 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5770 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5771 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5772 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5773 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5774 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5775 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5776 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5777 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5778 | UNREACHABLE(); |
| 5779 | } |
| 5780 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5781 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5782 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5783 | UNREACHABLE(); |
| 5784 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5785 | |
| 5786 | DECLARE_INSTRUCTION(And); |
| 5787 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5788 | protected: |
| 5789 | DEFAULT_COPY_CONSTRUCTOR(And); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5790 | }; |
| 5791 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5792 | class HOr final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5793 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5794 | HOr(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5795 | HInstruction* left, |
| 5796 | HInstruction* right, |
| 5797 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5798 | : HBinaryOperation(kOr, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5799 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5800 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5801 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5802 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5803 | 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] | 5804 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5805 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5806 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5807 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5808 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5809 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5810 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5811 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5812 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5813 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5814 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5815 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5816 | UNREACHABLE(); |
| 5817 | } |
| 5818 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5819 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5820 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5821 | UNREACHABLE(); |
| 5822 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5823 | |
| 5824 | DECLARE_INSTRUCTION(Or); |
| 5825 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5826 | protected: |
| 5827 | DEFAULT_COPY_CONSTRUCTOR(Or); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5828 | }; |
| 5829 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5830 | class HXor final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5831 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5832 | HXor(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5833 | HInstruction* left, |
| 5834 | HInstruction* right, |
| 5835 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5836 | : HBinaryOperation(kXor, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5837 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5838 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5839 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5840 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5841 | 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] | 5842 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5843 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5844 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5845 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5846 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5847 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5848 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5849 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5850 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5851 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5852 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5853 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5854 | UNREACHABLE(); |
| 5855 | } |
| 5856 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5857 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5858 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5859 | UNREACHABLE(); |
| 5860 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5861 | |
| 5862 | DECLARE_INSTRUCTION(Xor); |
| 5863 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5864 | protected: |
| 5865 | DEFAULT_COPY_CONSTRUCTOR(Xor); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5866 | }; |
| 5867 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5868 | class HRor final : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5869 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5870 | HRor(DataType::Type result_type, HInstruction* value, HInstruction* distance) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5871 | : HBinaryOperation(kRor, result_type, value, distance) { |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5872 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5873 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5874 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5875 | 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] | 5876 | using V = std::make_unsigned_t<T>; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5877 | V ux = static_cast<V>(value); |
| 5878 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5879 | return static_cast<T>(ux); |
| 5880 | } else { |
| 5881 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5882 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 5883 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5884 | } |
| 5885 | } |
| 5886 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5887 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5888 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5889 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5890 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5891 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5892 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5893 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5894 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5895 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5896 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5897 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5898 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5899 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5900 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5901 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5902 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5903 | UNREACHABLE(); |
| 5904 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5905 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5906 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5907 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5908 | UNREACHABLE(); |
| 5909 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5910 | |
| 5911 | DECLARE_INSTRUCTION(Ror); |
| 5912 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5913 | protected: |
| 5914 | DEFAULT_COPY_CONSTRUCTOR(Ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5915 | }; |
| 5916 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5917 | // The value of a parameter in this method. Its location depends on |
| 5918 | // the calling convention. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5919 | class HParameterValue final : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5920 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5921 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5922 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5923 | uint8_t index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5924 | DataType::Type parameter_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5925 | bool is_this = false) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5926 | : HExpression(kParameterValue, parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5927 | dex_file_(dex_file), |
| 5928 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5929 | index_(index) { |
| 5930 | SetPackedFlag<kFlagIsThis>(is_this); |
| 5931 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 5932 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5933 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5934 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5935 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5936 | uint8_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5937 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5938 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5939 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5940 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5941 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5942 | DECLARE_INSTRUCTION(ParameterValue); |
| 5943 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5944 | protected: |
| 5945 | DEFAULT_COPY_CONSTRUCTOR(ParameterValue); |
| 5946 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5947 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5948 | // Whether or not the parameter value corresponds to 'this' argument. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5949 | static constexpr size_t kFlagIsThis = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5950 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 5951 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 5952 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 5953 | "Too many packed fields."); |
| 5954 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5955 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5956 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5957 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5958 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5959 | const uint8_t index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5960 | }; |
| 5961 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5962 | class HNot final : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5963 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5964 | 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] | 5965 | : HUnaryOperation(kNot, result_type, input, dex_pc) { |
| 5966 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5967 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5968 | bool CanBeMoved() const override { return true; } |
| 5969 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5970 | return true; |
| 5971 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5972 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5973 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5974 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5975 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5976 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5977 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5978 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5979 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5980 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5981 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5982 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5983 | UNREACHABLE(); |
| 5984 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5985 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5986 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5987 | UNREACHABLE(); |
| 5988 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5989 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5990 | DECLARE_INSTRUCTION(Not); |
| 5991 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5992 | protected: |
| 5993 | DEFAULT_COPY_CONSTRUCTOR(Not); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5994 | }; |
| 5995 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5996 | class HBooleanNot final : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5997 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5998 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5999 | : HUnaryOperation(kBooleanNot, DataType::Type::kBool, input, dex_pc) { |
| 6000 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6001 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6002 | bool CanBeMoved() const override { return true; } |
| 6003 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6004 | return true; |
| 6005 | } |
| 6006 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 6007 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6008 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6009 | return !x; |
| 6010 | } |
| 6011 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6012 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6013 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 6014 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6015 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 6016 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6017 | UNREACHABLE(); |
| 6018 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6019 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6020 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 6021 | UNREACHABLE(); |
| 6022 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6023 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6024 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 6025 | UNREACHABLE(); |
| 6026 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6027 | |
| 6028 | DECLARE_INSTRUCTION(BooleanNot); |
| 6029 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6030 | protected: |
| 6031 | DEFAULT_COPY_CONSTRUCTOR(BooleanNot); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 6032 | }; |
| 6033 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6034 | class HTypeConversion final : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6035 | public: |
| 6036 | // Instantiate a type conversion of `input` to `result_type`. |
Vladimir Marko | c8fb211 | 2017-10-03 11:37:52 +0100 | [diff] [blame] | 6037 | 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] | 6038 | : HExpression(kTypeConversion, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6039 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 6040 | // Invariant: We should never generate a conversion to a Boolean value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6041 | DCHECK_NE(DataType::Type::kBool, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6045 | DataType::Type GetInputType() const { return GetInput()->GetType(); } |
| 6046 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6047 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6048 | bool IsClonable() const override { return true; } |
| 6049 | bool CanBeMoved() const override { return true; } |
| 6050 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6051 | return true; |
| 6052 | } |
Nicolas Geoffray | acc56ac | 2018-10-09 08:45:24 +0100 | [diff] [blame] | 6053 | // Return whether the conversion is implicit. This includes conversion to the same type. |
| 6054 | bool IsImplicitConversion() const { |
| 6055 | return DataType::IsTypeConversionImplicit(GetInputType(), GetResultType()); |
| 6056 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6057 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 6058 | // Try to statically evaluate the conversion and return a HConstant |
| 6059 | // containing the result. If the input cannot be converted, return nullptr. |
| 6060 | HConstant* TryStaticEvaluation() const; |
| 6061 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6062 | DECLARE_INSTRUCTION(TypeConversion); |
| 6063 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6064 | protected: |
| 6065 | DEFAULT_COPY_CONSTRUCTOR(TypeConversion); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 6066 | }; |
| 6067 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 6068 | static constexpr uint32_t kNoRegNumber = -1; |
| 6069 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6070 | class HNullCheck final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6071 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 6072 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6073 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 6074 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6075 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6076 | : HExpression(kNullCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6077 | SetRawInputAt(0, value); |
| 6078 | } |
| 6079 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6080 | bool IsClonable() const override { return true; } |
| 6081 | bool CanBeMoved() const override { return true; } |
| 6082 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6083 | return true; |
| 6084 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6085 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6086 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6087 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6088 | bool CanThrow() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 6089 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6090 | bool CanBeNull() const override { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 6091 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6092 | DECLARE_INSTRUCTION(NullCheck); |
| 6093 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6094 | protected: |
| 6095 | DEFAULT_COPY_CONSTRUCTOR(NullCheck); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6096 | }; |
| 6097 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6098 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 6099 | // 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] | 6100 | class FieldInfo : public ValueObject { |
| 6101 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6102 | FieldInfo(ArtField* field, |
| 6103 | MemberOffset field_offset, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6104 | DataType::Type field_type, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6105 | bool is_volatile, |
| 6106 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6107 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6108 | const DexFile& dex_file) |
| 6109 | : field_(field), |
| 6110 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6111 | field_type_(field_type), |
| 6112 | is_volatile_(is_volatile), |
| 6113 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6114 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6115 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6116 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6117 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6118 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6119 | DataType::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6120 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6121 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6122 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6123 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6124 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6125 | bool Equals(const FieldInfo& other) const { |
| 6126 | return field_ == other.field_ && |
| 6127 | field_offset_ == other.field_offset_ && |
| 6128 | field_type_ == other.field_type_ && |
| 6129 | is_volatile_ == other.is_volatile_ && |
| 6130 | index_ == other.index_ && |
| 6131 | declaring_class_def_index_ == other.declaring_class_def_index_ && |
| 6132 | &dex_file_ == &other.dex_file_; |
| 6133 | } |
| 6134 | |
| 6135 | std::ostream& Dump(std::ostream& os) const { |
| 6136 | os << field_ << ", off: " << field_offset_ << ", type: " << field_type_ |
| 6137 | << ", volatile: " << std::boolalpha << is_volatile_ << ", index_: " << std::dec << index_ |
| 6138 | << ", declaring_class: " << declaring_class_def_index_ << ", dex: " << dex_file_; |
| 6139 | return os; |
| 6140 | } |
| 6141 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6142 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6143 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6144 | const MemberOffset field_offset_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6145 | const DataType::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6146 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6147 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6148 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6149 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6150 | }; |
| 6151 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6152 | inline bool operator==(const FieldInfo& a, const FieldInfo& b) { |
| 6153 | return a.Equals(b); |
| 6154 | } |
| 6155 | |
| 6156 | inline std::ostream& operator<<(std::ostream& os, const FieldInfo& a) { |
| 6157 | return a.Dump(os); |
| 6158 | } |
| 6159 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6160 | class HInstanceFieldGet final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6161 | public: |
| 6162 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6163 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6164 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6165 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6166 | bool is_volatile, |
| 6167 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6168 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6169 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6170 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6171 | : HExpression(kInstanceFieldGet, |
| 6172 | field_type, |
| 6173 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 6174 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6175 | field_info_(field, |
| 6176 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6177 | field_type, |
| 6178 | is_volatile, |
| 6179 | field_idx, |
| 6180 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6181 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6182 | SetRawInputAt(0, value); |
| 6183 | } |
| 6184 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6185 | bool IsClonable() const override { return true; } |
| 6186 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6187 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6188 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6189 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6190 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6191 | } |
| 6192 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6193 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 6194 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6195 | } |
| 6196 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6197 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 6198 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6199 | } |
| 6200 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6201 | bool IsFieldAccess() const override { return true; } |
| 6202 | const FieldInfo& GetFieldInfo() const override { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6203 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6204 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6205 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6206 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6207 | void SetType(DataType::Type new_type) { |
| 6208 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6209 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6210 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6211 | SetPackedField<TypeField>(new_type); |
| 6212 | } |
| 6213 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6214 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 6215 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6216 | protected: |
| 6217 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldGet); |
| 6218 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6219 | private: |
| 6220 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6221 | }; |
| 6222 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6223 | class HPredicatedInstanceFieldGet final : public HExpression<2> { |
| 6224 | public: |
| 6225 | HPredicatedInstanceFieldGet(HInstanceFieldGet* orig, |
| 6226 | HInstruction* target, |
| 6227 | HInstruction* default_val) |
| 6228 | : HExpression(kPredicatedInstanceFieldGet, |
| 6229 | orig->GetFieldType(), |
| 6230 | orig->GetSideEffects(), |
| 6231 | orig->GetDexPc()), |
| 6232 | field_info_(orig->GetFieldInfo()) { |
| 6233 | // NB Default-val is at 0 so we can avoid doing a move. |
| 6234 | SetRawInputAt(1, target); |
| 6235 | SetRawInputAt(0, default_val); |
| 6236 | } |
| 6237 | |
| 6238 | HPredicatedInstanceFieldGet(HInstruction* value, |
| 6239 | ArtField* field, |
| 6240 | HInstruction* default_value, |
| 6241 | DataType::Type field_type, |
| 6242 | MemberOffset field_offset, |
| 6243 | bool is_volatile, |
| 6244 | uint32_t field_idx, |
| 6245 | uint16_t declaring_class_def_index, |
| 6246 | const DexFile& dex_file, |
| 6247 | uint32_t dex_pc) |
| 6248 | : HExpression(kPredicatedInstanceFieldGet, |
| 6249 | field_type, |
| 6250 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 6251 | dex_pc), |
| 6252 | field_info_(field, |
| 6253 | field_offset, |
| 6254 | field_type, |
| 6255 | is_volatile, |
| 6256 | field_idx, |
| 6257 | declaring_class_def_index, |
| 6258 | dex_file) { |
Alex Light | 7432805 | 2021-03-29 18:11:23 -0700 | [diff] [blame] | 6259 | SetRawInputAt(1, value); |
| 6260 | SetRawInputAt(0, default_value); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6261 | } |
| 6262 | |
| 6263 | bool IsClonable() const override { |
| 6264 | return true; |
| 6265 | } |
| 6266 | bool CanBeMoved() const override { |
| 6267 | return !IsVolatile(); |
| 6268 | } |
| 6269 | |
| 6270 | HInstruction* GetDefaultValue() const { |
| 6271 | return InputAt(0); |
| 6272 | } |
| 6273 | HInstruction* GetTarget() const { |
| 6274 | return InputAt(1); |
| 6275 | } |
| 6276 | |
| 6277 | bool InstructionDataEquals(const HInstruction* other) const override { |
| 6278 | const HPredicatedInstanceFieldGet* other_get = other->AsPredicatedInstanceFieldGet(); |
| 6279 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue() && |
| 6280 | GetDefaultValue() == other_get->GetDefaultValue(); |
| 6281 | } |
| 6282 | |
| 6283 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
| 6284 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
| 6285 | } |
| 6286 | |
| 6287 | size_t ComputeHashCode() const override { |
| 6288 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6289 | } |
| 6290 | |
| 6291 | bool IsFieldAccess() const override { return true; } |
| 6292 | const FieldInfo& GetFieldInfo() const override { return field_info_; } |
| 6293 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 6294 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
| 6295 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
| 6296 | |
| 6297 | void SetType(DataType::Type new_type) { |
| 6298 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6299 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6300 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6301 | SetPackedField<TypeField>(new_type); |
| 6302 | } |
| 6303 | |
| 6304 | DECLARE_INSTRUCTION(PredicatedInstanceFieldGet); |
| 6305 | |
| 6306 | protected: |
| 6307 | DEFAULT_COPY_CONSTRUCTOR(PredicatedInstanceFieldGet); |
| 6308 | |
| 6309 | private: |
| 6310 | const FieldInfo field_info_; |
| 6311 | }; |
| 6312 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6313 | class HInstanceFieldSet final : public HExpression<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6314 | public: |
| 6315 | HInstanceFieldSet(HInstruction* object, |
| 6316 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6317 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6318 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6319 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6320 | bool is_volatile, |
| 6321 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6322 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6323 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6324 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6325 | : HExpression(kInstanceFieldSet, |
| 6326 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 6327 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6328 | field_info_(field, |
| 6329 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6330 | field_type, |
| 6331 | is_volatile, |
| 6332 | field_idx, |
| 6333 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6334 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6335 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6336 | SetPackedFlag<kFlagIsPredicatedSet>(false); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6337 | SetRawInputAt(0, object); |
| 6338 | SetRawInputAt(1, value); |
| 6339 | } |
| 6340 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6341 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6342 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6343 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 6344 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6345 | } |
| 6346 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6347 | bool IsFieldAccess() const override { return true; } |
| 6348 | const FieldInfo& GetFieldInfo() const override { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6349 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6350 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6351 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6352 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6353 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6354 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6355 | bool GetIsPredicatedSet() const { return GetPackedFlag<kFlagIsPredicatedSet>(); } |
| 6356 | void SetIsPredicatedSet(bool value = true) { SetPackedFlag<kFlagIsPredicatedSet>(value); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6357 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6358 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 6359 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6360 | protected: |
| 6361 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldSet); |
| 6362 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6363 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6364 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6365 | static constexpr size_t kFlagIsPredicatedSet = kFlagValueCanBeNull + 1; |
| 6366 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagIsPredicatedSet + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6367 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6368 | "Too many packed fields."); |
| 6369 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6370 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6371 | }; |
| 6372 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6373 | class HArrayGet final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6374 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6375 | HArrayGet(HInstruction* array, |
| 6376 | HInstruction* index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6377 | DataType::Type type, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6378 | uint32_t dex_pc) |
| 6379 | : HArrayGet(array, |
| 6380 | index, |
| 6381 | type, |
| 6382 | SideEffects::ArrayReadOfType(type), |
| 6383 | dex_pc, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6384 | /* is_string_char_at= */ false) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6385 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6386 | |
| 6387 | HArrayGet(HInstruction* array, |
| 6388 | HInstruction* index, |
| 6389 | DataType::Type type, |
| 6390 | SideEffects side_effects, |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6391 | uint32_t dex_pc, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6392 | bool is_string_char_at) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6393 | : HExpression(kArrayGet, type, side_effects, dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6394 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6395 | SetRawInputAt(0, array); |
| 6396 | SetRawInputAt(1, index); |
| 6397 | } |
| 6398 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6399 | bool IsClonable() const override { return true; } |
| 6400 | bool CanBeMoved() const override { return true; } |
| 6401 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6402 | return true; |
| 6403 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6404 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6405 | // TODO: We can be smarter here. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6406 | // Currently, unless the array is the result of NewArray, the array access is always |
| 6407 | // preceded by some form of null NullCheck necessary for the bounds check, usually |
| 6408 | // implicit null check on the ArrayLength input to BoundsCheck or Deoptimize for |
| 6409 | // dynamic BCE. There are cases when these could be removed to produce better code. |
| 6410 | // If we ever add optimizations to do so we should allow an implicit check here |
| 6411 | // (as long as the address falls in the first page). |
| 6412 | // |
| 6413 | // As an example of such fancy optimization, we could eliminate BoundsCheck for |
| 6414 | // a = cond ? new int[1] : null; |
| 6415 | // a[0]; // The Phi does not need bounds check for either input. |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6416 | return false; |
| 6417 | } |
| 6418 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 6419 | bool IsEquivalentOf(HArrayGet* other) const { |
| 6420 | bool result = (GetDexPc() == other->GetDexPc()); |
| 6421 | if (kIsDebugBuild && result) { |
| 6422 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 6423 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 6424 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6425 | if (DataType::IsIntOrLongType(GetType())) { |
| 6426 | DCHECK(DataType::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 6427 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6428 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| 6429 | DCHECK(DataType::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 6430 | } |
| 6431 | } |
| 6432 | return result; |
| 6433 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6434 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6435 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 6436 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6437 | HInstruction* GetArray() const { return InputAt(0); } |
| 6438 | HInstruction* GetIndex() const { return InputAt(1); } |
| 6439 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6440 | void SetType(DataType::Type new_type) { |
| 6441 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6442 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6443 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6444 | SetPackedField<TypeField>(new_type); |
| 6445 | } |
| 6446 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6447 | DECLARE_INSTRUCTION(ArrayGet); |
| 6448 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6449 | protected: |
| 6450 | DEFAULT_COPY_CONSTRUCTOR(ArrayGet); |
| 6451 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6452 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6453 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 6454 | // intrinsic in the instruction simplifier. We can always determine whether |
| 6455 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 6456 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 6457 | // 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] | 6458 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6459 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 6460 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6461 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6462 | }; |
| 6463 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6464 | class HArraySet final : public HExpression<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6465 | public: |
| 6466 | HArraySet(HInstruction* array, |
| 6467 | HInstruction* index, |
| 6468 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6469 | DataType::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 6470 | uint32_t dex_pc) |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6471 | : HArraySet(array, |
| 6472 | index, |
| 6473 | value, |
| 6474 | expected_component_type, |
| 6475 | // Make a best guess for side effects now, may be refined during SSA building. |
| 6476 | ComputeSideEffects(GetComponentType(value->GetType(), expected_component_type)), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6477 | dex_pc) { |
| 6478 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6479 | |
| 6480 | HArraySet(HInstruction* array, |
| 6481 | HInstruction* index, |
| 6482 | HInstruction* value, |
| 6483 | DataType::Type expected_component_type, |
| 6484 | SideEffects side_effects, |
| 6485 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6486 | : HExpression(kArraySet, side_effects, dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6487 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6488 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6489 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 6490 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6491 | SetRawInputAt(0, array); |
| 6492 | SetRawInputAt(1, index); |
| 6493 | SetRawInputAt(2, value); |
| 6494 | } |
| 6495 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6496 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6497 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6498 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6499 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6500 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6501 | } |
| 6502 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 6503 | // Can throw ArrayStoreException. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6504 | bool CanThrow() const override { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 6505 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6506 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6507 | // TODO: Same as for ArrayGet. |
| 6508 | return false; |
| 6509 | } |
| 6510 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6511 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6512 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6513 | } |
| 6514 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6515 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6516 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6517 | } |
| 6518 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6519 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6520 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6521 | } |
| 6522 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6523 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6524 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 6525 | bool StaticTypeOfArrayIsObjectArray() const { |
| 6526 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 6527 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6528 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6529 | HInstruction* GetArray() const { return InputAt(0); } |
| 6530 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6531 | HInstruction* GetValue() const { return InputAt(2); } |
| 6532 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6533 | DataType::Type GetComponentType() const { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6534 | return GetComponentType(GetValue()->GetType(), GetRawExpectedComponentType()); |
| 6535 | } |
| 6536 | |
| 6537 | static DataType::Type GetComponentType(DataType::Type value_type, |
| 6538 | DataType::Type expected_component_type) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6539 | // The Dex format does not type floating point index operations. Since the |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6540 | // `expected_component_type` comes from SSA building and can therefore not |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6541 | // be correct, we also check what is the value type. If it is a floating |
| 6542 | // point type, we must use that type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6543 | return ((value_type == DataType::Type::kFloat32) || (value_type == DataType::Type::kFloat64)) |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6544 | ? value_type |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6545 | : expected_component_type; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6546 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6547 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6548 | DataType::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6549 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6550 | } |
| 6551 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6552 | static SideEffects ComputeSideEffects(DataType::Type type) { |
| 6553 | return SideEffects::ArrayWriteOfType(type).Union(SideEffectsForArchRuntimeCalls(type)); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 6554 | } |
| 6555 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6556 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type value_type) { |
| 6557 | return (value_type == DataType::Type::kReference) ? SideEffects::CanTriggerGC() |
| 6558 | : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6559 | } |
| 6560 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6561 | DECLARE_INSTRUCTION(ArraySet); |
| 6562 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6563 | protected: |
| 6564 | DEFAULT_COPY_CONSTRUCTOR(ArraySet); |
| 6565 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6566 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6567 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 6568 | static constexpr size_t kFieldExpectedComponentTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6569 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6570 | static constexpr size_t kFlagNeedsTypeCheck = |
| 6571 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 6572 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6573 | // Cached information for the reference_type_info_ so that codegen |
| 6574 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6575 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 6576 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 6577 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 6578 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6579 | using ExpectedComponentTypeField = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6580 | BitField<DataType::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6581 | }; |
| 6582 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6583 | class HArrayLength final : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6584 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6585 | 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] | 6586 | : HExpression(kArrayLength, DataType::Type::kInt32, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6587 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6588 | // Note that arrays do not change length, so the instruction does not |
| 6589 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6590 | SetRawInputAt(0, array); |
| 6591 | } |
| 6592 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6593 | bool IsClonable() const override { return true; } |
| 6594 | bool CanBeMoved() const override { return true; } |
| 6595 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6596 | return true; |
| 6597 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6598 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 6599 | return obj == InputAt(0); |
| 6600 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6601 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6602 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 6603 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6604 | DECLARE_INSTRUCTION(ArrayLength); |
| 6605 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6606 | protected: |
| 6607 | DEFAULT_COPY_CONSTRUCTOR(ArrayLength); |
| 6608 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6609 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6610 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 6611 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 6612 | // determine whether a particular HArrayLength is actually a String.length() by |
| 6613 | // looking at the type of the input but that requires holding the mutator lock, so |
| 6614 | // 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] | 6615 | static constexpr size_t kFlagIsStringLength = kNumberOfGenericPackedBits; |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6616 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 6617 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6618 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6619 | }; |
| 6620 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6621 | class HBoundsCheck final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6622 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 6623 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6624 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 6625 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6626 | HBoundsCheck(HInstruction* index, |
| 6627 | HInstruction* length, |
| 6628 | uint32_t dex_pc, |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6629 | bool is_string_char_at = false) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6630 | : HExpression(kBoundsCheck, index->GetType(), SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6631 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(index->GetType())); |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6632 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6633 | SetRawInputAt(0, index); |
| 6634 | SetRawInputAt(1, length); |
| 6635 | } |
| 6636 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6637 | bool IsClonable() const override { return true; } |
| 6638 | bool CanBeMoved() const override { return true; } |
| 6639 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6640 | return true; |
| 6641 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6642 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6643 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6644 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6645 | bool CanThrow() const override { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 6646 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 6647 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6648 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6649 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6650 | |
| 6651 | DECLARE_INSTRUCTION(BoundsCheck); |
| 6652 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6653 | protected: |
| 6654 | DEFAULT_COPY_CONSTRUCTOR(BoundsCheck); |
| 6655 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6656 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6657 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | f02046e | 2018-10-02 15:31:32 +0100 | [diff] [blame] | 6658 | static constexpr size_t kNumberOfBoundsCheckPackedBits = kFlagIsStringCharAt + 1; |
| 6659 | static_assert(kNumberOfBoundsCheckPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6660 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6661 | }; |
| 6662 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6663 | class HSuspendCheck final : public HExpression<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6664 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 6665 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6666 | : HExpression(kSuspendCheck, SideEffects::CanTriggerGC(), dex_pc), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6667 | slow_path_(nullptr) { |
| 6668 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6669 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6670 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6671 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6672 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6673 | return true; |
| 6674 | } |
| 6675 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6676 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 6677 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6678 | |
| 6679 | DECLARE_INSTRUCTION(SuspendCheck); |
| 6680 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6681 | protected: |
| 6682 | DEFAULT_COPY_CONSTRUCTOR(SuspendCheck); |
| 6683 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6684 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6685 | // Only used for code generation, in order to share the same slow path between back edges |
| 6686 | // of a same loop. |
| 6687 | SlowPathCode* slow_path_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6688 | }; |
| 6689 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6690 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 6691 | // It ensures that we can generate line number and local variables at this point. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6692 | class HNativeDebugInfo : public HExpression<0> { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6693 | public: |
| 6694 | explicit HNativeDebugInfo(uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6695 | : HExpression<0>(kNativeDebugInfo, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6696 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6697 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6698 | bool NeedsEnvironment() const override { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6699 | return true; |
| 6700 | } |
| 6701 | |
| 6702 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 6703 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6704 | protected: |
| 6705 | DEFAULT_COPY_CONSTRUCTOR(NativeDebugInfo); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6706 | }; |
| 6707 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6708 | /** |
| 6709 | * Instruction to load a Class object. |
| 6710 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6711 | class HLoadClass final : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6712 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6713 | // Determines how to load the Class. |
| 6714 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6715 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 6716 | kInvalid = -1, |
| 6717 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6718 | // Use the Class* from the method's own ArtMethod*. |
| 6719 | kReferrersClass, |
| 6720 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6721 | // 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] | 6722 | // Used for boot image classes referenced by boot image code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6723 | kBootImageLinkTimePcRelative, |
| 6724 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6725 | // 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] | 6726 | // Used for boot image classes referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6727 | kBootImageRelRo, |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6728 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6729 | // 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] | 6730 | // 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] | 6731 | kBssEntry, |
| 6732 | |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6733 | // Load from an entry for public class in the .bss section using a PC-relative load. |
| 6734 | // Used for classes that were unresolved during AOT-compilation outside the literal |
| 6735 | // package of the compiling class. Such classes are accessible only if they are public |
| 6736 | // and the .bss entry shall therefore be filled only if the resolved class is public. |
| 6737 | kBssEntryPublic, |
| 6738 | |
| 6739 | // Load from an entry for package class in the .bss section using a PC-relative load. |
| 6740 | // Used for classes that were unresolved during AOT-compilation but within the literal |
| 6741 | // package of the compiling class. Such classes are accessible if they are public or |
| 6742 | // in the same package which, given the literal package match, requires only matching |
| 6743 | // defining class loader and the .bss entry shall therefore be filled only if at least |
| 6744 | // one of those conditions holds. Note that all code in an oat file belongs to classes |
| 6745 | // with the same defining class loader. |
| 6746 | kBssEntryPackage, |
| 6747 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6748 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 6749 | // Used for boot image classes referenced by apps in JIT-compiled code. |
| 6750 | kJitBootImageAddress, |
| 6751 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6752 | // Load from the root table associated with the JIT compiled method. |
| 6753 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6754 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6755 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6756 | // the codegen is unable to use another appropriate kind. |
| 6757 | kRuntimeCall, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6758 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6759 | kLast = kRuntimeCall |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6760 | }; |
| 6761 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6762 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6763 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6764 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6765 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6766 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6767 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6768 | bool needs_access_check) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6769 | : HInstruction(kLoadClass, |
| 6770 | DataType::Type::kReference, |
| 6771 | SideEffectsForArchRuntimeCalls(), |
| 6772 | dex_pc), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6773 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6774 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6775 | dex_file_(dex_file), |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6776 | klass_(klass) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 6777 | // Referrers class should not need access check. We never inline unverified |
| 6778 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6779 | DCHECK(!is_referrers_class || !needs_access_check); |
| 6780 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6781 | SetPackedField<LoadKindField>( |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6782 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kRuntimeCall); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6783 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6784 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6785 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6786 | SetPackedFlag<kFlagValidLoadedClassRTI>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6787 | } |
| 6788 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6789 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6790 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6791 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6792 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6793 | LoadKind GetLoadKind() const { |
| 6794 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6795 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6796 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6797 | bool HasPcRelativeLoadKind() const { |
| 6798 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6799 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6800 | GetLoadKind() == LoadKind::kBssEntry || |
| 6801 | GetLoadKind() == LoadKind::kBssEntryPublic || |
| 6802 | GetLoadKind() == LoadKind::kBssEntryPackage; |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6803 | } |
| 6804 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6805 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6806 | |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame] | 6807 | bool InstructionDataEquals(const HInstruction* other) const override; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6808 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6809 | size_t ComputeHashCode() const override { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6810 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6811 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6812 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6813 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6814 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6815 | } |
| 6816 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 6817 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6818 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6819 | } |
| 6820 | |
| 6821 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6822 | return NeedsAccessCheck() || |
| 6823 | MustGenerateClinitCheck() || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6824 | GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6825 | GetLoadKind() == LoadKind::kBssEntry; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6826 | } |
| 6827 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6828 | bool CanThrow() const override { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6829 | return NeedsAccessCheck() || |
| 6830 | MustGenerateClinitCheck() || |
| 6831 | // If the class is in the boot image, the lookup in the runtime call cannot throw. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6832 | ((GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6833 | GetLoadKind() == LoadKind::kBssEntry) && |
| 6834 | !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6835 | } |
| 6836 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6837 | ReferenceTypeInfo GetLoadedClassRTI() { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6838 | if (GetPackedFlag<kFlagValidLoadedClassRTI>()) { |
| 6839 | // 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] | 6840 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact= */ true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6841 | } else { |
| 6842 | return ReferenceTypeInfo::CreateInvalid(); |
| 6843 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6844 | } |
| 6845 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6846 | // 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] | 6847 | void SetValidLoadedClassRTI() { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6848 | DCHECK(klass_ != nullptr); |
| 6849 | SetPackedFlag<kFlagValidLoadedClassRTI>(true); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6850 | } |
| 6851 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6852 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6853 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6854 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6855 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6856 | return SideEffects::CanTriggerGC(); |
| 6857 | } |
| 6858 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6859 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6860 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6861 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6862 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6863 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6864 | bool MustResolveTypeOnSlowPath() const { |
| 6865 | // Check that this instruction has a slow path. |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6866 | LoadKind load_kind = GetLoadKind(); |
| 6867 | DCHECK(load_kind != LoadKind::kRuntimeCall); // kRuntimeCall calls on main path. |
| 6868 | bool must_resolve_type_on_slow_path = |
| 6869 | load_kind == LoadKind::kBssEntry || |
| 6870 | load_kind == LoadKind::kBssEntryPublic || |
| 6871 | load_kind == LoadKind::kBssEntryPackage; |
| 6872 | DCHECK(must_resolve_type_on_slow_path || MustGenerateClinitCheck()); |
| 6873 | return must_resolve_type_on_slow_path; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6874 | } |
| 6875 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6876 | void MarkInBootImage() { |
| 6877 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 6878 | } |
| 6879 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6880 | void AddSpecialInput(HInstruction* special_input); |
| 6881 | |
| 6882 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6883 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6884 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6885 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6886 | } |
| 6887 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6888 | Handle<mirror::Class> GetClass() const { |
| 6889 | return klass_; |
| 6890 | } |
| 6891 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6892 | DECLARE_INSTRUCTION(LoadClass); |
| 6893 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6894 | protected: |
| 6895 | DEFAULT_COPY_CONSTRUCTOR(LoadClass); |
| 6896 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6897 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6898 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6899 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6900 | // Whether this instruction must generate the initialization check. |
| 6901 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6902 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6903 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 6904 | static constexpr size_t kFieldLoadKindSize = |
| 6905 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6906 | static constexpr size_t kFlagValidLoadedClassRTI = kFieldLoadKind + kFieldLoadKindSize; |
| 6907 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagValidLoadedClassRTI + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6908 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6909 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 6910 | |
| 6911 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6912 | return load_kind == LoadKind::kReferrersClass || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6913 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6914 | load_kind == LoadKind::kBssEntry || |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6915 | load_kind == LoadKind::kBssEntryPublic || |
| 6916 | load_kind == LoadKind::kBssEntryPackage || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6917 | load_kind == LoadKind::kRuntimeCall; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6918 | } |
| 6919 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6920 | void SetLoadKindInternal(LoadKind load_kind); |
| 6921 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6922 | // The special input is the HCurrentMethod for kRuntimeCall or kReferrersClass. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6923 | // 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] | 6924 | // for PC-relative loads, i.e. kBssEntry* or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6925 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6926 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6927 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 6928 | // - The compiling method's dex file if the class is defined there too. |
| 6929 | // - The compiling method's dex file if the class is referenced there. |
| 6930 | // - 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] | 6931 | // kBssEntry* or kRuntimeCall, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6932 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6933 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6934 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6935 | Handle<mirror::Class> klass_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6936 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6937 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 6938 | |
| 6939 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6940 | inline void HLoadClass::SetLoadKind(LoadKind load_kind) { |
| 6941 | // The load kind should be determined before inserting the instruction to the graph. |
| 6942 | DCHECK(GetBlock() == nullptr); |
| 6943 | DCHECK(GetEnvironment() == nullptr); |
| 6944 | SetPackedField<LoadKindField>(load_kind); |
| 6945 | if (load_kind != LoadKind::kRuntimeCall && load_kind != LoadKind::kReferrersClass) { |
| 6946 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6947 | } |
| 6948 | if (!NeedsEnvironment()) { |
| 6949 | SetSideEffects(SideEffects::None()); |
| 6950 | } |
| 6951 | } |
| 6952 | |
| 6953 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6954 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6955 | // The special input is used for PC-relative loads on some architectures, |
| 6956 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6957 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6958 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6959 | GetLoadKind() == LoadKind::kBssEntry || |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6960 | GetLoadKind() == LoadKind::kBssEntryPublic || |
| 6961 | GetLoadKind() == LoadKind::kBssEntryPackage || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6962 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6963 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6964 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 6965 | special_input->AddUseAt(this, 0); |
| 6966 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6967 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6968 | class HLoadString final : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6969 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6970 | // Determines how to load the String. |
| 6971 | enum class LoadKind { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6972 | // 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] | 6973 | // Used for boot image strings referenced by boot image code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6974 | kBootImageLinkTimePcRelative, |
| 6975 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6976 | // 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] | 6977 | // Used for boot image strings referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6978 | kBootImageRelRo, |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6979 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6980 | // 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] | 6981 | // 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] | 6982 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6983 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6984 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 6985 | // Used for boot image strings referenced by apps in JIT-compiled code. |
| 6986 | kJitBootImageAddress, |
| 6987 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6988 | // Load from the root table associated with the JIT compiled method. |
| 6989 | kJitTableAddress, |
| 6990 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6991 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6992 | // the codegen is unable to use another appropriate kind. |
| 6993 | kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6994 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6995 | kLast = kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6996 | }; |
| 6997 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6998 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6999 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7000 | const DexFile& dex_file, |
| 7001 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7002 | : HInstruction(kLoadString, |
| 7003 | DataType::Type::kReference, |
| 7004 | SideEffectsForArchRuntimeCalls(), |
| 7005 | dex_pc), |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7006 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7007 | string_index_(string_index), |
| 7008 | dex_file_(dex_file) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7009 | SetPackedField<LoadKindField>(LoadKind::kRuntimeCall); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 7010 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7011 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7012 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7013 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7014 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7015 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7016 | LoadKind GetLoadKind() const { |
| 7017 | return GetPackedField<LoadKindField>(); |
| 7018 | } |
| 7019 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7020 | bool HasPcRelativeLoadKind() const { |
| 7021 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 7022 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 7023 | GetLoadKind() == LoadKind::kBssEntry; |
| 7024 | } |
| 7025 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7026 | const DexFile& GetDexFile() const { |
| 7027 | return dex_file_; |
| 7028 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7029 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7030 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7031 | return string_index_; |
| 7032 | } |
| 7033 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7034 | Handle<mirror::String> GetString() const { |
| 7035 | return string_; |
| 7036 | } |
| 7037 | |
| 7038 | void SetString(Handle<mirror::String> str) { |
| 7039 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7040 | } |
| 7041 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7042 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7043 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7044 | bool InstructionDataEquals(const HInstruction* other) const override; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7045 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7046 | size_t ComputeHashCode() const override { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7047 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7048 | // Will call the runtime if we need to load the string through |
| 7049 | // 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] | 7050 | bool NeedsEnvironment() const override { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7051 | LoadKind load_kind = GetLoadKind(); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7052 | if (load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7053 | load_kind == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7054 | load_kind == LoadKind::kJitBootImageAddress || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7055 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7056 | return false; |
| 7057 | } |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 7058 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7059 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7060 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7061 | bool CanBeNull() const override { return false; } |
| 7062 | bool CanThrow() const override { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7063 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7064 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 7065 | return SideEffects::CanTriggerGC(); |
| 7066 | } |
| 7067 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7068 | void AddSpecialInput(HInstruction* special_input); |
| 7069 | |
| 7070 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 7071 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7072 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 7073 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7074 | } |
| 7075 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7076 | DECLARE_INSTRUCTION(LoadString); |
| 7077 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7078 | protected: |
| 7079 | DEFAULT_COPY_CONSTRUCTOR(LoadString); |
| 7080 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7081 | private: |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 7082 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7083 | static constexpr size_t kFieldLoadKindSize = |
| 7084 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 7085 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7086 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7087 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7088 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7089 | void SetLoadKindInternal(LoadKind load_kind); |
| 7090 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7091 | // The special input is the HCurrentMethod for kRuntimeCall. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7092 | // 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] | 7093 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7094 | HUserRecord<HInstruction*> special_input_; |
| 7095 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7096 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7097 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7098 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7099 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7100 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7101 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 7102 | |
| 7103 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 7104 | inline void HLoadString::SetLoadKind(LoadKind load_kind) { |
| 7105 | // The load kind should be determined before inserting the instruction to the graph. |
| 7106 | DCHECK(GetBlock() == nullptr); |
| 7107 | DCHECK(GetEnvironment() == nullptr); |
| 7108 | DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); |
| 7109 | SetPackedField<LoadKindField>(load_kind); |
| 7110 | if (load_kind != LoadKind::kRuntimeCall) { |
| 7111 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 7112 | } |
| 7113 | if (!NeedsEnvironment()) { |
| 7114 | SetSideEffects(SideEffects::None()); |
| 7115 | } |
| 7116 | } |
| 7117 | |
| 7118 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7119 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 7120 | // The special input is used for PC-relative loads on some architectures, |
| 7121 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7122 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7123 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7124 | GetLoadKind() == LoadKind::kBssEntry || |
| 7125 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7126 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 7127 | // so use the GetInputRecords() from the base class to set the input record. |
| 7128 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 7129 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7130 | special_input->AddUseAt(this, 0); |
| 7131 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7132 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7133 | class HLoadMethodHandle final : public HInstruction { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7134 | public: |
| 7135 | HLoadMethodHandle(HCurrentMethod* current_method, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 7136 | uint16_t method_handle_idx, |
| 7137 | const DexFile& dex_file, |
| 7138 | uint32_t dex_pc) |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7139 | : HInstruction(kLoadMethodHandle, |
| 7140 | DataType::Type::kReference, |
| 7141 | SideEffectsForArchRuntimeCalls(), |
| 7142 | dex_pc), |
| 7143 | special_input_(HUserRecord<HInstruction*>(current_method)), |
| 7144 | method_handle_idx_(method_handle_idx), |
| 7145 | dex_file_(dex_file) { |
| 7146 | } |
| 7147 | |
| 7148 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 7149 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7150 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 7151 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 7152 | } |
| 7153 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7154 | bool IsClonable() const override { return true; } |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7155 | |
| 7156 | uint16_t GetMethodHandleIndex() const { return method_handle_idx_; } |
| 7157 | |
| 7158 | const DexFile& GetDexFile() const { return dex_file_; } |
| 7159 | |
| 7160 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 7161 | return SideEffects::CanTriggerGC(); |
| 7162 | } |
| 7163 | |
| 7164 | DECLARE_INSTRUCTION(LoadMethodHandle); |
| 7165 | |
| 7166 | protected: |
| 7167 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodHandle); |
| 7168 | |
| 7169 | private: |
| 7170 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 7171 | HUserRecord<HInstruction*> special_input_; |
| 7172 | |
| 7173 | const uint16_t method_handle_idx_; |
| 7174 | const DexFile& dex_file_; |
| 7175 | }; |
| 7176 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7177 | class HLoadMethodType final : public HInstruction { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7178 | public: |
| 7179 | HLoadMethodType(HCurrentMethod* current_method, |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 7180 | dex::ProtoIndex proto_index, |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7181 | const DexFile& dex_file, |
| 7182 | uint32_t dex_pc) |
| 7183 | : HInstruction(kLoadMethodType, |
| 7184 | DataType::Type::kReference, |
| 7185 | SideEffectsForArchRuntimeCalls(), |
| 7186 | dex_pc), |
| 7187 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 7188 | proto_index_(proto_index), |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7189 | dex_file_(dex_file) { |
| 7190 | } |
| 7191 | |
| 7192 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 7193 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7194 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 7195 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 7196 | } |
| 7197 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7198 | bool IsClonable() const override { return true; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7199 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 7200 | dex::ProtoIndex GetProtoIndex() const { return proto_index_; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7201 | |
| 7202 | const DexFile& GetDexFile() const { return dex_file_; } |
| 7203 | |
| 7204 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 7205 | return SideEffects::CanTriggerGC(); |
| 7206 | } |
| 7207 | |
| 7208 | DECLARE_INSTRUCTION(LoadMethodType); |
| 7209 | |
| 7210 | protected: |
| 7211 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodType); |
| 7212 | |
| 7213 | private: |
| 7214 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 7215 | HUserRecord<HInstruction*> special_input_; |
| 7216 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 7217 | const dex::ProtoIndex proto_index_; |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7218 | const DexFile& dex_file_; |
| 7219 | }; |
| 7220 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7221 | /** |
| 7222 | * Performs an initialization check on its Class object input. |
| 7223 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7224 | class HClinitCheck final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7225 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 7226 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 7227 | : HExpression( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7228 | kClinitCheck, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7229 | DataType::Type::kReference, |
Mingyao Yang | 217eb06 | 2017-12-11 15:20:07 -0800 | [diff] [blame] | 7230 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7231 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7232 | SetRawInputAt(0, constant); |
| 7233 | } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 7234 | // TODO: Make ClinitCheck clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7235 | bool CanBeMoved() const override { return true; } |
| 7236 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7237 | return true; |
| 7238 | } |
| 7239 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7240 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7241 | // May call runtime to initialize the class. |
| 7242 | return true; |
| 7243 | } |
| 7244 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7245 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7246 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7247 | HLoadClass* GetLoadClass() const { |
| 7248 | DCHECK(InputAt(0)->IsLoadClass()); |
| 7249 | return InputAt(0)->AsLoadClass(); |
| 7250 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7251 | |
| 7252 | DECLARE_INSTRUCTION(ClinitCheck); |
| 7253 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7254 | |
| 7255 | protected: |
| 7256 | DEFAULT_COPY_CONSTRUCTOR(ClinitCheck); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7257 | }; |
| 7258 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7259 | class HStaticFieldGet final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7260 | public: |
| 7261 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7262 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7263 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7264 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 7265 | bool is_volatile, |
| 7266 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 7267 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 7268 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 7269 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7270 | : HExpression(kStaticFieldGet, |
| 7271 | field_type, |
| 7272 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 7273 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7274 | field_info_(field, |
| 7275 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 7276 | field_type, |
| 7277 | is_volatile, |
| 7278 | field_idx, |
| 7279 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7280 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7281 | SetRawInputAt(0, cls); |
| 7282 | } |
| 7283 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7284 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7285 | bool IsClonable() const override { return true; } |
| 7286 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7287 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7288 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7289 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7290 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7291 | } |
| 7292 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7293 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7294 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 7295 | } |
| 7296 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 7297 | bool IsFieldAccess() const override { return true; } |
| 7298 | const FieldInfo& GetFieldInfo() const override { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7299 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7300 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7301 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7302 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 7303 | void SetType(DataType::Type new_type) { |
| 7304 | DCHECK(DataType::IsIntegralType(GetType())); |
| 7305 | DCHECK(DataType::IsIntegralType(new_type)); |
| 7306 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 7307 | SetPackedField<TypeField>(new_type); |
| 7308 | } |
| 7309 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7310 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 7311 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7312 | protected: |
| 7313 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldGet); |
| 7314 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7315 | private: |
| 7316 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7317 | }; |
| 7318 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7319 | class HStaticFieldSet final : public HExpression<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7320 | public: |
| 7321 | HStaticFieldSet(HInstruction* cls, |
| 7322 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7323 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7324 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7325 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 7326 | bool is_volatile, |
| 7327 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 7328 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 7329 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 7330 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7331 | : HExpression(kStaticFieldSet, |
| 7332 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 7333 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7334 | field_info_(field, |
| 7335 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 7336 | field_type, |
| 7337 | is_volatile, |
| 7338 | field_idx, |
| 7339 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 7340 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7341 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7342 | SetRawInputAt(0, cls); |
| 7343 | SetRawInputAt(1, value); |
| 7344 | } |
| 7345 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7346 | bool IsClonable() const override { return true; } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 7347 | bool IsFieldAccess() const override { return true; } |
| 7348 | const FieldInfo& GetFieldInfo() const override { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7349 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7350 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7351 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7352 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 7353 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7354 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 7355 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 7356 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7357 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 7358 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7359 | protected: |
| 7360 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldSet); |
| 7361 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7362 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7363 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 7364 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 7365 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 7366 | "Too many packed fields."); |
| 7367 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7368 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7369 | }; |
| 7370 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 7371 | class HStringBuilderAppend final : public HVariableInputSizeInstruction { |
| 7372 | public: |
| 7373 | HStringBuilderAppend(HIntConstant* format, |
| 7374 | uint32_t number_of_arguments, |
| 7375 | ArenaAllocator* allocator, |
| 7376 | uint32_t dex_pc) |
| 7377 | : HVariableInputSizeInstruction( |
| 7378 | kStringBuilderAppend, |
| 7379 | DataType::Type::kReference, |
| 7380 | // The runtime call may read memory from inputs. It never writes outside |
| 7381 | // of the newly allocated result object (or newly allocated helper objects). |
| 7382 | SideEffects::AllReads().Union(SideEffects::CanTriggerGC()), |
| 7383 | dex_pc, |
| 7384 | allocator, |
| 7385 | number_of_arguments + /* format */ 1u, |
| 7386 | kArenaAllocInvokeInputs) { |
| 7387 | DCHECK_GE(number_of_arguments, 1u); // There must be something to append. |
| 7388 | SetRawInputAt(FormatIndex(), format); |
| 7389 | } |
| 7390 | |
| 7391 | void SetArgumentAt(size_t index, HInstruction* argument) { |
| 7392 | DCHECK_LE(index, GetNumberOfArguments()); |
| 7393 | SetRawInputAt(index, argument); |
| 7394 | } |
| 7395 | |
| 7396 | // Return the number of arguments, excluding the format. |
| 7397 | size_t GetNumberOfArguments() const { |
| 7398 | DCHECK_GE(InputCount(), 1u); |
| 7399 | return InputCount() - 1u; |
| 7400 | } |
| 7401 | |
| 7402 | size_t FormatIndex() const { |
| 7403 | return GetNumberOfArguments(); |
| 7404 | } |
| 7405 | |
| 7406 | HIntConstant* GetFormat() { |
| 7407 | return InputAt(FormatIndex())->AsIntConstant(); |
| 7408 | } |
| 7409 | |
| 7410 | bool NeedsEnvironment() const override { return true; } |
| 7411 | |
| 7412 | bool CanThrow() const override { return true; } |
| 7413 | |
Vladimir Marko | b1fe5e1 | 2020-03-10 14:30:49 +0000 | [diff] [blame] | 7414 | bool CanBeNull() const override { return false; } |
| 7415 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 7416 | DECLARE_INSTRUCTION(StringBuilderAppend); |
| 7417 | |
| 7418 | protected: |
| 7419 | DEFAULT_COPY_CONSTRUCTOR(StringBuilderAppend); |
| 7420 | }; |
| 7421 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7422 | class HUnresolvedInstanceFieldGet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7423 | public: |
| 7424 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7425 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7426 | uint32_t field_index, |
| 7427 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7428 | : HExpression(kUnresolvedInstanceFieldGet, |
| 7429 | field_type, |
| 7430 | SideEffects::AllExceptGCDependency(), |
| 7431 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7432 | field_index_(field_index) { |
| 7433 | SetRawInputAt(0, obj); |
| 7434 | } |
| 7435 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7436 | bool IsClonable() const override { return true; } |
| 7437 | bool NeedsEnvironment() const override { return true; } |
| 7438 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7439 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7440 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7441 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7442 | |
| 7443 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 7444 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7445 | protected: |
| 7446 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldGet); |
| 7447 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7448 | private: |
| 7449 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7450 | }; |
| 7451 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7452 | class HUnresolvedInstanceFieldSet final : public HExpression<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7453 | public: |
| 7454 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 7455 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7456 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7457 | uint32_t field_index, |
| 7458 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7459 | : HExpression(kUnresolvedInstanceFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7460 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7461 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7462 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7463 | SetRawInputAt(0, obj); |
| 7464 | SetRawInputAt(1, value); |
| 7465 | } |
| 7466 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7467 | bool IsClonable() const override { return true; } |
| 7468 | bool NeedsEnvironment() const override { return true; } |
| 7469 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7470 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7471 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7472 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7473 | |
| 7474 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 7475 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7476 | protected: |
| 7477 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldSet); |
| 7478 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7479 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7480 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 7481 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7482 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7483 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 7484 | kFieldFieldType + kFieldFieldTypeSize; |
| 7485 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7486 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7487 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7488 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7489 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7490 | }; |
| 7491 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7492 | class HUnresolvedStaticFieldGet final : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7493 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7494 | HUnresolvedStaticFieldGet(DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7495 | uint32_t field_index, |
| 7496 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7497 | : HExpression(kUnresolvedStaticFieldGet, |
| 7498 | field_type, |
| 7499 | SideEffects::AllExceptGCDependency(), |
| 7500 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7501 | field_index_(field_index) { |
| 7502 | } |
| 7503 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7504 | bool IsClonable() const override { return true; } |
| 7505 | bool NeedsEnvironment() const override { return true; } |
| 7506 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7507 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7508 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7509 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7510 | |
| 7511 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 7512 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7513 | protected: |
| 7514 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldGet); |
| 7515 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7516 | private: |
| 7517 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7518 | }; |
| 7519 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7520 | class HUnresolvedStaticFieldSet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7521 | public: |
| 7522 | HUnresolvedStaticFieldSet(HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7523 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7524 | uint32_t field_index, |
| 7525 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7526 | : HExpression(kUnresolvedStaticFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7527 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7528 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7529 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7530 | SetRawInputAt(0, value); |
| 7531 | } |
| 7532 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7533 | bool IsClonable() const override { return true; } |
| 7534 | bool NeedsEnvironment() const override { return true; } |
| 7535 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7536 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7537 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7538 | uint32_t GetFieldIndex() const { return field_index_; } |
| 7539 | |
| 7540 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 7541 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7542 | protected: |
| 7543 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldSet); |
| 7544 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7545 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7546 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 7547 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7548 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7549 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 7550 | kFieldFieldType + kFieldFieldTypeSize; |
| 7551 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7552 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7553 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7554 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7555 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 7556 | }; |
| 7557 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7558 | // Implement the move-exception DEX instruction. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7559 | class HLoadException final : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7560 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7561 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7562 | : HExpression(kLoadException, DataType::Type::kReference, SideEffects::None(), dex_pc) { |
| 7563 | } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7564 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7565 | bool CanBeNull() const override { return false; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 7566 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7567 | DECLARE_INSTRUCTION(LoadException); |
| 7568 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7569 | protected: |
| 7570 | DEFAULT_COPY_CONSTRUCTOR(LoadException); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7571 | }; |
| 7572 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7573 | // Implicit part of move-exception which clears thread-local exception storage. |
| 7574 | // 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] | 7575 | class HClearException final : public HExpression<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7576 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7577 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7578 | : HExpression(kClearException, SideEffects::AllWrites(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7579 | } |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7580 | |
| 7581 | DECLARE_INSTRUCTION(ClearException); |
| 7582 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7583 | protected: |
| 7584 | DEFAULT_COPY_CONSTRUCTOR(ClearException); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7585 | }; |
| 7586 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7587 | class HThrow final : public HExpression<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7588 | public: |
| 7589 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7590 | : HExpression(kThrow, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7591 | SetRawInputAt(0, exception); |
| 7592 | } |
| 7593 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7594 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7595 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7596 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7597 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7598 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7599 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7600 | bool AlwaysThrows() const override { return true; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 7601 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7602 | DECLARE_INSTRUCTION(Throw); |
| 7603 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7604 | protected: |
| 7605 | DEFAULT_COPY_CONSTRUCTOR(Throw); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7606 | }; |
| 7607 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7608 | /** |
| 7609 | * Implementation strategies for the code generator of a HInstanceOf |
| 7610 | * or `HCheckCast`. |
| 7611 | */ |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 7612 | 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] | 7613 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7614 | kExactCheck, // Can do a single class compare. |
| 7615 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 7616 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 7617 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 7618 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7619 | kArrayCheck, // No optimization yet when checking against a generic array. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7620 | kBitstringCheck, // Compare the type check bitstring. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7621 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7622 | }; |
| 7623 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 7624 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 7625 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7626 | // Note: HTypeCheckInstruction is just a helper class, not an abstract instruction with an |
| 7627 | // `IsTypeCheckInstruction()`. (New virtual methods in the HInstruction class have a high cost.) |
| 7628 | class HTypeCheckInstruction : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7629 | public: |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7630 | HTypeCheckInstruction(InstructionKind kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7631 | DataType::Type type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7632 | HInstruction* object, |
| 7633 | HInstruction* target_class_or_null, |
| 7634 | TypeCheckKind check_kind, |
| 7635 | Handle<mirror::Class> klass, |
| 7636 | uint32_t dex_pc, |
| 7637 | ArenaAllocator* allocator, |
| 7638 | HIntConstant* bitstring_path_to_root, |
| 7639 | HIntConstant* bitstring_mask, |
| 7640 | SideEffects side_effects) |
| 7641 | : HVariableInputSizeInstruction( |
| 7642 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7643 | type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7644 | side_effects, |
| 7645 | dex_pc, |
| 7646 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7647 | /* number_of_inputs= */ check_kind == TypeCheckKind::kBitstringCheck ? 4u : 2u, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7648 | kArenaAllocTypeCheckInputs), |
| 7649 | klass_(klass) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7650 | SetPackedField<TypeCheckKindField>(check_kind); |
| 7651 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7652 | SetPackedFlag<kFlagValidTargetClassRTI>(false); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7653 | SetRawInputAt(0, object); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7654 | SetRawInputAt(1, target_class_or_null); |
| 7655 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_path_to_root != nullptr); |
| 7656 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_mask != nullptr); |
| 7657 | if (check_kind == TypeCheckKind::kBitstringCheck) { |
| 7658 | DCHECK(target_class_or_null->IsNullConstant()); |
| 7659 | SetRawInputAt(2, bitstring_path_to_root); |
| 7660 | SetRawInputAt(3, bitstring_mask); |
| 7661 | } else { |
| 7662 | DCHECK(target_class_or_null->IsLoadClass()); |
| 7663 | } |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7664 | } |
| 7665 | |
| 7666 | HLoadClass* GetTargetClass() const { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7667 | DCHECK_NE(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7668 | HInstruction* load_class = InputAt(1); |
| 7669 | DCHECK(load_class->IsLoadClass()); |
| 7670 | return load_class->AsLoadClass(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7671 | } |
| 7672 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7673 | uint32_t GetBitstringPathToRoot() const { |
| 7674 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7675 | HInstruction* path_to_root = InputAt(2); |
| 7676 | DCHECK(path_to_root->IsIntConstant()); |
| 7677 | return static_cast<uint32_t>(path_to_root->AsIntConstant()->GetValue()); |
| 7678 | } |
| 7679 | |
| 7680 | uint32_t GetBitstringMask() const { |
| 7681 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7682 | HInstruction* mask = InputAt(3); |
| 7683 | DCHECK(mask->IsIntConstant()); |
| 7684 | return static_cast<uint32_t>(mask->AsIntConstant()->GetValue()); |
| 7685 | } |
| 7686 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7687 | bool IsClonable() const override { return true; } |
| 7688 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7689 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7690 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7691 | DCHECK(other->IsInstanceOf() || other->IsCheckCast()) << other->DebugName(); |
| 7692 | return GetPackedFields() == down_cast<const HTypeCheckInstruction*>(other)->GetPackedFields(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7693 | } |
| 7694 | |
Andreas Gampe | 3fbd3ad | 2018-03-26 21:14:46 +0000 | [diff] [blame] | 7695 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 7696 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 7697 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 7698 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
| 7699 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7700 | ReferenceTypeInfo GetTargetClassRTI() { |
| 7701 | if (GetPackedFlag<kFlagValidTargetClassRTI>()) { |
| 7702 | // 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] | 7703 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact= */ true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7704 | } else { |
| 7705 | return ReferenceTypeInfo::CreateInvalid(); |
| 7706 | } |
| 7707 | } |
| 7708 | |
| 7709 | // 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] | 7710 | void SetValidTargetClassRTI() { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7711 | DCHECK(klass_ != nullptr); |
| 7712 | SetPackedFlag<kFlagValidTargetClassRTI>(true); |
| 7713 | } |
| 7714 | |
| 7715 | Handle<mirror::Class> GetClass() const { |
| 7716 | return klass_; |
| 7717 | } |
| 7718 | |
| 7719 | protected: |
| 7720 | DEFAULT_COPY_CONSTRUCTOR(TypeCheckInstruction); |
| 7721 | |
| 7722 | private: |
| 7723 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 7724 | static constexpr size_t kFieldTypeCheckKindSize = |
| 7725 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 7726 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 7727 | static constexpr size_t kFlagValidTargetClassRTI = kFlagMustDoNullCheck + 1; |
| 7728 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagValidTargetClassRTI + 1; |
| 7729 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7730 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
| 7731 | |
| 7732 | Handle<mirror::Class> klass_; |
| 7733 | }; |
| 7734 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7735 | class HInstanceOf final : public HTypeCheckInstruction { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7736 | public: |
| 7737 | HInstanceOf(HInstruction* object, |
| 7738 | HInstruction* target_class_or_null, |
| 7739 | TypeCheckKind check_kind, |
| 7740 | Handle<mirror::Class> klass, |
| 7741 | uint32_t dex_pc, |
| 7742 | ArenaAllocator* allocator, |
| 7743 | HIntConstant* bitstring_path_to_root, |
| 7744 | HIntConstant* bitstring_mask) |
| 7745 | : HTypeCheckInstruction(kInstanceOf, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7746 | DataType::Type::kBool, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7747 | object, |
| 7748 | target_class_or_null, |
| 7749 | check_kind, |
| 7750 | klass, |
| 7751 | dex_pc, |
| 7752 | allocator, |
| 7753 | bitstring_path_to_root, |
| 7754 | bitstring_mask, |
| 7755 | SideEffectsForArchRuntimeCalls(check_kind)) {} |
| 7756 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7757 | bool IsClonable() const override { return true; } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 7758 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7759 | bool NeedsEnvironment() const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7760 | return CanCallRuntime(GetTypeCheckKind()); |
| 7761 | } |
| 7762 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7763 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
Vladimir Marko | 54f4fbd | 2020-02-12 10:52:22 +0000 | [diff] [blame] | 7764 | // TODO: Re-evaluate now that mips codegen has been removed. |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7765 | return check_kind != TypeCheckKind::kExactCheck; |
| 7766 | } |
| 7767 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7768 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7769 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7770 | } |
| 7771 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7772 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7773 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7774 | protected: |
| 7775 | DEFAULT_COPY_CONSTRUCTOR(InstanceOf); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7776 | }; |
| 7777 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7778 | class HBoundType final : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7779 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 7780 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7781 | : HExpression(kBoundType, DataType::Type::kReference, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7782 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 7783 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 7784 | SetPackedFlag<kFlagCanBeNull>(true); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7785 | DCHECK_EQ(input->GetType(), DataType::Type::kReference); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7786 | SetRawInputAt(0, input); |
| 7787 | } |
| 7788 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7789 | bool InstructionDataEquals(const HInstruction* other) const override; |
| 7790 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7791 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7792 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7793 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7794 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7795 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7796 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7797 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7798 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 7799 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7800 | } |
| 7801 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7802 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7803 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7804 | DECLARE_INSTRUCTION(BoundType); |
| 7805 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7806 | protected: |
| 7807 | DEFAULT_COPY_CONSTRUCTOR(BoundType); |
| 7808 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7809 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7810 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 7811 | // is false then CanBeNull() cannot be true). |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7812 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7813 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 7814 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 7815 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7816 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7817 | // 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] | 7818 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 7819 | // It is used to bound the type in cases like: |
| 7820 | // if (x instanceof ClassX) { |
| 7821 | // // uper_bound_ will be ClassX |
| 7822 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7823 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7824 | }; |
| 7825 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7826 | class HCheckCast final : public HTypeCheckInstruction { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7827 | public: |
| 7828 | HCheckCast(HInstruction* object, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7829 | HInstruction* target_class_or_null, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7830 | TypeCheckKind check_kind, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7831 | Handle<mirror::Class> klass, |
| 7832 | uint32_t dex_pc, |
| 7833 | ArenaAllocator* allocator, |
| 7834 | HIntConstant* bitstring_path_to_root, |
| 7835 | HIntConstant* bitstring_mask) |
| 7836 | : HTypeCheckInstruction(kCheckCast, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7837 | DataType::Type::kVoid, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7838 | object, |
| 7839 | target_class_or_null, |
| 7840 | check_kind, |
| 7841 | klass, |
| 7842 | dex_pc, |
| 7843 | allocator, |
| 7844 | bitstring_path_to_root, |
| 7845 | bitstring_mask, |
| 7846 | SideEffects::CanTriggerGC()) {} |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7847 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7848 | bool IsClonable() const override { return true; } |
| 7849 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7850 | // Instruction may throw a CheckCastError. |
| 7851 | return true; |
| 7852 | } |
| 7853 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7854 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7855 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7856 | DECLARE_INSTRUCTION(CheckCast); |
| 7857 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7858 | protected: |
| 7859 | DEFAULT_COPY_CONSTRUCTOR(CheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7860 | }; |
| 7861 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 7862 | /** |
| 7863 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 7864 | * @details We define the combined barrier types that are actually required |
| 7865 | * by the Java Memory Model, rather than using exactly the terminology from |
| 7866 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 7867 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 7868 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 7869 | * The current recipe is as follows: |
| 7870 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 7871 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 7872 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 7873 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 7874 | * class has final fields. |
| 7875 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 7876 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 7877 | */ |
| 7878 | enum MemBarrierKind { |
| 7879 | kAnyStore, |
| 7880 | kLoadAny, |
| 7881 | kStoreStore, |
| 7882 | kAnyAny, |
| 7883 | kNTStoreStore, |
| 7884 | kLastBarrierKind = kNTStoreStore |
| 7885 | }; |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 7886 | std::ostream& operator<<(std::ostream& os, MemBarrierKind kind); |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 7887 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7888 | class HMemoryBarrier final : public HExpression<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7889 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7890 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7891 | : HExpression(kMemoryBarrier, |
| 7892 | SideEffects::AllWritesAndReads(), // Assume write/read on all fields/arrays. |
| 7893 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7894 | SetPackedField<BarrierKindField>(barrier_kind); |
| 7895 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7896 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7897 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7898 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7899 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7900 | |
| 7901 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 7902 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7903 | protected: |
| 7904 | DEFAULT_COPY_CONSTRUCTOR(MemoryBarrier); |
| 7905 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7906 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7907 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 7908 | static constexpr size_t kFieldBarrierKindSize = |
| 7909 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 7910 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 7911 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 7912 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 7913 | "Too many packed fields."); |
| 7914 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7915 | }; |
| 7916 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7917 | // A constructor fence orders all prior stores to fields that could be accessed via a final field of |
| 7918 | // the specified object(s), with respect to any subsequent store that might "publish" |
| 7919 | // (i.e. make visible) the specified object to another thread. |
| 7920 | // |
| 7921 | // JLS 17.5.1 "Semantics of final fields" states that a freeze action happens |
| 7922 | // for all final fields (that were set) at the end of the invoked constructor. |
| 7923 | // |
| 7924 | // The constructor fence models the freeze actions for the final fields of an object |
| 7925 | // being constructed (semantically at the end of the constructor). Constructor fences |
| 7926 | // have a per-object affinity; two separate objects being constructed get two separate |
| 7927 | // constructor fences. |
| 7928 | // |
| 7929 | // (Note: that if calling a super-constructor or forwarding to another constructor, |
| 7930 | // the freezes would happen at the end of *that* constructor being invoked). |
| 7931 | // |
| 7932 | // The memory model guarantees that when the object being constructed is "published" after |
| 7933 | // constructor completion (i.e. escapes the current thread via a store), then any final field |
| 7934 | // writes must be observable on other threads (once they observe that publication). |
| 7935 | // |
| 7936 | // Further, anything written before the freeze, and read by dereferencing through the final field, |
| 7937 | // must also be visible (so final object field could itself have an object with non-final fields; |
| 7938 | // yet the freeze must also extend to them). |
| 7939 | // |
| 7940 | // Constructor example: |
| 7941 | // |
| 7942 | // class HasFinal { |
| 7943 | // final int field; Optimizing IR for <init>()V: |
| 7944 | // HasFinal() { |
| 7945 | // field = 123; HInstanceFieldSet(this, HasFinal.field, 123) |
| 7946 | // // freeze(this.field); HConstructorFence(this) |
| 7947 | // } HReturn |
| 7948 | // } |
| 7949 | // |
| 7950 | // HConstructorFence can serve double duty as a fence for new-instance/new-array allocations of |
| 7951 | // already-initialized classes; in that case the allocation must act as a "default-initializer" |
| 7952 | // of the object which effectively writes the class pointer "final field". |
| 7953 | // |
| 7954 | // For example, we can model default-initialiation as roughly the equivalent of the following: |
| 7955 | // |
| 7956 | // class Object { |
| 7957 | // private final Class header; |
| 7958 | // } |
| 7959 | // |
| 7960 | // Java code: Optimizing IR: |
| 7961 | // |
| 7962 | // T new_instance<T>() { |
| 7963 | // Object obj = allocate_memory(T.class.size); obj = HInvoke(art_quick_alloc_object, T) |
| 7964 | // obj.header = T.class; // header write is done by above call. |
| 7965 | // // freeze(obj.header) HConstructorFence(obj) |
| 7966 | // return (T)obj; |
| 7967 | // } |
| 7968 | // |
| 7969 | // See also: |
Vladimir Marko | c1c3452 | 2018-10-31 13:56:49 +0000 | [diff] [blame] | 7970 | // * DexCompilationUnit::RequiresConstructorBarrier |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7971 | // * QuasiAtomic::ThreadFenceForConstructor |
| 7972 | // |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7973 | class HConstructorFence final : public HVariableInputSizeInstruction { |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7974 | // A fence has variable inputs because the inputs can be removed |
| 7975 | // after prepare_for_register_allocation phase. |
| 7976 | // (TODO: In the future a fence could freeze multiple objects |
| 7977 | // after merging two fences together.) |
| 7978 | public: |
| 7979 | // `fence_object` is the reference that needs to be protected for correct publication. |
| 7980 | // |
| 7981 | // It makes sense in the following situations: |
| 7982 | // * <init> constructors, it's the "this" parameter (i.e. HParameterValue, s.t. IsThis() == true). |
| 7983 | // * new-instance-like instructions, it's the return value (i.e. HNewInstance). |
| 7984 | // |
| 7985 | // After construction the `fence_object` becomes the 0th input. |
| 7986 | // This is not an input in a real sense, but just a convenient place to stash the information |
| 7987 | // about the associated object. |
| 7988 | HConstructorFence(HInstruction* fence_object, |
| 7989 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7990 | ArenaAllocator* allocator) |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7991 | // We strongly suspect there is not a more accurate way to describe the fine-grained reordering |
| 7992 | // constraints described in the class header. We claim that these SideEffects constraints |
| 7993 | // enforce a superset of the real constraints. |
| 7994 | // |
| 7995 | // The ordering described above is conservatively modeled with SideEffects as follows: |
| 7996 | // |
| 7997 | // * To prevent reordering of the publication stores: |
| 7998 | // ----> "Reads of objects" is the initial SideEffect. |
| 7999 | // * For every primitive final field store in the constructor: |
| 8000 | // ----> Union that field's type as a read (e.g. "Read of T") into the SideEffect. |
| 8001 | // * If there are any stores to reference final fields in the constructor: |
| 8002 | // ----> Use a more conservative "AllReads" SideEffect because any stores to any references |
| 8003 | // that are reachable from `fence_object` also need to be prevented for reordering |
| 8004 | // (and we do not want to do alias analysis to figure out what those stores are). |
| 8005 | // |
| 8006 | // In the implementation, this initially starts out as an "all reads" side effect; this is an |
| 8007 | // even more conservative approach than the one described above, and prevents all of the |
| 8008 | // above reordering without analyzing any of the instructions in the constructor. |
| 8009 | // |
| 8010 | // If in a later phase we discover that there are no writes to reference final fields, |
| 8011 | // 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] | 8012 | : HVariableInputSizeInstruction(kConstructorFence, |
| 8013 | SideEffects::AllReads(), |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8014 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 8015 | allocator, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8016 | /* number_of_inputs= */ 1, |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8017 | kArenaAllocConstructorFenceInputs) { |
| 8018 | DCHECK(fence_object != nullptr); |
| 8019 | SetRawInputAt(0, fence_object); |
| 8020 | } |
| 8021 | |
| 8022 | // The object associated with this constructor fence. |
| 8023 | // |
| 8024 | // (Note: This will be null after the prepare_for_register_allocation phase, |
| 8025 | // as all constructor fence inputs are removed there). |
| 8026 | HInstruction* GetFenceObject() const { |
| 8027 | return InputAt(0); |
| 8028 | } |
| 8029 | |
| 8030 | // Find all the HConstructorFence uses (`fence_use`) for `this` and: |
| 8031 | // - Delete `fence_use` from `this`'s use list. |
| 8032 | // - Delete `this` from `fence_use`'s inputs list. |
| 8033 | // - If the `fence_use` is dead, remove it from the graph. |
| 8034 | // |
| 8035 | // A fence is considered dead once it no longer has any uses |
| 8036 | // and all of the inputs are dead. |
| 8037 | // |
| 8038 | // This must *not* be called during/after prepare_for_register_allocation, |
| 8039 | // because that removes all the inputs to the fences but the fence is actually |
| 8040 | // still considered live. |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8041 | // |
| 8042 | // Returns how many HConstructorFence instructions were removed from graph. |
| 8043 | static size_t RemoveConstructorFences(HInstruction* instruction); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8044 | |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 8045 | // Combine all inputs of `this` and `other` instruction and remove |
| 8046 | // `other` from the graph. |
| 8047 | // |
| 8048 | // Inputs are unique after the merge. |
| 8049 | // |
| 8050 | // Requirement: `this` must not be the same as `other. |
| 8051 | void Merge(HConstructorFence* other); |
| 8052 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 8053 | // Check if this constructor fence is protecting |
| 8054 | // an HNewInstance or HNewArray that is also the immediate |
| 8055 | // predecessor of `this`. |
| 8056 | // |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 8057 | // If `ignore_inputs` is true, then the immediate predecessor doesn't need |
| 8058 | // to be one of the inputs of `this`. |
| 8059 | // |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 8060 | // Returns the associated HNewArray or HNewInstance, |
| 8061 | // or null otherwise. |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 8062 | HInstruction* GetAssociatedAllocation(bool ignore_inputs = false); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 8063 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8064 | DECLARE_INSTRUCTION(ConstructorFence); |
| 8065 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8066 | protected: |
| 8067 | DEFAULT_COPY_CONSTRUCTOR(ConstructorFence); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 8068 | }; |
| 8069 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8070 | class HMonitorOperation final : public HExpression<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8071 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8072 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8073 | kEnter, |
| 8074 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8075 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8076 | }; |
| 8077 | |
| 8078 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 8079 | : HExpression(kMonitorOperation, |
| 8080 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 8081 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8082 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8083 | SetRawInputAt(0, object); |
| 8084 | } |
| 8085 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 8086 | // Instruction may go into runtime, so we need an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8087 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 8088 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8089 | bool CanThrow() const override { |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 8090 | // Verifier guarantees that monitor-exit cannot throw. |
| 8091 | // This is important because it allows the HGraphBuilder to remove |
| 8092 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 8093 | return IsEnter(); |
| 8094 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8095 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8096 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 8097 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8098 | |
| 8099 | DECLARE_INSTRUCTION(MonitorOperation); |
| 8100 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8101 | protected: |
| 8102 | DEFAULT_COPY_CONSTRUCTOR(MonitorOperation); |
| 8103 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 8104 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8105 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 8106 | static constexpr size_t kFieldOperationKindSize = |
| 8107 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 8108 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 8109 | kFieldOperationKind + kFieldOperationKindSize; |
| 8110 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 8111 | "Too many packed fields."); |
| 8112 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8113 | }; |
| 8114 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8115 | class HSelect final : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8116 | public: |
| 8117 | HSelect(HInstruction* condition, |
| 8118 | HInstruction* true_value, |
| 8119 | HInstruction* false_value, |
| 8120 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 8121 | : HExpression(kSelect, HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8122 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 8123 | |
| 8124 | // First input must be `true_value` or `false_value` to allow codegens to |
| 8125 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 8126 | // that architectures which implement HSelect as a conditional move also |
| 8127 | // will not need to invert the condition. |
| 8128 | SetRawInputAt(0, false_value); |
| 8129 | SetRawInputAt(1, true_value); |
| 8130 | SetRawInputAt(2, condition); |
| 8131 | } |
| 8132 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8133 | bool IsClonable() const override { return true; } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8134 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 8135 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 8136 | HInstruction* GetCondition() const { return InputAt(2); } |
| 8137 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8138 | bool CanBeMoved() const override { return true; } |
| 8139 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 8140 | return true; |
| 8141 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8142 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8143 | bool CanBeNull() const override { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8144 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 8145 | } |
| 8146 | |
| 8147 | DECLARE_INSTRUCTION(Select); |
| 8148 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8149 | protected: |
| 8150 | DEFAULT_COPY_CONSTRUCTOR(Select); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 8151 | }; |
| 8152 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 8153 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8154 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8155 | MoveOperands(Location source, |
| 8156 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8157 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8158 | HInstruction* instruction) |
| 8159 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8160 | |
| 8161 | Location GetSource() const { return source_; } |
| 8162 | Location GetDestination() const { return destination_; } |
| 8163 | |
| 8164 | void SetSource(Location value) { source_ = value; } |
| 8165 | void SetDestination(Location value) { destination_ = value; } |
| 8166 | |
| 8167 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 8168 | // destination (but not the source). |
| 8169 | Location MarkPending() { |
| 8170 | DCHECK(!IsPending()); |
| 8171 | Location dest = destination_; |
| 8172 | destination_ = Location::NoLocation(); |
| 8173 | return dest; |
| 8174 | } |
| 8175 | |
| 8176 | void ClearPending(Location dest) { |
| 8177 | DCHECK(IsPending()); |
| 8178 | destination_ = dest; |
| 8179 | } |
| 8180 | |
| 8181 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8182 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 8183 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8184 | } |
| 8185 | |
| 8186 | // True if this blocks a move from the given location. |
| 8187 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 8188 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8189 | } |
| 8190 | |
| 8191 | // A move is redundant if it's been eliminated, if its source and |
| 8192 | // destination are the same, or if its destination is unneeded. |
| 8193 | bool IsRedundant() const { |
| 8194 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 8195 | } |
| 8196 | |
| 8197 | // We clear both operands to indicate move that's been eliminated. |
| 8198 | void Eliminate() { |
| 8199 | source_ = destination_ = Location::NoLocation(); |
| 8200 | } |
| 8201 | |
| 8202 | bool IsEliminated() const { |
| 8203 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 8204 | return source_.IsInvalid(); |
| 8205 | } |
| 8206 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8207 | DataType::Type GetType() const { return type_; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 8208 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8209 | bool Is64BitMove() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8210 | return DataType::Is64BitType(type_); |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8211 | } |
| 8212 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 8213 | HInstruction* GetInstruction() const { return instruction_; } |
| 8214 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8215 | private: |
| 8216 | Location source_; |
| 8217 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8218 | // The type this move is for. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8219 | DataType::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 8220 | // The instruction this move is assocatied with. Null when this move is |
| 8221 | // for moving an input in the expected locations of user (including a phi user). |
| 8222 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 8223 | // in the same parallel move. |
| 8224 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8225 | }; |
| 8226 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8227 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 8228 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8229 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 8230 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8231 | class HParallelMove final : public HExpression<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8232 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 8233 | explicit HParallelMove(ArenaAllocator* allocator, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 8234 | : HExpression(kParallelMove, SideEffects::None(), dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 8235 | moves_(allocator->Adapter(kArenaAllocMoveOperands)) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8236 | moves_.reserve(kDefaultNumberOfMoves); |
| 8237 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8238 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8239 | void AddMove(Location source, |
| 8240 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8241 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 8242 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 8243 | DCHECK(source.IsValid()); |
| 8244 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 8245 | if (kIsDebugBuild) { |
| 8246 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8247 | for (const MoveOperands& move : moves_) { |
| 8248 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8249 | // Special case the situation where the move is for the spill slot |
| 8250 | // of the instruction. |
| 8251 | if ((GetPrevious() == instruction) |
| 8252 | || ((GetPrevious() == nullptr) |
| 8253 | && instruction->IsPhi() |
| 8254 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8255 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8256 | << "Doing parallel moves for the same instruction."; |
| 8257 | } else { |
| 8258 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 8259 | } |
| 8260 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 8261 | } |
| 8262 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8263 | for (const MoveOperands& move : moves_) { |
| 8264 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 8265 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8266 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Alex Light | a7c66e7 | 2021-01-27 11:41:58 -0800 | [diff] [blame] | 8267 | << source << " ==> " << destination << " for " << SafePrint(instruction); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 8268 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 8269 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8270 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8271 | } |
| 8272 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8273 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8274 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8275 | } |
| 8276 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8277 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8278 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 8279 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8280 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8281 | protected: |
| 8282 | DEFAULT_COPY_CONSTRUCTOR(ParallelMove); |
| 8283 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8284 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 8285 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 8286 | }; |
| 8287 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8288 | // This instruction computes an intermediate address pointing in the 'middle' of an object. The |
| 8289 | // result pointer cannot be handled by GC, so extra care is taken to make sure that this value is |
| 8290 | // never used across anything that can trigger GC. |
| 8291 | // The result of this instruction is not a pointer in the sense of `DataType::Type::kreference`. |
| 8292 | // So we represent it by the type `DataType::Type::kInt`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8293 | class HIntermediateAddress final : public HExpression<2> { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8294 | public: |
| 8295 | HIntermediateAddress(HInstruction* base_address, HInstruction* offset, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 8296 | : HExpression(kIntermediateAddress, |
| 8297 | DataType::Type::kInt32, |
| 8298 | SideEffects::DependsOnGC(), |
| 8299 | dex_pc) { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8300 | DCHECK_EQ(DataType::Size(DataType::Type::kInt32), |
| 8301 | DataType::Size(DataType::Type::kReference)) |
| 8302 | << "kPrimInt and kPrimNot have different sizes."; |
| 8303 | SetRawInputAt(0, base_address); |
| 8304 | SetRawInputAt(1, offset); |
| 8305 | } |
| 8306 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8307 | bool IsClonable() const override { return true; } |
| 8308 | bool CanBeMoved() const override { return true; } |
| 8309 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8310 | return true; |
| 8311 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8312 | bool IsActualObject() const override { return false; } |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8313 | |
| 8314 | HInstruction* GetBaseAddress() const { return InputAt(0); } |
| 8315 | HInstruction* GetOffset() const { return InputAt(1); } |
| 8316 | |
| 8317 | DECLARE_INSTRUCTION(IntermediateAddress); |
| 8318 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8319 | protected: |
| 8320 | DEFAULT_COPY_CONSTRUCTOR(IntermediateAddress); |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8321 | }; |
| 8322 | |
| 8323 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8324 | } // namespace art |
| 8325 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 8326 | #include "nodes_vector.h" |
| 8327 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 8328 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 8329 | #include "nodes_shared.h" |
| 8330 | #endif |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 8331 | #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64) |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8332 | #include "nodes_x86.h" |
| 8333 | #endif |
| 8334 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 8335 | namespace art { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8336 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8337 | class OptimizingCompilerStats; |
| 8338 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8339 | class HGraphVisitor : public ValueObject { |
| 8340 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8341 | explicit HGraphVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 8342 | : stats_(stats), |
| 8343 | graph_(graph) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 8344 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8345 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8346 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8347 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 8348 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 8349 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8350 | void VisitInsertionOrder(); |
| 8351 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 8352 | // Visit the graph following dominator tree reverse post-order. |
| 8353 | void VisitReversePostOrder(); |
| 8354 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 8355 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8356 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8357 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8358 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8359 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 8360 | |
| 8361 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 8362 | |
| 8363 | #undef DECLARE_VISIT_INSTRUCTION |
| 8364 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8365 | protected: |
| 8366 | OptimizingCompilerStats* stats_; |
| 8367 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8368 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 8369 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8370 | |
| 8371 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 8372 | }; |
| 8373 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8374 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 8375 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 8376 | explicit HGraphDelegateVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 8377 | : HGraphVisitor(graph, stats) {} |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8378 | virtual ~HGraphDelegateVisitor() {} |
| 8379 | |
| 8380 | // Visit functions that delegate to to super class. |
| 8381 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8382 | void Visit##name(H##name* instr) override { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 8383 | |
| 8384 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 8385 | |
| 8386 | #undef DECLARE_VISIT_INSTRUCTION |
| 8387 | |
| 8388 | private: |
| 8389 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 8390 | }; |
| 8391 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8392 | // Create a clone of the instruction, insert it into the graph; replace the old one with a new |
| 8393 | // and remove the old instruction. |
| 8394 | HInstruction* ReplaceInstrOrPhiByClone(HInstruction* instr); |
| 8395 | |
| 8396 | // Create a clone for each clonable instructions/phis and replace the original with the clone. |
| 8397 | // |
| 8398 | // Used for testing individual instruction cloner. |
| 8399 | class CloneAndReplaceInstructionVisitor : public HGraphDelegateVisitor { |
| 8400 | public: |
| 8401 | explicit CloneAndReplaceInstructionVisitor(HGraph* graph) |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8402 | : HGraphDelegateVisitor(graph), instr_replaced_by_clones_count_(0) {} |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8403 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8404 | void VisitInstruction(HInstruction* instruction) override { |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8405 | if (instruction->IsClonable()) { |
| 8406 | ReplaceInstrOrPhiByClone(instruction); |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8407 | instr_replaced_by_clones_count_++; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8408 | } |
| 8409 | } |
| 8410 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8411 | size_t GetInstrReplacedByClonesCount() const { return instr_replaced_by_clones_count_; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8412 | |
| 8413 | private: |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 8414 | size_t instr_replaced_by_clones_count_; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 8415 | |
| 8416 | DISALLOW_COPY_AND_ASSIGN(CloneAndReplaceInstructionVisitor); |
| 8417 | }; |
| 8418 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8419 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 8420 | // of an inner loop. The order in which the blocks are iterated is on their |
| 8421 | // block id. |
| 8422 | class HBlocksInLoopIterator : public ValueObject { |
| 8423 | public: |
| 8424 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 8425 | : blocks_in_loop_(info.GetBlocks()), |
| 8426 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 8427 | index_(0) { |
| 8428 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 8429 | Advance(); |
| 8430 | } |
| 8431 | } |
| 8432 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8433 | bool Done() const { return index_ == blocks_.size(); } |
| 8434 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8435 | void Advance() { |
| 8436 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8437 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8438 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 8439 | break; |
| 8440 | } |
| 8441 | } |
| 8442 | } |
| 8443 | |
| 8444 | private: |
| 8445 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8446 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 8447 | size_t index_; |
| 8448 | |
| 8449 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 8450 | }; |
| 8451 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8452 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 8453 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 8454 | // post order. |
| 8455 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 8456 | public: |
| 8457 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 8458 | : blocks_in_loop_(info.GetBlocks()), |
| 8459 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 8460 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8461 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8462 | Advance(); |
| 8463 | } |
| 8464 | } |
| 8465 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8466 | bool Done() const { return index_ == blocks_.size(); } |
| 8467 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8468 | void Advance() { |
| 8469 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8470 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 8471 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8472 | break; |
| 8473 | } |
| 8474 | } |
| 8475 | } |
| 8476 | |
| 8477 | private: |
| 8478 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 8479 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 8480 | size_t index_; |
| 8481 | |
| 8482 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 8483 | }; |
| 8484 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 8485 | // Returns int64_t value of a properly typed constant. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 8486 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 8487 | if (constant->IsIntConstant()) { |
| 8488 | return constant->AsIntConstant()->GetValue(); |
| 8489 | } else if (constant->IsLongConstant()) { |
| 8490 | return constant->AsLongConstant()->GetValue(); |
| 8491 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 8492 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 8493 | return 0; |
| 8494 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 8495 | } |
| 8496 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 8497 | // Returns true iff instruction is an integral constant (and sets value on success). |
| 8498 | inline bool IsInt64AndGet(HInstruction* instruction, /*out*/ int64_t* value) { |
| 8499 | if (instruction->IsIntConstant()) { |
| 8500 | *value = instruction->AsIntConstant()->GetValue(); |
| 8501 | return true; |
| 8502 | } else if (instruction->IsLongConstant()) { |
| 8503 | *value = instruction->AsLongConstant()->GetValue(); |
| 8504 | return true; |
| 8505 | } else if (instruction->IsNullConstant()) { |
| 8506 | *value = 0; |
| 8507 | return true; |
| 8508 | } |
| 8509 | return false; |
| 8510 | } |
| 8511 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 8512 | // Returns true iff instruction is the given integral constant. |
| 8513 | inline bool IsInt64Value(HInstruction* instruction, int64_t value) { |
| 8514 | int64_t val = 0; |
| 8515 | return IsInt64AndGet(instruction, &val) && val == value; |
| 8516 | } |
| 8517 | |
| 8518 | // Returns true iff instruction is a zero bit pattern. |
| 8519 | inline bool IsZeroBitPattern(HInstruction* instruction) { |
| 8520 | return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern(); |
| 8521 | } |
| 8522 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 8523 | // Implement HInstruction::Is##type() for concrete instructions. |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8524 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8525 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } |
| 8526 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 8527 | #undef INSTRUCTION_TYPE_CHECK |
| 8528 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 8529 | // Implement HInstruction::Is##type() for abstract instructions. |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8530 | #define INSTRUCTION_TYPE_CHECK_RESULT(type, super) \ |
| 8531 | std::is_base_of<BaseType, H##type>::value, |
| 8532 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 8533 | inline bool HInstruction::Is##type() const { \ |
| 8534 | DCHECK_LT(GetKind(), kLastInstructionKind); \ |
| 8535 | using BaseType = H##type; \ |
| 8536 | static constexpr bool results[] = { \ |
| 8537 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK_RESULT) \ |
| 8538 | }; \ |
| 8539 | return results[static_cast<size_t>(GetKind())]; \ |
| 8540 | } |
| 8541 | |
| 8542 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 8543 | #undef INSTRUCTION_TYPE_CHECK |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 8544 | #undef INSTRUCTION_TYPE_CHECK_RESULT |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8545 | |
| 8546 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8547 | inline const H##type* HInstruction::As##type() const { \ |
| 8548 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 8549 | } \ |
| 8550 | inline H##type* HInstruction::As##type() { \ |
| 8551 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 8552 | } |
| 8553 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 8554 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 8555 | #undef INSTRUCTION_TYPE_CAST |
| 8556 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 8557 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 8558 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 8559 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 8560 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 8561 | size_t number_of_new_blocks, |
| 8562 | size_t after) { |
| 8563 | DCHECK_LT(after, blocks->size()); |
| 8564 | size_t old_size = blocks->size(); |
| 8565 | size_t new_size = old_size + number_of_new_blocks; |
| 8566 | blocks->resize(new_size); |
| 8567 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 8568 | } |
| 8569 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 8570 | /* |
| 8571 | * Hunt "under the hood" of array lengths (leading to array references), |
| 8572 | * null checks (also leading to array references), and new arrays |
| 8573 | * (leading to the actual length). This makes it more likely related |
| 8574 | * instructions become actually comparable. |
| 8575 | */ |
| 8576 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 8577 | while (instruction->IsArrayLength() || |
| 8578 | instruction->IsNullCheck() || |
| 8579 | instruction->IsNewArray()) { |
| 8580 | instruction = instruction->IsNewArray() |
| 8581 | ? instruction->AsNewArray()->GetLength() |
| 8582 | : instruction->InputAt(0); |
| 8583 | } |
| 8584 | return instruction; |
| 8585 | } |
| 8586 | |
Artem Serov | b47b978 | 2019-12-04 21:02:09 +0000 | [diff] [blame] | 8587 | inline bool IsAddOrSub(const HInstruction* instruction) { |
| 8588 | return instruction->IsAdd() || instruction->IsSub(); |
| 8589 | } |
| 8590 | |
Artem Serov | 21c7e6f | 2017-07-27 16:04:42 +0100 | [diff] [blame] | 8591 | void RemoveEnvironmentUses(HInstruction* instruction); |
| 8592 | bool HasEnvironmentUsedByOthers(HInstruction* instruction); |
| 8593 | void ResetEnvironmentInputRecords(HInstruction* instruction); |
| 8594 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 8595 | // Detects an instruction that is >= 0. As long as the value is carried by |
| 8596 | // a single instruction, arithmetic wrap-around cannot occur. |
| 8597 | bool IsGEZero(HInstruction* instruction); |
| 8598 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8599 | } // namespace art |
| 8600 | |
| 8601 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |