Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_NODES_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_NODES_H_ |
| 19 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 20 | #include <algorithm> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 21 | #include <array> |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 22 | #include <type_traits> |
| 23 | |
Mathieu Chartier | e5d80f8 | 2015-10-15 17:47:48 -0700 | [diff] [blame] | 24 | #include "base/arena_bit_vector.h" |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 25 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 26 | #include "base/arena_object.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 27 | #include "base/stl_util.h" |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 28 | #include "dex_file.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 29 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 30 | #include "handle.h" |
| 31 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 32 | #include "invoke_type.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 33 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 34 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 35 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 36 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 37 | #include "primitive.h" |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 38 | #include "utils/array_ref.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 39 | #include "utils/intrusive_forward_list.h" |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 40 | #include "utils/transform_array_ref.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 41 | |
| 42 | namespace art { |
| 43 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 44 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 45 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 46 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 47 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 48 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 49 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 50 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 51 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 52 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 53 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 54 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 55 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 56 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 57 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 58 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 59 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 60 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 61 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 62 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 63 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 64 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 65 | namespace mirror { |
| 66 | class DexCache; |
| 67 | } // namespace mirror |
| 68 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 69 | static const int kDefaultNumberOfBlocks = 8; |
| 70 | static const int kDefaultNumberOfSuccessors = 2; |
| 71 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 72 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 73 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 74 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 75 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 76 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 77 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 78 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 79 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 80 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 81 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 82 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 83 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 84 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 85 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 86 | static constexpr uint32_t kNoDexPc = -1; |
| 87 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 88 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 89 | // For the purposes of the compiler, the dex files must actually be the same object |
| 90 | // if we want to safely treat them as the same. This is especially important for JIT |
| 91 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 92 | // times and provide different class resolution but no two class loaders should ever |
| 93 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 94 | // all sorts of weird failures. |
| 95 | return &lhs == &rhs; |
| 96 | } |
| 97 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 98 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 99 | // All types. |
| 100 | kCondEQ, // == |
| 101 | kCondNE, // != |
| 102 | // Signed integers and floating-point numbers. |
| 103 | kCondLT, // < |
| 104 | kCondLE, // <= |
| 105 | kCondGT, // > |
| 106 | kCondGE, // >= |
| 107 | // Unsigned integers. |
| 108 | kCondB, // < |
| 109 | kCondBE, // <= |
| 110 | kCondA, // > |
| 111 | kCondAE, // >= |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 114 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 115 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 116 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 117 | kAnalysisFailThrowCatchLoop, |
| 118 | kAnalysisFailAmbiguousArrayOp, |
| 119 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 122 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 123 | public: |
| 124 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 125 | |
| 126 | void AddInstruction(HInstruction* instruction); |
| 127 | void RemoveInstruction(HInstruction* instruction); |
| 128 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 129 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 130 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 131 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 132 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 133 | // Return true if this list contains `instruction`. |
| 134 | bool Contains(HInstruction* instruction) const; |
| 135 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 136 | // Return true if `instruction1` is found before `instruction2` in |
| 137 | // this instruction list and false otherwise. Abort if none |
| 138 | // of these instructions is found. |
| 139 | bool FoundBefore(const HInstruction* instruction1, |
| 140 | const HInstruction* instruction2) const; |
| 141 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 142 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 143 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 144 | |
| 145 | // Update the block of all instructions to be `block`. |
| 146 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 147 | |
| 148 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 149 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 150 | void Add(const HInstructionList& instruction_list); |
| 151 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 152 | // Return the number of instructions in the list. This is an expensive operation. |
| 153 | size_t CountSize() const; |
| 154 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 155 | private: |
| 156 | HInstruction* first_instruction_; |
| 157 | HInstruction* last_instruction_; |
| 158 | |
| 159 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 160 | friend class HGraph; |
| 161 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 162 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 163 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 164 | |
| 165 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 166 | }; |
| 167 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 168 | class ReferenceTypeInfo : ValueObject { |
| 169 | public: |
| 170 | typedef Handle<mirror::Class> TypeHandle; |
| 171 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 172 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 173 | |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 174 | static ReferenceTypeInfo Create(TypeHandle type_handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 175 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 176 | } |
| 177 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 178 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 179 | return ReferenceTypeInfo(type_handle, is_exact); |
| 180 | } |
| 181 | |
| 182 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 183 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 184 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 185 | return handle.GetReference() != nullptr; |
| 186 | } |
| 187 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 188 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 189 | return IsValidHandle(type_handle_); |
| 190 | } |
| 191 | |
| 192 | bool IsExact() const { return is_exact_; } |
| 193 | |
| 194 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 195 | DCHECK(IsValid()); |
| 196 | return GetTypeHandle()->IsObjectClass(); |
| 197 | } |
| 198 | |
| 199 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 200 | DCHECK(IsValid()); |
| 201 | return GetTypeHandle()->IsStringClass(); |
| 202 | } |
| 203 | |
| 204 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 205 | DCHECK(IsValid()); |
| 206 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 207 | } |
| 208 | |
| 209 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 210 | DCHECK(IsValid()); |
| 211 | return GetTypeHandle()->IsInterface(); |
| 212 | } |
| 213 | |
| 214 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 215 | DCHECK(IsValid()); |
| 216 | return GetTypeHandle()->IsArrayClass(); |
| 217 | } |
| 218 | |
| 219 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 220 | DCHECK(IsValid()); |
| 221 | return GetTypeHandle()->IsPrimitiveArray(); |
| 222 | } |
| 223 | |
| 224 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 225 | DCHECK(IsValid()); |
| 226 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 227 | } |
| 228 | |
| 229 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 230 | DCHECK(IsValid()); |
| 231 | if (!IsExact()) return false; |
| 232 | if (!IsArrayClass()) return false; |
| 233 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 234 | } |
| 235 | |
| 236 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 237 | DCHECK(IsValid()); |
| 238 | if (!IsExact()) return false; |
| 239 | if (!IsArrayClass()) return false; |
| 240 | if (!rti.IsArrayClass()) return false; |
| 241 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 242 | rti.GetTypeHandle()->GetComponentType()); |
| 243 | } |
| 244 | |
| 245 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 246 | |
| 247 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 248 | DCHECK(IsValid()); |
| 249 | DCHECK(rti.IsValid()); |
| 250 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 251 | } |
| 252 | |
| 253 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 254 | DCHECK(IsValid()); |
| 255 | DCHECK(rti.IsValid()); |
| 256 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 257 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 258 | } |
| 259 | |
| 260 | // Returns true if the type information provide the same amount of details. |
| 261 | // Note that it does not mean that the instructions have the same actual type |
| 262 | // (because the type can be the result of a merge). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 263 | bool IsEqual(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 264 | if (!IsValid() && !rti.IsValid()) { |
| 265 | // Invalid types are equal. |
| 266 | return true; |
| 267 | } |
| 268 | if (!IsValid() || !rti.IsValid()) { |
| 269 | // One is valid, the other not. |
| 270 | return false; |
| 271 | } |
| 272 | return IsExact() == rti.IsExact() |
| 273 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 274 | } |
| 275 | |
| 276 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 277 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 278 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 279 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 280 | |
| 281 | // The class of the object. |
| 282 | TypeHandle type_handle_; |
| 283 | // Whether or not the type is exact or a superclass of the actual type. |
| 284 | // Whether or not we have any information about this type. |
| 285 | bool is_exact_; |
| 286 | }; |
| 287 | |
| 288 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 289 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 290 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 291 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 292 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 293 | HGraph(ArenaAllocator* arena, |
| 294 | const DexFile& dex_file, |
| 295 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 296 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 297 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 298 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 299 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 300 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 301 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 302 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 303 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 304 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 305 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 306 | entry_block_(nullptr), |
| 307 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 308 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 309 | number_of_vregs_(0), |
| 310 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 311 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 312 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 313 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 314 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 315 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 316 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 317 | dex_file_(dex_file), |
| 318 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 319 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 320 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 321 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 322 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 323 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 324 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 325 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 326 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 327 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 328 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 329 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
| 330 | osr_(osr) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 331 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 332 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 333 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 334 | // Acquires and stores RTI of inexact Object to be used when creating HNullConstant. |
| 335 | void InitializeInexactObjectRTI(StackHandleScopeCollection* handles); |
| 336 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 337 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 338 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 339 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 340 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 341 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 342 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 343 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 344 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 345 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 346 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 347 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 348 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 349 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 350 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 351 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 352 | void ComputeDominanceInformation(); |
| 353 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 354 | void ClearLoopInformation(); |
| 355 | void FindBackEdges(ArenaBitVector* visited); |
| 356 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 357 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 358 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 359 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 360 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 361 | // 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] | 362 | // 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] | 363 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 364 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 365 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 366 | // order and loop information. |
| 367 | void ComputeTryBlockInformation(); |
| 368 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 369 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 370 | // Returns the instruction to replace the invoke expression or null if the |
| 371 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 372 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 373 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 374 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 375 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 376 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 377 | // should be the new back edge. |
| 378 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 379 | HBasicBlock* reference, |
| 380 | bool replace_if_back_edge); |
| 381 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 382 | // Need to add a couple of blocks to test if the loop body is entered and |
| 383 | // put deoptimization instructions, etc. |
| 384 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 385 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 386 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 387 | // other blocks and has no instructions or phis. |
| 388 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 389 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 390 | // Splits the edge between `block` and `successor` while preserving the |
| 391 | // indices in the predecessor/successor lists. If there are multiple edges |
| 392 | // between the blocks, the lowest indices are used. |
| 393 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 394 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 395 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 396 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 397 | void SimplifyLoop(HBasicBlock* header); |
| 398 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 399 | int32_t GetNextInstructionId() { |
| 400 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 401 | return current_instruction_id_++; |
| 402 | } |
| 403 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 404 | int32_t GetCurrentInstructionId() const { |
| 405 | return current_instruction_id_; |
| 406 | } |
| 407 | |
| 408 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 409 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 410 | current_instruction_id_ = id; |
| 411 | } |
| 412 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 413 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 414 | return maximum_number_of_out_vregs_; |
| 415 | } |
| 416 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 417 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 418 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 419 | } |
| 420 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 421 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 422 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 423 | } |
| 424 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 425 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 426 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 427 | } |
| 428 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 429 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 430 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 431 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 434 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 435 | number_of_vregs_ = number_of_vregs; |
| 436 | } |
| 437 | |
| 438 | uint16_t GetNumberOfVRegs() const { |
| 439 | return number_of_vregs_; |
| 440 | } |
| 441 | |
| 442 | void SetNumberOfInVRegs(uint16_t value) { |
| 443 | number_of_in_vregs_ = value; |
| 444 | } |
| 445 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 446 | uint16_t GetNumberOfInVRegs() const { |
| 447 | return number_of_in_vregs_; |
| 448 | } |
| 449 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 450 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 451 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 452 | return number_of_vregs_ - number_of_in_vregs_; |
| 453 | } |
| 454 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 455 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 456 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 457 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 458 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 459 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 460 | return linear_order_; |
| 461 | } |
| 462 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 463 | bool HasBoundsChecks() const { |
| 464 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 465 | } |
| 466 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 467 | void SetHasBoundsChecks(bool value) { |
| 468 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 469 | } |
| 470 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 471 | bool ShouldGenerateConstructorBarrier() const { |
| 472 | return should_generate_constructor_barrier_; |
| 473 | } |
| 474 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 475 | bool IsDebuggable() const { return debuggable_; } |
| 476 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 477 | // 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] | 478 | // already, it is created and inserted into the graph. This method is only for |
| 479 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 480 | HConstant* GetConstant(Primitive::Type type, int64_t value, uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 481 | |
| 482 | // TODO: This is problematic for the consistency of reference type propagation |
| 483 | // because it can be created anytime after the pass and thus it will be left |
| 484 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 485 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 486 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 487 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 488 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 489 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 490 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 491 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 492 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 493 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 494 | 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] | 495 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 496 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 497 | 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] | 498 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 499 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 500 | HCurrentMethod* GetCurrentMethod(); |
| 501 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 502 | const DexFile& GetDexFile() const { |
| 503 | return dex_file_; |
| 504 | } |
| 505 | |
| 506 | uint32_t GetMethodIdx() const { |
| 507 | return method_idx_; |
| 508 | } |
| 509 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 510 | InvokeType GetInvokeType() const { |
| 511 | return invoke_type_; |
| 512 | } |
| 513 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 514 | InstructionSet GetInstructionSet() const { |
| 515 | return instruction_set_; |
| 516 | } |
| 517 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 518 | bool IsCompilingOsr() const { return osr_; } |
| 519 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 520 | bool HasTryCatch() const { return has_try_catch_; } |
| 521 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 522 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 523 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 524 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 525 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 526 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 527 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 528 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 529 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 530 | // The instruction has been inserted into the graph, either as a constant, or |
| 531 | // before cursor. |
| 532 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 533 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 534 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 535 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 536 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 537 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 538 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 539 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 540 | template <class InstructionType, typename ValueType> |
| 541 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 542 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 543 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 544 | // Try to find an existing constant of the given value. |
| 545 | InstructionType* constant = nullptr; |
| 546 | auto cached_constant = cache->find(value); |
| 547 | if (cached_constant != cache->end()) { |
| 548 | constant = cached_constant->second; |
| 549 | } |
| 550 | |
| 551 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 552 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 553 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 554 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 555 | cache->Overwrite(value, constant); |
| 556 | InsertConstant(constant); |
| 557 | } |
| 558 | return constant; |
| 559 | } |
| 560 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 561 | void InsertConstant(HConstant* instruction); |
| 562 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 563 | // Cache a float constant into the graph. This method should only be |
| 564 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 565 | void CacheFloatConstant(HFloatConstant* constant); |
| 566 | |
| 567 | // See CacheFloatConstant comment. |
| 568 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 569 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 570 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 571 | |
| 572 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 573 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 574 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 575 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 576 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 577 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 578 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 579 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 580 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 581 | HBasicBlock* entry_block_; |
| 582 | HBasicBlock* exit_block_; |
| 583 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 584 | // 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] | 585 | uint16_t maximum_number_of_out_vregs_; |
| 586 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 587 | // The number of virtual registers in this method. Contains the parameters. |
| 588 | uint16_t number_of_vregs_; |
| 589 | |
| 590 | // The number of virtual registers used by parameters of this method. |
| 591 | uint16_t number_of_in_vregs_; |
| 592 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 593 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 594 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 595 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 596 | // Has bounds checks. We can totally skip BCE if it's false. |
| 597 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 598 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 599 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 600 | // try/catch-related passes if false. |
| 601 | bool has_try_catch_; |
| 602 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 603 | // Flag whether there are any irreducible loops in the graph. |
| 604 | bool has_irreducible_loops_; |
| 605 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 606 | // Indicates whether the graph should be compiled in a way that |
| 607 | // ensures full debuggability. If false, we can apply more |
| 608 | // aggressive optimizations that may limit the level of debugging. |
| 609 | const bool debuggable_; |
| 610 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 611 | // 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] | 612 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 613 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 614 | // The dex file from which the method is from. |
| 615 | const DexFile& dex_file_; |
| 616 | |
| 617 | // The method index in the dex file. |
| 618 | const uint32_t method_idx_; |
| 619 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 620 | // If inlined, this encodes how the callee is being invoked. |
| 621 | const InvokeType invoke_type_; |
| 622 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 623 | // Whether the graph has been transformed to SSA form. Only used |
| 624 | // in debug mode to ensure we are not using properties only valid |
| 625 | // for non-SSA form (like the number of temporaries). |
| 626 | bool in_ssa_form_; |
| 627 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 628 | const bool should_generate_constructor_barrier_; |
| 629 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 630 | const InstructionSet instruction_set_; |
| 631 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 632 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 633 | HNullConstant* cached_null_constant_; |
| 634 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 635 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 636 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 637 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 638 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 639 | HCurrentMethod* cached_current_method_; |
| 640 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 641 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 642 | // for example for methods whose declaring class could not be resolved |
| 643 | // (such as when the superclass could not be found). |
| 644 | ArtMethod* art_method_; |
| 645 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 646 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 647 | // collection pointer to passes which may create NullConstant. |
| 648 | ReferenceTypeInfo inexact_object_rti_; |
| 649 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 650 | // Whether we are compiling this graph for on stack replacement: this will |
| 651 | // make all loops seen as irreducible and emit special stack maps to mark |
| 652 | // compiled code entries which the interpreter can directly jump to. |
| 653 | const bool osr_; |
| 654 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 655 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 656 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 657 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 658 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 659 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 660 | }; |
| 661 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 662 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 663 | public: |
| 664 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 665 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 666 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 667 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 668 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 669 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 670 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 671 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 672 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 673 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 674 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 675 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 676 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 677 | |
| 678 | void Dump(std::ostream& os); |
| 679 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 680 | HBasicBlock* GetHeader() const { |
| 681 | return header_; |
| 682 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 683 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 684 | void SetHeader(HBasicBlock* block) { |
| 685 | header_ = block; |
| 686 | } |
| 687 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 688 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 689 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 690 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 691 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 692 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 693 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 696 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 697 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 698 | } |
| 699 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 700 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 701 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 702 | } |
| 703 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 704 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 705 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 708 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 709 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 710 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 711 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 712 | } |
| 713 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 714 | // Returns the lifetime position of the back edge that has the |
| 715 | // greatest lifetime position. |
| 716 | size_t GetLifetimeEnd() const; |
| 717 | |
| 718 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 719 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 720 | } |
| 721 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 722 | // Finds blocks that are part of this loop. |
| 723 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 724 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 725 | // Returns whether this loop information contains `block`. |
| 726 | // Note that this loop information *must* be populated before entering this function. |
| 727 | bool Contains(const HBasicBlock& block) const; |
| 728 | |
| 729 | // Returns whether this loop information is an inner loop of `other`. |
| 730 | // Note that `other` *must* be populated before entering this function. |
| 731 | bool IsIn(const HLoopInformation& other) const; |
| 732 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 733 | // Returns true if instruction is not defined within this loop. |
| 734 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 735 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 736 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 737 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 738 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 739 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 740 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 741 | void ClearAllBlocks() { |
| 742 | blocks_.ClearAllBits(); |
| 743 | } |
| 744 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 745 | bool HasBackEdgeNotDominatedByHeader() const; |
| 746 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 747 | bool IsPopulated() const { |
| 748 | return blocks_.GetHighestBitSet() != -1; |
| 749 | } |
| 750 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 751 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 752 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 753 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 754 | // Internal recursive implementation of `Populate`. |
| 755 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 756 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 757 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 758 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 759 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 760 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 761 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 762 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 763 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 764 | |
| 765 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 766 | }; |
| 767 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 768 | // Stores try/catch information for basic blocks. |
| 769 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 770 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 771 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 772 | public: |
| 773 | // Try block information constructor. |
| 774 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 775 | : try_entry_(&try_entry), |
| 776 | catch_dex_file_(nullptr), |
| 777 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 778 | DCHECK(try_entry_ != nullptr); |
| 779 | } |
| 780 | |
| 781 | // Catch block information constructor. |
| 782 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 783 | : try_entry_(nullptr), |
| 784 | catch_dex_file_(&dex_file), |
| 785 | catch_type_index_(catch_type_index) {} |
| 786 | |
| 787 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 788 | |
| 789 | const HTryBoundary& GetTryEntry() const { |
| 790 | DCHECK(IsTryBlock()); |
| 791 | return *try_entry_; |
| 792 | } |
| 793 | |
| 794 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 795 | |
| 796 | bool IsCatchAllTypeIndex() const { |
| 797 | DCHECK(IsCatchBlock()); |
| 798 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 799 | } |
| 800 | |
| 801 | uint16_t GetCatchTypeIndex() const { |
| 802 | DCHECK(IsCatchBlock()); |
| 803 | return catch_type_index_; |
| 804 | } |
| 805 | |
| 806 | const DexFile& GetCatchDexFile() const { |
| 807 | DCHECK(IsCatchBlock()); |
| 808 | return *catch_dex_file_; |
| 809 | } |
| 810 | |
| 811 | private: |
| 812 | // One of possibly several TryBoundary instructions entering the block's try. |
| 813 | // Only set for try blocks. |
| 814 | const HTryBoundary* try_entry_; |
| 815 | |
| 816 | // Exception type information. Only set for catch blocks. |
| 817 | const DexFile* catch_dex_file_; |
| 818 | const uint16_t catch_type_index_; |
| 819 | }; |
| 820 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 821 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 822 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 823 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 824 | // A block in a method. Contains the list of instructions represented |
| 825 | // as a double linked list. Each block knows its predecessors and |
| 826 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 827 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 828 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 829 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 830 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 831 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 832 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 833 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 834 | loop_information_(nullptr), |
| 835 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 836 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 837 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 838 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 839 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 840 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 841 | try_catch_information_(nullptr) { |
| 842 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 843 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 844 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 845 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 846 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 847 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 848 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 851 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 852 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 853 | } |
| 854 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 855 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 856 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 857 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 858 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 859 | return ContainsElement(successors_, block, start_from); |
| 860 | } |
| 861 | |
| 862 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 863 | return dominated_blocks_; |
| 864 | } |
| 865 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 866 | bool IsEntryBlock() const { |
| 867 | return graph_->GetEntryBlock() == this; |
| 868 | } |
| 869 | |
| 870 | bool IsExitBlock() const { |
| 871 | return graph_->GetExitBlock() == this; |
| 872 | } |
| 873 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 874 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 875 | bool IsSingleTryBoundary() const; |
| 876 | |
| 877 | // Returns true if this block emits nothing but a jump. |
| 878 | bool IsSingleJump() const { |
| 879 | HLoopInformation* loop_info = GetLoopInformation(); |
| 880 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 881 | // Back edges generate a suspend check. |
| 882 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 883 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 884 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 885 | void AddBackEdge(HBasicBlock* back_edge) { |
| 886 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 887 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 888 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 889 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 890 | loop_information_->AddBackEdge(back_edge); |
| 891 | } |
| 892 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 893 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 894 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 895 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 896 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 897 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 898 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 899 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 900 | HBasicBlock* GetDominator() const { return dominator_; } |
| 901 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 902 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 903 | |
| 904 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 905 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 906 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 907 | |
| 908 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 909 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 910 | } |
| 911 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 912 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 913 | |
| 914 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 915 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 918 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 919 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 920 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 921 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 922 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 923 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 924 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 925 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 926 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 927 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 928 | successors_.push_back(block); |
| 929 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 932 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 933 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 934 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 935 | new_block->predecessors_.push_back(this); |
| 936 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 939 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 940 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 941 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 942 | new_block->successors_.push_back(this); |
| 943 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 946 | // Insert `this` between `predecessor` and `successor. This method |
| 947 | // preserves the indicies, and will update the first edge found between |
| 948 | // `predecessor` and `successor`. |
| 949 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 950 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 951 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 952 | successor->predecessors_[predecessor_index] = this; |
| 953 | predecessor->successors_[successor_index] = this; |
| 954 | successors_.push_back(successor); |
| 955 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 956 | } |
| 957 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 958 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 959 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 960 | } |
| 961 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 962 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 963 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 964 | } |
| 965 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 966 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 967 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 971 | predecessors_.push_back(block); |
| 972 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 973 | } |
| 974 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 975 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 976 | DCHECK_EQ(predecessors_.size(), 2u); |
| 977 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 978 | } |
| 979 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 980 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 981 | DCHECK_EQ(successors_.size(), 2u); |
| 982 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 983 | } |
| 984 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 985 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 986 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 987 | } |
| 988 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 989 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 990 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 991 | } |
| 992 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 993 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 994 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 995 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 999 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1000 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1004 | // predecessors is at index `idx`. |
| 1005 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1006 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1007 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1008 | } |
| 1009 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1010 | // Create a new block between this block and its predecessors. The new block |
| 1011 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1012 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1013 | // loop and try/catch information are not updated. |
| 1014 | HBasicBlock* CreateImmediateDominator(); |
| 1015 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1016 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1017 | // created, latter block. Note that this method will add the block to the |
| 1018 | // graph, create a Goto at the end of the former block and will create an edge |
| 1019 | // 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] | 1020 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1021 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1022 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1023 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1024 | // created block. Note that this method just updates raw block information, |
| 1025 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1026 | // update the graph, reverse post order, loop information, nor make sure the |
| 1027 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1028 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1029 | |
| 1030 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1031 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1032 | |
| 1033 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1034 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1035 | // that this method does not update the graph, reverse post order, loop |
| 1036 | // information, nor make sure the blocks are consistent (for example ending |
| 1037 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1038 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1039 | |
| 1040 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1041 | // of `this` are moved to `other`. |
| 1042 | // Note that this method does not update the graph, reverse post order, loop |
| 1043 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1044 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1045 | void ReplaceWith(HBasicBlock* other); |
| 1046 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1047 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1048 | // order, links to predecessors, successors, dominators and deletes the block |
| 1049 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1050 | // predecessor of `other` and vice versa. |
| 1051 | void MergeWith(HBasicBlock* other); |
| 1052 | |
| 1053 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1054 | // removes it from all loops it is included in and eventually from the graph. |
| 1055 | // The block must not dominate any other block. Predecessors and successors |
| 1056 | // are safely updated. |
| 1057 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1058 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1059 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1060 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1061 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1062 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1063 | // Replace instruction `initial` with `replacement` within this block. |
| 1064 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1065 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1066 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1067 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1068 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1069 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1070 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1071 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1072 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1073 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1074 | |
| 1075 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1076 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1077 | } |
| 1078 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1079 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1080 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1081 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1082 | } |
| 1083 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1084 | bool IsFirstPredecessorBackEdge() const { |
| 1085 | DCHECK(IsLoopHeader()); |
| 1086 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1087 | } |
| 1088 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1089 | HLoopInformation* GetLoopInformation() const { |
| 1090 | return loop_information_; |
| 1091 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1092 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1093 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1094 | // 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] | 1095 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1096 | void SetInLoop(HLoopInformation* info) { |
| 1097 | if (IsLoopHeader()) { |
| 1098 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1099 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1100 | loop_information_ = info; |
| 1101 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1102 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1103 | // Note that a non loop header having a loop information means this loop information |
| 1104 | // has already been populated |
| 1105 | loop_information_ = info; |
| 1106 | } else { |
| 1107 | // Block is part of an inner loop. Do not update the loop information. |
| 1108 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1109 | // at this point, because this method is being called while populating `info`. |
| 1110 | } |
| 1111 | } |
| 1112 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1113 | // Raw update of the loop information. |
| 1114 | void SetLoopInformation(HLoopInformation* info) { |
| 1115 | loop_information_ = info; |
| 1116 | } |
| 1117 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1118 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1119 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1120 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1121 | |
| 1122 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1123 | try_catch_information_ = try_catch_information; |
| 1124 | } |
| 1125 | |
| 1126 | bool IsTryBlock() const { |
| 1127 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1128 | } |
| 1129 | |
| 1130 | bool IsCatchBlock() const { |
| 1131 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1132 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1133 | |
| 1134 | // Returns the try entry that this block's successors should have. They will |
| 1135 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1136 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1137 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1138 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1139 | bool HasThrowingInstructions() const; |
| 1140 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1141 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1142 | bool Dominates(HBasicBlock* block) const; |
| 1143 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1144 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1145 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1146 | |
| 1147 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1148 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1149 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1150 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1151 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1152 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1153 | bool HasSinglePhi() const; |
| 1154 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1155 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1156 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1157 | ArenaVector<HBasicBlock*> predecessors_; |
| 1158 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1159 | HInstructionList instructions_; |
| 1160 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1161 | HLoopInformation* loop_information_; |
| 1162 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1163 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1164 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1165 | // The dex program counter of the first instruction of this block. |
| 1166 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1167 | size_t lifetime_start_; |
| 1168 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1169 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1170 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1171 | friend class HGraph; |
| 1172 | friend class HInstruction; |
| 1173 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1174 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1175 | }; |
| 1176 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1177 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1178 | // from the innermost to the outermost. |
| 1179 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1180 | public: |
| 1181 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1182 | : current_(block.GetLoopInformation()) {} |
| 1183 | |
| 1184 | bool Done() const { return current_ == nullptr; } |
| 1185 | |
| 1186 | void Advance() { |
| 1187 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1188 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | HLoopInformation* Current() const { |
| 1192 | DCHECK(!Done()); |
| 1193 | return current_; |
| 1194 | } |
| 1195 | |
| 1196 | private: |
| 1197 | HLoopInformation* current_; |
| 1198 | |
| 1199 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1200 | }; |
| 1201 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1202 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1203 | M(Above, Condition) \ |
| 1204 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1205 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1206 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1207 | M(ArrayGet, Instruction) \ |
| 1208 | M(ArrayLength, Instruction) \ |
| 1209 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1210 | M(Below, Condition) \ |
| 1211 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1212 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1213 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1214 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1215 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1216 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1217 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1218 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1219 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1220 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1221 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1222 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1223 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1224 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1225 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1226 | M(Exit, Instruction) \ |
| 1227 | M(FloatConstant, Constant) \ |
| 1228 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1229 | M(GreaterThan, Condition) \ |
| 1230 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1231 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1232 | M(InstanceFieldGet, Instruction) \ |
| 1233 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1234 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1235 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1236 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1237 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1238 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1239 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1240 | M(LessThan, Condition) \ |
| 1241 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1242 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1243 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1244 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1245 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1246 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1247 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1248 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1249 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1250 | M(Neg, UnaryOperation) \ |
| 1251 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1252 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1253 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1254 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1255 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1256 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1257 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1258 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1259 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1260 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1261 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1262 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1263 | M(Return, Instruction) \ |
| 1264 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1265 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1266 | M(Shl, BinaryOperation) \ |
| 1267 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1268 | M(StaticFieldGet, Instruction) \ |
| 1269 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1270 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1271 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1272 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1273 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1274 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1275 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1276 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1277 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1278 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1279 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1280 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1281 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1282 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1283 | /* |
| 1284 | * Instructions, shared across several (not all) architectures. |
| 1285 | */ |
| 1286 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1287 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1288 | #else |
| 1289 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1290 | M(BitwiseNegatedRight, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1291 | M(MultiplyAccumulate, Instruction) \ |
| 1292 | M(IntermediateAddress, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1293 | #endif |
| 1294 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1295 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1296 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1297 | #else |
| 1298 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1299 | M(ArmDexCacheArraysBase, Instruction) |
| 1300 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1301 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1302 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1303 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1304 | #else |
| 1305 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1306 | M(Arm64DataProcWithShifterOp, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1307 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1308 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1309 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1310 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1311 | #else |
| 1312 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1313 | M(MipsComputeBaseMethodAddress, Instruction) \ |
| 1314 | M(MipsDexCacheArraysBase, Instruction) |
| 1315 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1316 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1317 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1318 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1319 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1320 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1321 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1322 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1323 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1324 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1325 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1326 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1327 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1328 | |
| 1329 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1330 | |
| 1331 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1332 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1333 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1334 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1335 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1336 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1337 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1338 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1339 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1340 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1341 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1342 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1343 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1344 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1345 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1346 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1347 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1348 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1349 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1350 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1351 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1352 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1353 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1354 | #undef FORWARD_DECLARATION |
| 1355 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1356 | #define DECLARE_INSTRUCTION(type) \ |
| 1357 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1358 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1359 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1360 | return other->Is##type(); \ |
| 1361 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1362 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1363 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1364 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1365 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1366 | const H##type* As##type() const { return this; } \ |
| 1367 | H##type* As##type() { return this; } |
| 1368 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1369 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1370 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1371 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1372 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1373 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1374 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1375 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1376 | // Hook for the IntrusiveForwardList<>. |
| 1377 | // TODO: Hide this better. |
| 1378 | IntrusiveForwardListHook hook; |
| 1379 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1380 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1381 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1382 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1383 | |
| 1384 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1385 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1386 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1387 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1388 | |
| 1389 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1390 | }; |
| 1391 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1392 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1393 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1394 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1395 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1396 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1397 | // by the used instructions. |
| 1398 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1399 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1400 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1401 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1402 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1403 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1404 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1405 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1406 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1407 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1408 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1412 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1413 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1414 | |
| 1415 | private: |
| 1416 | // Instruction used by the user. |
| 1417 | HInstruction* instruction_; |
| 1418 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1419 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1420 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1421 | }; |
| 1422 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1423 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1424 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1425 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1426 | struct HInputExtractor { |
| 1427 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1428 | return record.GetInstruction(); |
| 1429 | } |
| 1430 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1431 | return record.GetInstruction(); |
| 1432 | } |
| 1433 | }; |
| 1434 | |
| 1435 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1436 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1437 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1438 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1439 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1440 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1441 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1442 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1443 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1444 | * modify the value of a reference field read [although it may modify the |
| 1445 | * reference fetch prior to reading the field, which is represented by its own |
| 1446 | * write/read dependence]). The analysis makes conservative points-to |
| 1447 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1448 | * the same, and any reference read depends on any reference read without |
| 1449 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1450 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1451 | * The internal representation uses 38-bit and is described in the table below. |
| 1452 | * The first line indicates the side effect, and for field/array accesses the |
| 1453 | * second line indicates the type of the access (in the order of the |
| 1454 | * Primitive::Type enum). |
| 1455 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1456 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1457 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1458 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1459 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1460 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1461 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1462 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1463 | * |
| 1464 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1465 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1466 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1467 | class SideEffects : public ValueObject { |
| 1468 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1469 | SideEffects() : flags_(0) {} |
| 1470 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1471 | static SideEffects None() { |
| 1472 | return SideEffects(0); |
| 1473 | } |
| 1474 | |
| 1475 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1476 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1477 | } |
| 1478 | |
| 1479 | static SideEffects AllChanges() { |
| 1480 | return SideEffects(kAllChangeBits); |
| 1481 | } |
| 1482 | |
| 1483 | static SideEffects AllDependencies() { |
| 1484 | return SideEffects(kAllDependOnBits); |
| 1485 | } |
| 1486 | |
| 1487 | static SideEffects AllExceptGCDependency() { |
| 1488 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1489 | } |
| 1490 | |
| 1491 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1492 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1493 | } |
| 1494 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1495 | static SideEffects AllWrites() { |
| 1496 | return SideEffects(kAllWrites); |
| 1497 | } |
| 1498 | |
| 1499 | static SideEffects AllReads() { |
| 1500 | return SideEffects(kAllReads); |
| 1501 | } |
| 1502 | |
| 1503 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1504 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1505 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1506 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1507 | } |
| 1508 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1509 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1510 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1511 | } |
| 1512 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1513 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1514 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1515 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1516 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1520 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1523 | static SideEffects CanTriggerGC() { |
| 1524 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1525 | } |
| 1526 | |
| 1527 | static SideEffects DependsOnGC() { |
| 1528 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1529 | } |
| 1530 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1531 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1532 | SideEffects Union(SideEffects other) const { |
| 1533 | return SideEffects(flags_ | other.flags_); |
| 1534 | } |
| 1535 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1536 | SideEffects Exclusion(SideEffects other) const { |
| 1537 | return SideEffects(flags_ & ~other.flags_); |
| 1538 | } |
| 1539 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1540 | void Add(SideEffects other) { |
| 1541 | flags_ |= other.flags_; |
| 1542 | } |
| 1543 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1544 | bool Includes(SideEffects other) const { |
| 1545 | return (other.flags_ & flags_) == other.flags_; |
| 1546 | } |
| 1547 | |
| 1548 | bool HasSideEffects() const { |
| 1549 | return (flags_ & kAllChangeBits); |
| 1550 | } |
| 1551 | |
| 1552 | bool HasDependencies() const { |
| 1553 | return (flags_ & kAllDependOnBits); |
| 1554 | } |
| 1555 | |
| 1556 | // Returns true if there are no side effects or dependencies. |
| 1557 | bool DoesNothing() const { |
| 1558 | return flags_ == 0; |
| 1559 | } |
| 1560 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1561 | // Returns true if something is written. |
| 1562 | bool DoesAnyWrite() const { |
| 1563 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1564 | } |
| 1565 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1566 | // Returns true if something is read. |
| 1567 | bool DoesAnyRead() const { |
| 1568 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1569 | } |
| 1570 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1571 | // Returns true if potentially everything is written and read |
| 1572 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1573 | bool DoesAllReadWrite() const { |
| 1574 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1575 | } |
| 1576 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1577 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1578 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1581 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1582 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1583 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1584 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1588 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1589 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1590 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1591 | for (int s = kLastBit; s >= 0; s--) { |
| 1592 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1593 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1594 | // This is a bit for the GC side effect. |
| 1595 | if (current_bit_is_set) { |
| 1596 | flags += "GC"; |
| 1597 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1598 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1599 | } else { |
| 1600 | // This is a bit for the array/field analysis. |
| 1601 | // The underscore character stands for the 'can trigger GC' bit. |
| 1602 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1603 | if (current_bit_is_set) { |
| 1604 | flags += kDebug[s]; |
| 1605 | } |
| 1606 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1607 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1608 | flags += "|"; |
| 1609 | } |
| 1610 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1611 | } |
| 1612 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1613 | } |
| 1614 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1615 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1616 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1617 | private: |
| 1618 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1619 | |
| 1620 | static constexpr int kFieldWriteOffset = 0; |
| 1621 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1622 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1623 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1624 | |
| 1625 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1626 | |
| 1627 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1628 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1629 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1630 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1631 | |
| 1632 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1633 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1634 | |
| 1635 | // Aliases. |
| 1636 | |
| 1637 | static_assert(kChangeBits == kDependOnBits, |
| 1638 | "the 'change' bits should match the 'depend on' bits."); |
| 1639 | |
| 1640 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1641 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1642 | static constexpr uint64_t kAllWrites = |
| 1643 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1644 | static constexpr uint64_t kAllReads = |
| 1645 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1646 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1647 | // Translates type to bit flag. |
| 1648 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1649 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1650 | const uint64_t one = 1; |
| 1651 | const int shift = type; // 0-based consecutive enum |
| 1652 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1653 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1654 | return one << (type + offset); |
| 1655 | } |
| 1656 | |
| 1657 | // Private constructor on direct flags value. |
| 1658 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1659 | |
| 1660 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1661 | }; |
| 1662 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1663 | // 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] | 1664 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1665 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1666 | HEnvironment(ArenaAllocator* arena, |
| 1667 | size_t number_of_vregs, |
| 1668 | const DexFile& dex_file, |
| 1669 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1670 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1671 | InvokeType invoke_type, |
| 1672 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1673 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1674 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1675 | parent_(nullptr), |
| 1676 | dex_file_(dex_file), |
| 1677 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1678 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1679 | invoke_type_(invoke_type), |
| 1680 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1681 | } |
| 1682 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1683 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1684 | : HEnvironment(arena, |
| 1685 | to_copy.Size(), |
| 1686 | to_copy.GetDexFile(), |
| 1687 | to_copy.GetMethodIdx(), |
| 1688 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1689 | to_copy.GetInvokeType(), |
| 1690 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1691 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1692 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1693 | if (parent_ != nullptr) { |
| 1694 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1695 | } else { |
| 1696 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1697 | parent_->CopyFrom(parent); |
| 1698 | if (parent->GetParent() != nullptr) { |
| 1699 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1700 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1701 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1704 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1705 | void CopyFrom(HEnvironment* environment); |
| 1706 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1707 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1708 | // input to the loop phi instead. This is for inserting instructions that |
| 1709 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1710 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1711 | |
| 1712 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1713 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1717 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1720 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1721 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1722 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1723 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1724 | HEnvironment* GetParent() const { return parent_; } |
| 1725 | |
| 1726 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1727 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1731 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | uint32_t GetDexPc() const { |
| 1735 | return dex_pc_; |
| 1736 | } |
| 1737 | |
| 1738 | uint32_t GetMethodIdx() const { |
| 1739 | return method_idx_; |
| 1740 | } |
| 1741 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1742 | InvokeType GetInvokeType() const { |
| 1743 | return invoke_type_; |
| 1744 | } |
| 1745 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1746 | const DexFile& GetDexFile() const { |
| 1747 | return dex_file_; |
| 1748 | } |
| 1749 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1750 | HInstruction* GetHolder() const { |
| 1751 | return holder_; |
| 1752 | } |
| 1753 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1754 | |
| 1755 | bool IsFromInlinedInvoke() const { |
| 1756 | return GetParent() != nullptr; |
| 1757 | } |
| 1758 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1759 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1760 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1761 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1762 | HEnvironment* parent_; |
| 1763 | const DexFile& dex_file_; |
| 1764 | const uint32_t method_idx_; |
| 1765 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1766 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1767 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1768 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1769 | HInstruction* const holder_; |
| 1770 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1771 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1772 | |
| 1773 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1774 | }; |
| 1775 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1776 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1777 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1778 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1779 | : previous_(nullptr), |
| 1780 | next_(nullptr), |
| 1781 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1782 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1783 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1784 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1785 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1786 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1787 | locations_(nullptr), |
| 1788 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1789 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1790 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1791 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1792 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1793 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1794 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1795 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1796 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1797 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1798 | enum InstructionKind { |
| 1799 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1800 | }; |
| 1801 | #undef DECLARE_KIND |
| 1802 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1803 | HInstruction* GetNext() const { return next_; } |
| 1804 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1805 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1806 | HInstruction* GetNextDisregardingMoves() const; |
| 1807 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1808 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1809 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1810 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1811 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1812 | bool IsInBlock() const { return block_ != nullptr; } |
| 1813 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1814 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1815 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1816 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1817 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1818 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1819 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1820 | |
| 1821 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1822 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1823 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1824 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1825 | } |
| 1826 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1827 | HInputsRef GetInputs() { |
| 1828 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1829 | } |
| 1830 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1831 | HConstInputsRef GetInputs() const { |
| 1832 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1836 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1837 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1838 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1839 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1840 | } |
| 1841 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1842 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1843 | virtual const char* DebugName() const = 0; |
| 1844 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1845 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1846 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1847 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1848 | |
| 1849 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1850 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1851 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1852 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1853 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1854 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1855 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1856 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1857 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1858 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1859 | // Does not apply for all instructions, but having this at top level greatly |
| 1860 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1861 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1862 | virtual bool CanBeNull() const { |
| 1863 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1864 | return true; |
| 1865 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1866 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1867 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1868 | return false; |
| 1869 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1870 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1871 | virtual bool IsActualObject() const { |
| 1872 | return GetType() == Primitive::kPrimNot; |
| 1873 | } |
| 1874 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1875 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1876 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1877 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1878 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1879 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1880 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1881 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1882 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1883 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1884 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1885 | // Note: fixup_end remains valid across push_front(). |
| 1886 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1887 | HUseListNode<HInstruction*>* new_node = |
| 1888 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1889 | uses_.push_front(*new_node); |
| 1890 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1893 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1894 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1895 | // Note: env_fixup_end remains valid across push_front(). |
| 1896 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 1897 | HUseListNode<HEnvironment*>* new_node = |
| 1898 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 1899 | env_uses_.push_front(*new_node); |
| 1900 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1901 | } |
| 1902 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1903 | void RemoveAsUserOfInput(size_t input) { |
| 1904 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1905 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1906 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1907 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1908 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1909 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1910 | void RemoveAsUserOfAllInputs() { |
| 1911 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 1912 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1913 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1914 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 1915 | } |
| 1916 | } |
| 1917 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1918 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1919 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1920 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1921 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 1922 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 1923 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1924 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1925 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1926 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1927 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1928 | // Does this instruction strictly dominate `other_instruction`? |
| 1929 | // Returns false if this instruction and `other_instruction` are the same. |
| 1930 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1931 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1932 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1933 | int GetId() const { return id_; } |
| 1934 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1935 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1936 | int GetSsaIndex() const { return ssa_index_; } |
| 1937 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1938 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1939 | |
| 1940 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1941 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1942 | // Set the `environment_` field. Raw because this method does not |
| 1943 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1944 | void SetRawEnvironment(HEnvironment* environment) { |
| 1945 | DCHECK(environment_ == nullptr); |
| 1946 | DCHECK_EQ(environment->GetHolder(), this); |
| 1947 | environment_ = environment; |
| 1948 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1949 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 1950 | void InsertRawEnvironment(HEnvironment* environment) { |
| 1951 | DCHECK(environment_ != nullptr); |
| 1952 | DCHECK_EQ(environment->GetHolder(), this); |
| 1953 | DCHECK(environment->GetParent() == nullptr); |
| 1954 | environment->parent_ = environment_; |
| 1955 | environment_ = environment; |
| 1956 | } |
| 1957 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1958 | void RemoveEnvironment(); |
| 1959 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1960 | // Set the environment of this instruction, copying it from `environment`. While |
| 1961 | // copying, the uses lists are being updated. |
| 1962 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1963 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1964 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1965 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1966 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1967 | if (environment->GetParent() != nullptr) { |
| 1968 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1969 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1970 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1971 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1972 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1973 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1974 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1975 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1976 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1977 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1978 | if (environment->GetParent() != nullptr) { |
| 1979 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1980 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1983 | // Returns the number of entries in the environment. Typically, that is the |
| 1984 | // number of dex registers in a method. It could be more in case of inlining. |
| 1985 | size_t EnvironmentSize() const; |
| 1986 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1987 | LocationSummary* GetLocations() const { return locations_; } |
| 1988 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1989 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1990 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1991 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1992 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1993 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1994 | // uses of this instruction by `other` are *not* updated. |
| 1995 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1996 | ReplaceWith(other); |
| 1997 | other->ReplaceInput(this, use_index); |
| 1998 | } |
| 1999 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2000 | // Move `this` instruction before `cursor`. |
| 2001 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2002 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2003 | // Move `this` before its first user and out of any loops. If there is no |
| 2004 | // out-of-loop user that dominates all other users, move the instruction |
| 2005 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2006 | // |
| 2007 | // This can be used only on non-throwing instructions with no side effects that |
| 2008 | // have at least one use but no environment uses. |
| 2009 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2010 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2011 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2012 | bool Is##type() const; \ |
| 2013 | const H##type* As##type() const; \ |
| 2014 | H##type* As##type(); |
| 2015 | |
| 2016 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2017 | #undef INSTRUCTION_TYPE_CHECK |
| 2018 | |
| 2019 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2020 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2021 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2022 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2023 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2024 | #undef INSTRUCTION_TYPE_CHECK |
| 2025 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2026 | // Returns whether the instruction can be moved within the graph. |
| 2027 | virtual bool CanBeMoved() const { return false; } |
| 2028 | |
| 2029 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2030 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2031 | return false; |
| 2032 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2033 | |
| 2034 | // Returns whether any data encoded in the two instructions is equal. |
| 2035 | // This method does not look at the inputs. Both instructions must be |
| 2036 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2037 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2038 | return false; |
| 2039 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2040 | |
| 2041 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2042 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2043 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2044 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2045 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2046 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2047 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2048 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2049 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2050 | InstructionKind GetKind() const PURE; |
| 2051 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2052 | |
| 2053 | virtual size_t ComputeHashCode() const { |
| 2054 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2055 | for (const HInstruction* input : GetInputs()) { |
| 2056 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2057 | } |
| 2058 | return result; |
| 2059 | } |
| 2060 | |
| 2061 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2062 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2063 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2064 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2065 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2066 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2067 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2068 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2069 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2070 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2071 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2072 | |
| 2073 | // Returns whether the code generation of the instruction will require to have access |
| 2074 | // to the current method. Such instructions are: |
| 2075 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2076 | // to walk the stack and have the current method stored at a specific stack address. |
| 2077 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2078 | // fields of the current method. |
| 2079 | bool NeedsCurrentMethod() const { |
| 2080 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2081 | } |
| 2082 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2083 | // Returns whether the code generation of the instruction will require to have access |
| 2084 | // to the dex cache of the current method's declaring class via the current method. |
| 2085 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2086 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2087 | // Does this instruction have any use in an environment before |
| 2088 | // control flow hits 'other'? |
| 2089 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2090 | |
| 2091 | // Remove all references to environment uses of this instruction. |
| 2092 | // The caller must ensure that this is safe to do. |
| 2093 | void RemoveEnvironmentUsers(); |
| 2094 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2095 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2096 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2097 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2098 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2099 | // If set, the machine code for this instruction is assumed to be generated by |
| 2100 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2101 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2102 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2103 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2104 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2105 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2106 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2107 | return GetInputRecords()[i]; |
| 2108 | } |
| 2109 | |
| 2110 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2111 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2112 | input_records[index] = input; |
| 2113 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2114 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2115 | uint32_t GetPackedFields() const { |
| 2116 | return packed_fields_; |
| 2117 | } |
| 2118 | |
| 2119 | template <size_t flag> |
| 2120 | bool GetPackedFlag() const { |
| 2121 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2122 | } |
| 2123 | |
| 2124 | template <size_t flag> |
| 2125 | void SetPackedFlag(bool value = true) { |
| 2126 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2127 | } |
| 2128 | |
| 2129 | template <typename BitFieldType> |
| 2130 | typename BitFieldType::value_type GetPackedField() const { |
| 2131 | return BitFieldType::Decode(packed_fields_); |
| 2132 | } |
| 2133 | |
| 2134 | template <typename BitFieldType> |
| 2135 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2136 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2137 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2138 | } |
| 2139 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2140 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2141 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2142 | auto before_use_node = uses_.before_begin(); |
| 2143 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2144 | HInstruction* user = use_node->GetUser(); |
| 2145 | size_t input_index = use_node->GetIndex(); |
| 2146 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2147 | before_use_node = use_node; |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2152 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2153 | if (next != uses_.end()) { |
| 2154 | HInstruction* next_user = next->GetUser(); |
| 2155 | size_t next_index = next->GetIndex(); |
| 2156 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2157 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2158 | } |
| 2159 | } |
| 2160 | |
| 2161 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2162 | auto before_env_use_node = env_uses_.before_begin(); |
| 2163 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2164 | HEnvironment* user = env_use_node->GetUser(); |
| 2165 | size_t input_index = env_use_node->GetIndex(); |
| 2166 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2167 | before_env_use_node = env_use_node; |
| 2168 | } |
| 2169 | } |
| 2170 | |
| 2171 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2172 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2173 | if (next != env_uses_.end()) { |
| 2174 | HEnvironment* next_user = next->GetUser(); |
| 2175 | size_t next_index = next->GetIndex(); |
| 2176 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2177 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2178 | } |
| 2179 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2180 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2181 | HInstruction* previous_; |
| 2182 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2183 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2184 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2185 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2186 | // An instruction gets an id when it is added to the graph. |
| 2187 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2188 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2189 | int id_; |
| 2190 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2191 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2192 | int ssa_index_; |
| 2193 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2194 | // Packed fields. |
| 2195 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2196 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2197 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2198 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2199 | |
| 2200 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2201 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2202 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2203 | // The environment associated with this instruction. Not null if the instruction |
| 2204 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2205 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2206 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2207 | // Set by the code generator. |
| 2208 | LocationSummary* locations_; |
| 2209 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2210 | // Set by the liveness analysis. |
| 2211 | LiveInterval* live_interval_; |
| 2212 | |
| 2213 | // Set by the liveness analysis, this is the position in a linear |
| 2214 | // order of blocks where this instruction's live interval start. |
| 2215 | size_t lifetime_position_; |
| 2216 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2217 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2218 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2219 | // The reference handle part of the reference type info. |
| 2220 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2221 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2222 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2223 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2224 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2225 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2226 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2227 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2228 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2229 | |
| 2230 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2231 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2232 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2233 | |
| 2234 | class HInstructionIterator : public ValueObject { |
| 2235 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2236 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2237 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2238 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2241 | bool Done() const { return instruction_ == nullptr; } |
| 2242 | HInstruction* Current() const { return instruction_; } |
| 2243 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2244 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2245 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | private: |
| 2249 | HInstruction* instruction_; |
| 2250 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2251 | |
| 2252 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2253 | }; |
| 2254 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2255 | class HBackwardInstructionIterator : public ValueObject { |
| 2256 | public: |
| 2257 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2258 | : instruction_(instructions.last_instruction_) { |
| 2259 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2260 | } |
| 2261 | |
| 2262 | bool Done() const { return instruction_ == nullptr; } |
| 2263 | HInstruction* Current() const { return instruction_; } |
| 2264 | void Advance() { |
| 2265 | instruction_ = next_; |
| 2266 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2267 | } |
| 2268 | |
| 2269 | private: |
| 2270 | HInstruction* instruction_; |
| 2271 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2272 | |
| 2273 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2274 | }; |
| 2275 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2276 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2277 | class HTemplateInstruction: public HInstruction { |
| 2278 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2279 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2280 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2281 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2282 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2283 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2284 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2285 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2286 | } |
| 2287 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2288 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2289 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2290 | |
| 2291 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2292 | }; |
| 2293 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2294 | // HTemplateInstruction specialization for N=0. |
| 2295 | template<> |
| 2296 | class HTemplateInstruction<0>: public HInstruction { |
| 2297 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2298 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2299 | : HInstruction(side_effects, dex_pc) {} |
| 2300 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2301 | virtual ~HTemplateInstruction() {} |
| 2302 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2303 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2304 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2305 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | private: |
| 2309 | friend class SsaBuilder; |
| 2310 | }; |
| 2311 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2312 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2313 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2314 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2315 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2316 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2317 | this->template SetPackedField<TypeField>(type); |
| 2318 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2319 | virtual ~HExpression() {} |
| 2320 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2321 | Primitive::Type GetType() const OVERRIDE { |
| 2322 | return TypeField::Decode(this->GetPackedFields()); |
| 2323 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2324 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2325 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2326 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2327 | static constexpr size_t kFieldTypeSize = |
| 2328 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2329 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2330 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2331 | "Too many packed fields."); |
| 2332 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2333 | }; |
| 2334 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2335 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2336 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2337 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2338 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2339 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2340 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2341 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2342 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2343 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2344 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2345 | |
| 2346 | private: |
| 2347 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2348 | }; |
| 2349 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2350 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2351 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2352 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2353 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2354 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2355 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2356 | SetRawInputAt(0, value); |
| 2357 | } |
| 2358 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2359 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2360 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2361 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2362 | |
| 2363 | private: |
| 2364 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2365 | }; |
| 2366 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2367 | class HPhi FINAL : public HInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2368 | public: |
| 2369 | HPhi(ArenaAllocator* arena, |
| 2370 | uint32_t reg_number, |
| 2371 | size_t number_of_inputs, |
| 2372 | Primitive::Type type, |
| 2373 | uint32_t dex_pc = kNoDexPc) |
| 2374 | : HInstruction(SideEffects::None(), dex_pc), |
| 2375 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
| 2376 | reg_number_(reg_number) { |
| 2377 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2378 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2379 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2380 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2381 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2382 | SetPackedFlag<kFlagIsLive>(true); |
| 2383 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2384 | } |
| 2385 | |
| 2386 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2387 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2388 | return Primitive::PrimitiveKind(type); |
| 2389 | } |
| 2390 | |
| 2391 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2392 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2393 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2394 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2395 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2396 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2397 | |
| 2398 | void AddInput(HInstruction* input); |
| 2399 | void RemoveInputAt(size_t index); |
| 2400 | |
| 2401 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2402 | void SetType(Primitive::Type new_type) { |
| 2403 | // Make sure that only valid type changes occur. The following are allowed: |
| 2404 | // (1) int -> float/ref (primitive type propagation), |
| 2405 | // (2) long -> double (primitive type propagation). |
| 2406 | DCHECK(GetType() == new_type || |
| 2407 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2408 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2409 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2410 | SetPackedField<TypeField>(new_type); |
| 2411 | } |
| 2412 | |
| 2413 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2414 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2415 | |
| 2416 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2417 | |
| 2418 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2419 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2420 | bool IsDead() const { return !IsLive(); } |
| 2421 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2422 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2423 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2424 | return other != nullptr |
| 2425 | && other->IsPhi() |
| 2426 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2427 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2428 | } |
| 2429 | |
| 2430 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2431 | // An equivalent phi is a phi having the same dex register and type. |
| 2432 | // It assumes that phis with the same dex register are adjacent. |
| 2433 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2434 | HInstruction* next = GetNext(); |
| 2435 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2436 | if (next->GetType() == GetType()) { |
| 2437 | return next->AsPhi(); |
| 2438 | } |
| 2439 | next = next->GetNext(); |
| 2440 | } |
| 2441 | return nullptr; |
| 2442 | } |
| 2443 | |
| 2444 | DECLARE_INSTRUCTION(Phi); |
| 2445 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2446 | private: |
| 2447 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2448 | static constexpr size_t kFieldTypeSize = |
| 2449 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2450 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2451 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2452 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2453 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2454 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2455 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2456 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2457 | const uint32_t reg_number_; |
| 2458 | |
| 2459 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2460 | }; |
| 2461 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2462 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2463 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2464 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2465 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2466 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2467 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2468 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2469 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2470 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2471 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2472 | |
| 2473 | private: |
| 2474 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2475 | }; |
| 2476 | |
| 2477 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2478 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2479 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2480 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2481 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2482 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2483 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2484 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2485 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2486 | } |
| 2487 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2488 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2489 | |
| 2490 | private: |
| 2491 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2492 | }; |
| 2493 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2494 | class HConstant : public HExpression<0> { |
| 2495 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2496 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2497 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2498 | |
| 2499 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2500 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2501 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2502 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2503 | // Is this constant 0 in the arithmetic sense? |
| 2504 | virtual bool IsArithmeticZero() const { return false; } |
| 2505 | // Is this constant a 0-bit pattern? |
| 2506 | virtual bool IsZeroBitPattern() const { return false; } |
| 2507 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2508 | virtual bool IsOne() const { return false; } |
| 2509 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2510 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2511 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2512 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2513 | |
| 2514 | private: |
| 2515 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2516 | }; |
| 2517 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2518 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2519 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2520 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2521 | return true; |
| 2522 | } |
| 2523 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2524 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2525 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2526 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2527 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2528 | // The null constant representation is a 0-bit pattern. |
| 2529 | virtual bool IsZeroBitPattern() const { return true; } |
| 2530 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2531 | DECLARE_INSTRUCTION(NullConstant); |
| 2532 | |
| 2533 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2534 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2535 | |
| 2536 | friend class HGraph; |
| 2537 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2538 | }; |
| 2539 | |
| 2540 | // Constants of the type int. Those can be from Dex instructions, or |
| 2541 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2542 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2543 | public: |
| 2544 | int32_t GetValue() const { return value_; } |
| 2545 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2546 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2547 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2548 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2549 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2550 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2551 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2552 | return other->AsIntConstant()->value_ == value_; |
| 2553 | } |
| 2554 | |
| 2555 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2556 | |
| 2557 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2558 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2559 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2560 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2561 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2562 | // Integer constants are used to encode Boolean values as well, |
| 2563 | // where 1 means true and 0 means false. |
| 2564 | bool IsTrue() const { return GetValue() == 1; } |
| 2565 | bool IsFalse() const { return GetValue() == 0; } |
| 2566 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2567 | DECLARE_INSTRUCTION(IntConstant); |
| 2568 | |
| 2569 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2570 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2571 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2572 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2573 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2574 | |
| 2575 | const int32_t value_; |
| 2576 | |
| 2577 | friend class HGraph; |
| 2578 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2579 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2580 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2581 | }; |
| 2582 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2583 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2584 | public: |
| 2585 | int64_t GetValue() const { return value_; } |
| 2586 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2587 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2588 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2589 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2590 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2591 | return other->AsLongConstant()->value_ == value_; |
| 2592 | } |
| 2593 | |
| 2594 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2595 | |
| 2596 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2597 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2598 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2599 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2600 | |
| 2601 | DECLARE_INSTRUCTION(LongConstant); |
| 2602 | |
| 2603 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2604 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2605 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2606 | |
| 2607 | const int64_t value_; |
| 2608 | |
| 2609 | friend class HGraph; |
| 2610 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2611 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2612 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2613 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2614 | public: |
| 2615 | float GetValue() const { return value_; } |
| 2616 | |
| 2617 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2618 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2619 | } |
| 2620 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2621 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2622 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2623 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2624 | } |
| 2625 | |
| 2626 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2627 | |
| 2628 | bool IsMinusOne() const OVERRIDE { |
| 2629 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2630 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2631 | bool IsArithmeticZero() const OVERRIDE { |
| 2632 | return std::fpclassify(value_) == FP_ZERO; |
| 2633 | } |
| 2634 | bool IsArithmeticPositiveZero() const { |
| 2635 | return IsArithmeticZero() && !std::signbit(value_); |
| 2636 | } |
| 2637 | bool IsArithmeticNegativeZero() const { |
| 2638 | return IsArithmeticZero() && std::signbit(value_); |
| 2639 | } |
| 2640 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2641 | 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] | 2642 | } |
| 2643 | bool IsOne() const OVERRIDE { |
| 2644 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2645 | } |
| 2646 | bool IsNaN() const { |
| 2647 | return std::isnan(value_); |
| 2648 | } |
| 2649 | |
| 2650 | DECLARE_INSTRUCTION(FloatConstant); |
| 2651 | |
| 2652 | private: |
| 2653 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2654 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2655 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2656 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2657 | |
| 2658 | const float value_; |
| 2659 | |
| 2660 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2661 | friend class SsaBuilder; |
| 2662 | friend class HGraph; |
| 2663 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2664 | }; |
| 2665 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2666 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2667 | public: |
| 2668 | double GetValue() const { return value_; } |
| 2669 | |
| 2670 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2671 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2672 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2673 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2674 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2675 | } |
| 2676 | |
| 2677 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2678 | |
| 2679 | bool IsMinusOne() const OVERRIDE { |
| 2680 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2681 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2682 | bool IsArithmeticZero() const OVERRIDE { |
| 2683 | return std::fpclassify(value_) == FP_ZERO; |
| 2684 | } |
| 2685 | bool IsArithmeticPositiveZero() const { |
| 2686 | return IsArithmeticZero() && !std::signbit(value_); |
| 2687 | } |
| 2688 | bool IsArithmeticNegativeZero() const { |
| 2689 | return IsArithmeticZero() && std::signbit(value_); |
| 2690 | } |
| 2691 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2692 | 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] | 2693 | } |
| 2694 | bool IsOne() const OVERRIDE { |
| 2695 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2696 | } |
| 2697 | bool IsNaN() const { |
| 2698 | return std::isnan(value_); |
| 2699 | } |
| 2700 | |
| 2701 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2702 | |
| 2703 | private: |
| 2704 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2705 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2706 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2707 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2708 | |
| 2709 | const double value_; |
| 2710 | |
| 2711 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2712 | friend class SsaBuilder; |
| 2713 | friend class HGraph; |
| 2714 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2715 | }; |
| 2716 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2717 | // Conditional branch. A block ending with an HIf instruction must have |
| 2718 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2719 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2720 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2721 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2722 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2723 | SetRawInputAt(0, input); |
| 2724 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2725 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2726 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2727 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2728 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2729 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2733 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2736 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2737 | |
| 2738 | private: |
| 2739 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2740 | }; |
| 2741 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2742 | |
| 2743 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2744 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2745 | // non-exceptional control flow. |
| 2746 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2747 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2748 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2749 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2750 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2751 | kEntry, |
| 2752 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2753 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2754 | }; |
| 2755 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2756 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2757 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2758 | SetPackedField<BoundaryKindField>(kind); |
| 2759 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2760 | |
| 2761 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2762 | |
| 2763 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2764 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2765 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2766 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2767 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2768 | } |
| 2769 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2770 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2771 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2772 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2773 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2774 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | // If not present already, adds `handler` to its block's list of exception |
| 2778 | // handlers. |
| 2779 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2780 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2781 | GetBlock()->AddSuccessor(handler); |
| 2782 | } |
| 2783 | } |
| 2784 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2785 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2786 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2787 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2788 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2789 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2790 | DECLARE_INSTRUCTION(TryBoundary); |
| 2791 | |
| 2792 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2793 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2794 | static constexpr size_t kFieldBoundaryKindSize = |
| 2795 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2796 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2797 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2798 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2799 | "Too many packed fields."); |
| 2800 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2801 | |
| 2802 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2803 | }; |
| 2804 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2805 | // Deoptimize to interpreter, upon checking a condition. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2806 | class HDeoptimize FINAL : public HTemplateInstruction<1> { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2807 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2808 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2809 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2810 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2811 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2812 | SetRawInputAt(0, cond); |
| 2813 | } |
| 2814 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2815 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2816 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2817 | return true; |
| 2818 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2819 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2820 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2821 | |
| 2822 | DECLARE_INSTRUCTION(Deoptimize); |
| 2823 | |
| 2824 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2825 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2826 | }; |
| 2827 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2828 | // Represents the ArtMethod that was passed as a first argument to |
| 2829 | // the method. It is used by instructions that depend on it, like |
| 2830 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2831 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2832 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2833 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2834 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2835 | |
| 2836 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2837 | |
| 2838 | private: |
| 2839 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2840 | }; |
| 2841 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2842 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2843 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2844 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2845 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2846 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2847 | kVTable, |
| 2848 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2849 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2850 | }; |
| 2851 | HClassTableGet(HInstruction* cls, |
| 2852 | Primitive::Type type, |
| 2853 | TableKind kind, |
| 2854 | size_t index, |
| 2855 | uint32_t dex_pc) |
| 2856 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2857 | index_(index) { |
| 2858 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2859 | SetRawInputAt(0, cls); |
| 2860 | } |
| 2861 | |
| 2862 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2863 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2864 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2865 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2866 | } |
| 2867 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2868 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2869 | size_t GetIndex() const { return index_; } |
| 2870 | |
| 2871 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2872 | |
| 2873 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2874 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2875 | static constexpr size_t kFieldTableKindSize = |
| 2876 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2877 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2878 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2879 | "Too many packed fields."); |
| 2880 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2881 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2882 | // The index of the ArtMethod in the table. |
| 2883 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2884 | |
| 2885 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2886 | }; |
| 2887 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2888 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2889 | // have one successor for each entry in the switch table, and the final successor |
| 2890 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2891 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2892 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2893 | HPackedSwitch(int32_t start_value, |
| 2894 | uint32_t num_entries, |
| 2895 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2896 | uint32_t dex_pc = kNoDexPc) |
| 2897 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2898 | start_value_(start_value), |
| 2899 | num_entries_(num_entries) { |
| 2900 | SetRawInputAt(0, input); |
| 2901 | } |
| 2902 | |
| 2903 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2904 | |
| 2905 | int32_t GetStartValue() const { return start_value_; } |
| 2906 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2907 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2908 | |
| 2909 | HBasicBlock* GetDefaultBlock() const { |
| 2910 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2911 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2912 | } |
| 2913 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2914 | |
| 2915 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2916 | const int32_t start_value_; |
| 2917 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2918 | |
| 2919 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2920 | }; |
| 2921 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2922 | class HUnaryOperation : public HExpression<1> { |
| 2923 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2924 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2925 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2926 | SetRawInputAt(0, input); |
| 2927 | } |
| 2928 | |
| 2929 | HInstruction* GetInput() const { return InputAt(0); } |
| 2930 | Primitive::Type GetResultType() const { return GetType(); } |
| 2931 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2932 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2933 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2934 | return true; |
| 2935 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2936 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2937 | // Try to statically evaluate `this` and return a HConstant |
| 2938 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2939 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2940 | HConstant* TryStaticEvaluation() const; |
| 2941 | |
| 2942 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2943 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2944 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2945 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 2946 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2947 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2948 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2949 | |
| 2950 | private: |
| 2951 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2952 | }; |
| 2953 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2954 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2955 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2956 | HBinaryOperation(Primitive::Type result_type, |
| 2957 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2958 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2959 | SideEffects side_effects = SideEffects::None(), |
| 2960 | uint32_t dex_pc = kNoDexPc) |
| 2961 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2962 | SetRawInputAt(0, left); |
| 2963 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2964 | } |
| 2965 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2966 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2967 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2968 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2969 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2970 | virtual bool IsCommutative() const { return false; } |
| 2971 | |
| 2972 | // Put constant on the right. |
| 2973 | // Returns whether order is changed. |
| 2974 | bool OrderInputsWithConstantOnTheRight() { |
| 2975 | HInstruction* left = InputAt(0); |
| 2976 | HInstruction* right = InputAt(1); |
| 2977 | if (left->IsConstant() && !right->IsConstant()) { |
| 2978 | ReplaceInput(right, 0); |
| 2979 | ReplaceInput(left, 1); |
| 2980 | return true; |
| 2981 | } |
| 2982 | return false; |
| 2983 | } |
| 2984 | |
| 2985 | // Order inputs by instruction id, but favor constant on the right side. |
| 2986 | // This helps GVN for commutative ops. |
| 2987 | void OrderInputs() { |
| 2988 | DCHECK(IsCommutative()); |
| 2989 | HInstruction* left = InputAt(0); |
| 2990 | HInstruction* right = InputAt(1); |
| 2991 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2992 | return; |
| 2993 | } |
| 2994 | if (OrderInputsWithConstantOnTheRight()) { |
| 2995 | return; |
| 2996 | } |
| 2997 | // Order according to instruction id. |
| 2998 | if (left->GetId() > right->GetId()) { |
| 2999 | ReplaceInput(right, 0); |
| 3000 | ReplaceInput(left, 1); |
| 3001 | } |
| 3002 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3003 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3004 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3005 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3006 | return true; |
| 3007 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3008 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3009 | // Try to statically evaluate `this` and return a HConstant |
| 3010 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3011 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3012 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3013 | |
| 3014 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3015 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3016 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3017 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3018 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3019 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3020 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3021 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3022 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3023 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3024 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3025 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3026 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3027 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3028 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3029 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3030 | // 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] | 3031 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3032 | HConstant* GetConstantRight() const; |
| 3033 | |
| 3034 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3035 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3036 | HInstruction* GetLeastConstantLeft() const; |
| 3037 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3038 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3039 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3040 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3041 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3042 | }; |
| 3043 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3044 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3045 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3046 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3047 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3048 | kGtBias, // return 1 for NaN comparisons |
| 3049 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3050 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3051 | }; |
| 3052 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3053 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3054 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3055 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3056 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3057 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3058 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3059 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3060 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3061 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3062 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3063 | // `instruction`, and disregard moves in between. |
| 3064 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3065 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3066 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3067 | |
| 3068 | virtual IfCondition GetCondition() const = 0; |
| 3069 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3070 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3071 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3072 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3073 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3074 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3075 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3076 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3077 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3078 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3079 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3080 | } |
| 3081 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3082 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3083 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3084 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3085 | if (if_cond == kCondNE) { |
| 3086 | return true; |
| 3087 | } else if (if_cond == kCondEQ) { |
| 3088 | return false; |
| 3089 | } |
| 3090 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3094 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3095 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3096 | if (if_cond == kCondEQ) { |
| 3097 | return true; |
| 3098 | } else if (if_cond == kCondNE) { |
| 3099 | return false; |
| 3100 | } |
| 3101 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3102 | } |
| 3103 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3104 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3105 | // Needed if we merge a HCompare into a HCondition. |
| 3106 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3107 | static constexpr size_t kFieldComparisonBiasSize = |
| 3108 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3109 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3110 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3111 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3112 | using ComparisonBiasField = |
| 3113 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3114 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3115 | template <typename T> |
| 3116 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3117 | |
| 3118 | template <typename T> |
| 3119 | int32_t CompareFP(T x, T y) const { |
| 3120 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3121 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3122 | // Handle the bias. |
| 3123 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3124 | } |
| 3125 | |
| 3126 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3127 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3128 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3129 | } |
| 3130 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3131 | private: |
| 3132 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3133 | }; |
| 3134 | |
| 3135 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3136 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3137 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3138 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3139 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3140 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3141 | bool IsCommutative() const OVERRIDE { return true; } |
| 3142 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3143 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3144 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3145 | return MakeConstantCondition(true, GetDexPc()); |
| 3146 | } |
| 3147 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3148 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3149 | } |
| 3150 | // In the following Evaluate methods, a HCompare instruction has |
| 3151 | // been merged into this HEqual instruction; evaluate it as |
| 3152 | // `Compare(x, y) == 0`. |
| 3153 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3154 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3155 | GetDexPc()); |
| 3156 | } |
| 3157 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3158 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3159 | } |
| 3160 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3161 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3162 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3163 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3164 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3165 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3166 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3167 | return kCondEQ; |
| 3168 | } |
| 3169 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3170 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3171 | return kCondNE; |
| 3172 | } |
| 3173 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3174 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3175 | template <typename T> static bool Compute(T x, T y) { return x == y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3176 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3177 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3178 | }; |
| 3179 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3180 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3181 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3182 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3183 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3184 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3185 | bool IsCommutative() const OVERRIDE { return true; } |
| 3186 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3187 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3188 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3189 | return MakeConstantCondition(false, GetDexPc()); |
| 3190 | } |
| 3191 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3192 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3193 | } |
| 3194 | // In the following Evaluate methods, a HCompare instruction has |
| 3195 | // been merged into this HNotEqual instruction; evaluate it as |
| 3196 | // `Compare(x, y) != 0`. |
| 3197 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3198 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3199 | } |
| 3200 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3201 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3202 | } |
| 3203 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3204 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3205 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3206 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3207 | DECLARE_INSTRUCTION(NotEqual); |
| 3208 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3209 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3210 | return kCondNE; |
| 3211 | } |
| 3212 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3213 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3214 | return kCondEQ; |
| 3215 | } |
| 3216 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3217 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3218 | template <typename T> static bool Compute(T x, T y) { return x != y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3219 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3220 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3221 | }; |
| 3222 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3223 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3224 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3225 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3226 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3227 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3228 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3229 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3230 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3231 | // In the following Evaluate methods, a HCompare instruction has |
| 3232 | // been merged into this HLessThan instruction; evaluate it as |
| 3233 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3234 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3235 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3236 | } |
| 3237 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3238 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3239 | } |
| 3240 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3241 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3242 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3243 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3244 | DECLARE_INSTRUCTION(LessThan); |
| 3245 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3246 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3247 | return kCondLT; |
| 3248 | } |
| 3249 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3250 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3251 | return kCondGE; |
| 3252 | } |
| 3253 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3254 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3255 | template <typename T> static bool Compute(T x, T y) { return x < y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3256 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3257 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3258 | }; |
| 3259 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3260 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3261 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3262 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3263 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3264 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3265 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3266 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3267 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3268 | // In the following Evaluate methods, a HCompare instruction has |
| 3269 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3270 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3271 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3272 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3273 | } |
| 3274 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3275 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3276 | } |
| 3277 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3278 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3279 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3280 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3281 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3282 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3283 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3284 | return kCondLE; |
| 3285 | } |
| 3286 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3287 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3288 | return kCondGT; |
| 3289 | } |
| 3290 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3291 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3292 | template <typename T> static bool Compute(T x, T y) { return x <= y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3293 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3294 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3295 | }; |
| 3296 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3297 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3298 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3299 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3300 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3301 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3302 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3303 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3304 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3305 | // In the following Evaluate methods, a HCompare instruction has |
| 3306 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3307 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3308 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3309 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3310 | } |
| 3311 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3312 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3313 | } |
| 3314 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3315 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3316 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3317 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3318 | DECLARE_INSTRUCTION(GreaterThan); |
| 3319 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3320 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3321 | return kCondGT; |
| 3322 | } |
| 3323 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3324 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3325 | return kCondLE; |
| 3326 | } |
| 3327 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3328 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3329 | template <typename T> static bool Compute(T x, T y) { return x > y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3330 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3331 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3332 | }; |
| 3333 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3334 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3335 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3336 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3337 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3338 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3339 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3340 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3341 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3342 | // In the following Evaluate methods, a HCompare instruction has |
| 3343 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3344 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3345 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3346 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3347 | } |
| 3348 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3349 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3350 | } |
| 3351 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3352 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3353 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3354 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3355 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3356 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3357 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3358 | return kCondGE; |
| 3359 | } |
| 3360 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3361 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3362 | return kCondLT; |
| 3363 | } |
| 3364 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3365 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3366 | template <typename T> static bool Compute(T x, T y) { return x >= y; } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3367 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3368 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3369 | }; |
| 3370 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3371 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3372 | public: |
| 3373 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3374 | : HCondition(first, second, dex_pc) {} |
| 3375 | |
| 3376 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3377 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3378 | } |
| 3379 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3380 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3381 | } |
| 3382 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3383 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3384 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3385 | UNREACHABLE(); |
| 3386 | } |
| 3387 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3388 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3389 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3390 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | DECLARE_INSTRUCTION(Below); |
| 3394 | |
| 3395 | IfCondition GetCondition() const OVERRIDE { |
| 3396 | return kCondB; |
| 3397 | } |
| 3398 | |
| 3399 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3400 | return kCondAE; |
| 3401 | } |
| 3402 | |
| 3403 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3404 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3405 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3406 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3407 | |
| 3408 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3409 | }; |
| 3410 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3411 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3412 | public: |
| 3413 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3414 | : HCondition(first, second, dex_pc) {} |
| 3415 | |
| 3416 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3417 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3418 | } |
| 3419 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3420 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3421 | } |
| 3422 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3423 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3424 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3425 | UNREACHABLE(); |
| 3426 | } |
| 3427 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3428 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3429 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3430 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3434 | |
| 3435 | IfCondition GetCondition() const OVERRIDE { |
| 3436 | return kCondBE; |
| 3437 | } |
| 3438 | |
| 3439 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3440 | return kCondA; |
| 3441 | } |
| 3442 | |
| 3443 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3444 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3445 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3446 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3447 | |
| 3448 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3449 | }; |
| 3450 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3451 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3452 | public: |
| 3453 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3454 | : HCondition(first, second, dex_pc) {} |
| 3455 | |
| 3456 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3457 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3458 | } |
| 3459 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3460 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3461 | } |
| 3462 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3463 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3464 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3465 | UNREACHABLE(); |
| 3466 | } |
| 3467 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3468 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3469 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3470 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3471 | } |
| 3472 | |
| 3473 | DECLARE_INSTRUCTION(Above); |
| 3474 | |
| 3475 | IfCondition GetCondition() const OVERRIDE { |
| 3476 | return kCondA; |
| 3477 | } |
| 3478 | |
| 3479 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3480 | return kCondBE; |
| 3481 | } |
| 3482 | |
| 3483 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3484 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3485 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3486 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3487 | |
| 3488 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3489 | }; |
| 3490 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3491 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3492 | public: |
| 3493 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3494 | : HCondition(first, second, dex_pc) {} |
| 3495 | |
| 3496 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3497 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3498 | } |
| 3499 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3500 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3501 | } |
| 3502 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3503 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3504 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3505 | UNREACHABLE(); |
| 3506 | } |
| 3507 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3508 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3509 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3510 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3514 | |
| 3515 | IfCondition GetCondition() const OVERRIDE { |
| 3516 | return kCondAE; |
| 3517 | } |
| 3518 | |
| 3519 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3520 | return kCondB; |
| 3521 | } |
| 3522 | |
| 3523 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3524 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3525 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3526 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3527 | |
| 3528 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3529 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3530 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3531 | // Instruction to check how two inputs compare to each other. |
| 3532 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3533 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3534 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3535 | // Note that `comparison_type` is the type of comparison performed |
| 3536 | // between the comparison's inputs, not the type of the instantiated |
| 3537 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3538 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3539 | HInstruction* first, |
| 3540 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3541 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3542 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3543 | : HBinaryOperation(Primitive::kPrimInt, |
| 3544 | first, |
| 3545 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3546 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3547 | dex_pc) { |
| 3548 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3549 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3550 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3551 | } |
| 3552 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3553 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3554 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3555 | |
| 3556 | template <typename T> |
| 3557 | int32_t ComputeFP(T x, T y) const { |
| 3558 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3559 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3560 | // Handle the bias. |
| 3561 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3562 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3563 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3564 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3565 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3566 | // reach this code path when processing a freshly built HIR |
| 3567 | // graph. However HCompare integer instructions can be synthesized |
| 3568 | // by the instruction simplifier to implement IntegerCompare and |
| 3569 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3570 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3571 | } |
| 3572 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3573 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3574 | } |
| 3575 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3576 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3577 | } |
| 3578 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3579 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3580 | } |
| 3581 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3582 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3583 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3584 | } |
| 3585 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3586 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3587 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3588 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3589 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3590 | bool IsGtBias() const { |
| 3591 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3592 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3593 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3594 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3595 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3596 | // Comparisons do not require a runtime call in any back end. |
| 3597 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3598 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3599 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3600 | DECLARE_INSTRUCTION(Compare); |
| 3601 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3602 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3603 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3604 | static constexpr size_t kFieldComparisonBiasSize = |
| 3605 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3606 | static constexpr size_t kNumberOfComparePackedBits = |
| 3607 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3608 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3609 | using ComparisonBiasField = |
| 3610 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3611 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3612 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3613 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3614 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3615 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3616 | } |
| 3617 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3618 | private: |
| 3619 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3620 | }; |
| 3621 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3622 | class HNewInstance FINAL : public HExpression<2> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3623 | public: |
| 3624 | HNewInstance(HInstruction* cls, |
| 3625 | HCurrentMethod* current_method, |
| 3626 | uint32_t dex_pc, |
| 3627 | uint16_t type_index, |
| 3628 | const DexFile& dex_file, |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3629 | bool needs_access_check, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3630 | bool finalizable, |
| 3631 | QuickEntrypointEnum entrypoint) |
| 3632 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3633 | type_index_(type_index), |
| 3634 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3635 | entrypoint_(entrypoint) { |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3636 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3637 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3638 | SetRawInputAt(0, cls); |
| 3639 | SetRawInputAt(1, current_method); |
| 3640 | } |
| 3641 | |
| 3642 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3643 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3644 | |
| 3645 | // Calls runtime so needs an environment. |
| 3646 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3647 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3648 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3649 | bool CanThrow() const OVERRIDE { return true; } |
| 3650 | |
| 3651 | // Needs to call into runtime to make sure it's instantiable/accessible. |
| 3652 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3653 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3654 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3655 | |
| 3656 | bool CanBeNull() const OVERRIDE { return false; } |
| 3657 | |
| 3658 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3659 | |
| 3660 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3661 | entrypoint_ = entrypoint; |
| 3662 | } |
| 3663 | |
| 3664 | bool IsStringAlloc() const; |
| 3665 | |
| 3666 | DECLARE_INSTRUCTION(NewInstance); |
| 3667 | |
| 3668 | private: |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3669 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfExpressionPackedBits; |
| 3670 | static constexpr size_t kFlagFinalizable = kFlagNeedsAccessCheck + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3671 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3672 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3673 | "Too many packed fields."); |
| 3674 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3675 | const uint16_t type_index_; |
| 3676 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3677 | QuickEntrypointEnum entrypoint_; |
| 3678 | |
| 3679 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3680 | }; |
| 3681 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3682 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3683 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3684 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3685 | #include "intrinsics_list.h" |
| 3686 | kNone, |
| 3687 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3688 | #undef INTRINSICS_LIST |
| 3689 | #undef OPTIMIZING_INTRINSICS |
| 3690 | }; |
| 3691 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3692 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3693 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3694 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3695 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3696 | }; |
| 3697 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3698 | enum IntrinsicSideEffects { |
| 3699 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3700 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3701 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3702 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3703 | }; |
| 3704 | |
| 3705 | enum IntrinsicExceptions { |
| 3706 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3707 | kCanThrow // Intrinsic may throw exceptions. |
| 3708 | }; |
| 3709 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3710 | class HInvoke : public HInstruction { |
| 3711 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3712 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3713 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3714 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 3715 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 3716 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 3717 | } |
| 3718 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3719 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3720 | SetRawInputAt(index, argument); |
| 3721 | } |
| 3722 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3723 | // Return the number of arguments. This number can be lower than |
| 3724 | // the number of inputs returned by InputCount(), as some invoke |
| 3725 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3726 | // inputs at the end of their list of inputs. |
| 3727 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3728 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3729 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3730 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3731 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3732 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3733 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3734 | InvokeType GetOriginalInvokeType() const { |
| 3735 | return GetPackedField<OriginalInvokeTypeField>(); |
| 3736 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3737 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3738 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3739 | return intrinsic_; |
| 3740 | } |
| 3741 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3742 | void SetIntrinsic(Intrinsics intrinsic, |
| 3743 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3744 | IntrinsicSideEffects side_effects, |
| 3745 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3746 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3747 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3748 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3749 | } |
| 3750 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3751 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3752 | |
| 3753 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3754 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3755 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3756 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3757 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3758 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3759 | uint32_t* GetIntrinsicOptimizations() { |
| 3760 | return &intrinsic_optimizations_; |
| 3761 | } |
| 3762 | |
| 3763 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3764 | return &intrinsic_optimizations_; |
| 3765 | } |
| 3766 | |
| 3767 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3768 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3769 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3770 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3771 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3772 | static constexpr size_t kFieldOriginalInvokeType = kNumberOfGenericPackedBits; |
| 3773 | static constexpr size_t kFieldOriginalInvokeTypeSize = |
| 3774 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3775 | static constexpr size_t kFieldReturnType = |
| 3776 | kFieldOriginalInvokeType + kFieldOriginalInvokeTypeSize; |
| 3777 | static constexpr size_t kFieldReturnTypeSize = |
| 3778 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3779 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3780 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3781 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3782 | using OriginalInvokeTypeField = |
| 3783 | BitField<InvokeType, kFieldOriginalInvokeType, kFieldOriginalInvokeTypeSize>; |
| 3784 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3785 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3786 | HInvoke(ArenaAllocator* arena, |
| 3787 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3788 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3789 | Primitive::Type return_type, |
| 3790 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3791 | uint32_t dex_method_index, |
| 3792 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3793 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3794 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3795 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3796 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3797 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3798 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3799 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3800 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3801 | SetPackedField<ReturnTypeField>(return_type); |
| 3802 | SetPackedField<OriginalInvokeTypeField>(original_invoke_type); |
| 3803 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3804 | } |
| 3805 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3806 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3807 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3808 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3809 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3810 | const uint32_t dex_method_index_; |
| 3811 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3812 | |
| 3813 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3814 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3815 | |
| 3816 | private: |
| 3817 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3818 | }; |
| 3819 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3820 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3821 | public: |
| 3822 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3823 | uint32_t number_of_arguments, |
| 3824 | Primitive::Type return_type, |
| 3825 | uint32_t dex_pc, |
| 3826 | uint32_t dex_method_index, |
| 3827 | InvokeType invoke_type) |
| 3828 | : HInvoke(arena, |
| 3829 | number_of_arguments, |
| 3830 | 0u /* number_of_other_inputs */, |
| 3831 | return_type, |
| 3832 | dex_pc, |
| 3833 | dex_method_index, |
| 3834 | invoke_type) { |
| 3835 | } |
| 3836 | |
| 3837 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3838 | |
| 3839 | private: |
| 3840 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3841 | }; |
| 3842 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3843 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3844 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3845 | // Requirements of this method call regarding the class |
| 3846 | // initialization (clinit) check of its declaring class. |
| 3847 | enum class ClinitCheckRequirement { |
| 3848 | kNone, // Class already initialized. |
| 3849 | kExplicit, // Static call having explicit clinit check as last input. |
| 3850 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3851 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3852 | }; |
| 3853 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3854 | // Determines how to load the target ArtMethod*. |
| 3855 | enum class MethodLoadKind { |
| 3856 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3857 | kStringInit, |
| 3858 | |
| 3859 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3860 | kRecursive, |
| 3861 | |
| 3862 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3863 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3864 | kDirectAddress, |
| 3865 | |
| 3866 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3867 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3868 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3869 | // the image relocatable or not. |
| 3870 | kDirectAddressWithFixup, |
| 3871 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3872 | // Load from resolved methods array in the dex cache using a PC-relative load. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3873 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3874 | // may cause class initialization (the entry may point to a resolution method), |
| 3875 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3876 | kDexCachePcRelative, |
| 3877 | |
| 3878 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3879 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3880 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3881 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3882 | kDexCacheViaMethod, |
| 3883 | }; |
| 3884 | |
| 3885 | // Determines the location of the code pointer. |
| 3886 | enum class CodePtrLocation { |
| 3887 | // Recursive call, use local PC-relative call instruction. |
| 3888 | kCallSelf, |
| 3889 | |
| 3890 | // Use PC-relative call instruction patched at link time. |
| 3891 | // Used for calls within an oat file, boot->boot or app->app. |
| 3892 | kCallPCRelative, |
| 3893 | |
| 3894 | // Call to a known target address, embed the direct address in code. |
| 3895 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3896 | kCallDirect, |
| 3897 | |
| 3898 | // Call to a target address that will be known at link time, embed the direct |
| 3899 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3900 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3901 | // the image relocatable or not. |
| 3902 | kCallDirectWithFixup, |
| 3903 | |
| 3904 | // Use code pointer from the ArtMethod*. |
| 3905 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3906 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3907 | kCallArtMethod, |
| 3908 | }; |
| 3909 | |
| 3910 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3911 | MethodLoadKind method_load_kind; |
| 3912 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3913 | // The method load data holds |
| 3914 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3915 | // Note that there are multiple string init methods, each having its own offset. |
| 3916 | // - the method address for kDirectAddress |
| 3917 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3918 | uint64_t method_load_data; |
| 3919 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3920 | }; |
| 3921 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3922 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3923 | uint32_t number_of_arguments, |
| 3924 | Primitive::Type return_type, |
| 3925 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3926 | uint32_t method_index, |
| 3927 | MethodReference target_method, |
| 3928 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3929 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3930 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3931 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3932 | : HInvoke(arena, |
| 3933 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3934 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3935 | // potentially one other if the clinit check is explicit, and potentially |
| 3936 | // one other if the method is a string factory. |
| 3937 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3938 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3939 | return_type, |
| 3940 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3941 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3942 | original_invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3943 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3944 | dispatch_info_(dispatch_info) { |
| 3945 | SetPackedField<OptimizedInvokeTypeField>(optimized_invoke_type); |
| 3946 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 3947 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3948 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3949 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3950 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3951 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3952 | |
| 3953 | // Using the current method is the default and once we find a better |
| 3954 | // method load kind, we should not go back to using the current method. |
| 3955 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3956 | |
| 3957 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3958 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3959 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3960 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3961 | dispatch_info_ = dispatch_info; |
| 3962 | } |
| 3963 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3964 | void AddSpecialInput(HInstruction* input) { |
| 3965 | // We allow only one special input. |
| 3966 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3967 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3968 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3969 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3970 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3971 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3972 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 3973 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 3974 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 3975 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 3976 | DCHECK(!input_records.empty()); |
| 3977 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 3978 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 3979 | // Note: `last_input` may be null during arguments setup. |
| 3980 | if (last_input != nullptr) { |
| 3981 | // `last_input` is the last input of a static invoke marked as having |
| 3982 | // an explicit clinit check. It must either be: |
| 3983 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3984 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3985 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 3986 | } |
| 3987 | } |
| 3988 | return input_records; |
| 3989 | } |
| 3990 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3991 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3992 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3993 | // TODO: for intrinsics we can generate implicit null checks. |
| 3994 | return false; |
| 3995 | } |
| 3996 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3997 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3998 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3999 | } |
| 4000 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4001 | // Get the index of the special input, if any. |
| 4002 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4003 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4004 | // method pointer; otherwise there may be one platform-specific special input, |
| 4005 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4006 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4007 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4008 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4009 | InvokeType GetOptimizedInvokeType() const { |
| 4010 | return GetPackedField<OptimizedInvokeTypeField>(); |
| 4011 | } |
| 4012 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4013 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4014 | SetPackedField<OptimizedInvokeTypeField>(invoke_type); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4015 | } |
| 4016 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4017 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4018 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4019 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4020 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4021 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4022 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4023 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4024 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 4025 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4026 | bool HasCurrentMethodInput() const { |
| 4027 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4028 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4029 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4030 | return true; |
| 4031 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4032 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4033 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4034 | return false; |
| 4035 | } |
| 4036 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4037 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 4038 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4039 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4040 | |
| 4041 | int32_t GetStringInitOffset() const { |
| 4042 | DCHECK(IsStringInit()); |
| 4043 | return dispatch_info_.method_load_data; |
| 4044 | } |
| 4045 | |
| 4046 | uint64_t GetMethodAddress() const { |
| 4047 | DCHECK(HasMethodAddress()); |
| 4048 | return dispatch_info_.method_load_data; |
| 4049 | } |
| 4050 | |
| 4051 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4052 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4053 | return dispatch_info_.method_load_data; |
| 4054 | } |
| 4055 | |
| 4056 | uint64_t GetDirectCodePtr() const { |
| 4057 | DCHECK(HasDirectCodePtr()); |
| 4058 | return dispatch_info_.direct_code_ptr; |
| 4059 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4060 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4061 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4062 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4063 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4064 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4065 | // Is this instruction a call to a static method? |
| 4066 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4067 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4068 | } |
| 4069 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4070 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4071 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4072 | // instruction; only relevant for static calls with explicit clinit check. |
| 4073 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4074 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4075 | size_t last_input_index = inputs_.size() - 1u; |
| 4076 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4077 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4078 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4079 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4080 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4081 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4082 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | // 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] | 4086 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4087 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4088 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | // Is this a call to a static method whose declaring class has an |
| 4092 | // implicit intialization check requirement? |
| 4093 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4094 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4095 | } |
| 4096 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4097 | // Does this method load kind need the current method as an input? |
| 4098 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4099 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4100 | } |
| 4101 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4102 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4103 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4104 | protected: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4105 | void InsertInputAt(size_t index, HInstruction* input); |
| 4106 | void RemoveInputAt(size_t index); |
| 4107 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4108 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4109 | static constexpr size_t kFieldOptimizedInvokeType = kNumberOfInvokePackedBits; |
| 4110 | static constexpr size_t kFieldOptimizedInvokeTypeSize = |
| 4111 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4112 | static constexpr size_t kFieldClinitCheckRequirement = |
| 4113 | kFieldOptimizedInvokeType + kFieldOptimizedInvokeTypeSize; |
| 4114 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4115 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4116 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4117 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4118 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4119 | "Too many packed fields."); |
| 4120 | using OptimizedInvokeTypeField = |
| 4121 | BitField<InvokeType, kFieldOptimizedInvokeType, kFieldOptimizedInvokeTypeSize>; |
| 4122 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4123 | kFieldClinitCheckRequirement, |
| 4124 | kFieldClinitCheckRequirementSize>; |
| 4125 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4126 | // The target method may refer to different dex file or method index than the original |
| 4127 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 4128 | // in derived class to increase visibility. |
| 4129 | MethodReference target_method_; |
| 4130 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4131 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4132 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4133 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4134 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4135 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4136 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4137 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4138 | public: |
| 4139 | HInvokeVirtual(ArenaAllocator* arena, |
| 4140 | uint32_t number_of_arguments, |
| 4141 | Primitive::Type return_type, |
| 4142 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4143 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4144 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4145 | : HInvoke(arena, number_of_arguments, 0u, return_type, dex_pc, dex_method_index, kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4146 | vtable_index_(vtable_index) {} |
| 4147 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4148 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4149 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4150 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4151 | } |
| 4152 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4153 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4154 | |
| 4155 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4156 | |
| 4157 | private: |
| 4158 | const uint32_t vtable_index_; |
| 4159 | |
| 4160 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4161 | }; |
| 4162 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4163 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4164 | public: |
| 4165 | HInvokeInterface(ArenaAllocator* arena, |
| 4166 | uint32_t number_of_arguments, |
| 4167 | Primitive::Type return_type, |
| 4168 | uint32_t dex_pc, |
| 4169 | uint32_t dex_method_index, |
| 4170 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4171 | : HInvoke(arena, number_of_arguments, 0u, return_type, dex_pc, dex_method_index, kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4172 | imt_index_(imt_index) {} |
| 4173 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4174 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4175 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4176 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4177 | } |
| 4178 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4179 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4180 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4181 | |
| 4182 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4183 | |
| 4184 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4185 | const uint32_t imt_index_; |
| 4186 | |
| 4187 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4188 | }; |
| 4189 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4190 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4191 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4192 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4193 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4194 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4195 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4196 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4197 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4198 | |
| 4199 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4200 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4201 | } |
| 4202 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4203 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4204 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4205 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4206 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4207 | } |
| 4208 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4209 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4210 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4211 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4212 | DECLARE_INSTRUCTION(Neg); |
| 4213 | |
| 4214 | private: |
| 4215 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4216 | }; |
| 4217 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4218 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4219 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4220 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4221 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4222 | uint32_t dex_pc, |
| 4223 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4224 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4225 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4226 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4227 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4228 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4229 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4230 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4231 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4232 | } |
| 4233 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4234 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4235 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4236 | |
| 4237 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4238 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4239 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4240 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4241 | bool CanThrow() const OVERRIDE { return true; } |
| 4242 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4243 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4244 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4245 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4246 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4247 | DECLARE_INSTRUCTION(NewArray); |
| 4248 | |
| 4249 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4250 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4251 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4252 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4253 | |
| 4254 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4255 | }; |
| 4256 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4257 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4258 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4259 | HAdd(Primitive::Type result_type, |
| 4260 | HInstruction* left, |
| 4261 | HInstruction* right, |
| 4262 | uint32_t dex_pc = kNoDexPc) |
| 4263 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4264 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4265 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4266 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4267 | 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] | 4268 | |
| 4269 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4270 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4271 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4272 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4273 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4274 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4275 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4276 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4277 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4278 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4279 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4280 | } |
| 4281 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4282 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4283 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4284 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4285 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4286 | DECLARE_INSTRUCTION(Add); |
| 4287 | |
| 4288 | private: |
| 4289 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4290 | }; |
| 4291 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4292 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4293 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4294 | HSub(Primitive::Type result_type, |
| 4295 | HInstruction* left, |
| 4296 | HInstruction* right, |
| 4297 | uint32_t dex_pc = kNoDexPc) |
| 4298 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4299 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4300 | 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] | 4301 | |
| 4302 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4303 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4304 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4305 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4306 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4307 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4308 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4309 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4310 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4311 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4312 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4313 | } |
| 4314 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4315 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4316 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4317 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4318 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4319 | DECLARE_INSTRUCTION(Sub); |
| 4320 | |
| 4321 | private: |
| 4322 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4323 | }; |
| 4324 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4325 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4326 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4327 | HMul(Primitive::Type result_type, |
| 4328 | HInstruction* left, |
| 4329 | HInstruction* right, |
| 4330 | uint32_t dex_pc = kNoDexPc) |
| 4331 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4332 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4333 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4334 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4335 | 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] | 4336 | |
| 4337 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4338 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4339 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4340 | } |
| 4341 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4342 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4343 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4344 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4345 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4346 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4347 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4348 | } |
| 4349 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4350 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4351 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4352 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4353 | |
| 4354 | DECLARE_INSTRUCTION(Mul); |
| 4355 | |
| 4356 | private: |
| 4357 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4358 | }; |
| 4359 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4360 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4361 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4362 | HDiv(Primitive::Type result_type, |
| 4363 | HInstruction* left, |
| 4364 | HInstruction* right, |
| 4365 | uint32_t dex_pc) |
| 4366 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4367 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4368 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4369 | T ComputeIntegral(T x, T y) const { |
| 4370 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4371 | // Our graph structure ensures we never have 0 for `y` during |
| 4372 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4373 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4374 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4375 | return (y == -1) ? -x : x / y; |
| 4376 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4377 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4378 | template <typename T> |
| 4379 | T ComputeFP(T x, T y) const { |
| 4380 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4381 | return x / y; |
| 4382 | } |
| 4383 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4384 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4385 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4386 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4387 | } |
| 4388 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4389 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4390 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4391 | } |
| 4392 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4393 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4394 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4395 | } |
| 4396 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4397 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4398 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4399 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4400 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4401 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4402 | // The generated code can use a runtime call. |
| 4403 | return SideEffects::CanTriggerGC(); |
| 4404 | } |
| 4405 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4406 | DECLARE_INSTRUCTION(Div); |
| 4407 | |
| 4408 | private: |
| 4409 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4410 | }; |
| 4411 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4412 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4413 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4414 | HRem(Primitive::Type result_type, |
| 4415 | HInstruction* left, |
| 4416 | HInstruction* right, |
| 4417 | uint32_t dex_pc) |
| 4418 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4419 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4420 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4421 | T ComputeIntegral(T x, T y) const { |
| 4422 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4423 | // Our graph structure ensures we never have 0 for `y` during |
| 4424 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4425 | DCHECK_NE(y, 0); |
| 4426 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4427 | return (y == -1) ? 0 : x % y; |
| 4428 | } |
| 4429 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4430 | template <typename T> |
| 4431 | T ComputeFP(T x, T y) const { |
| 4432 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4433 | return std::fmod(x, y); |
| 4434 | } |
| 4435 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4436 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4437 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4438 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4439 | } |
| 4440 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4441 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4442 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4443 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4444 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4445 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4446 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4447 | } |
| 4448 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4449 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4450 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4451 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4452 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4453 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4454 | return SideEffects::CanTriggerGC(); |
| 4455 | } |
| 4456 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4457 | DECLARE_INSTRUCTION(Rem); |
| 4458 | |
| 4459 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4460 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4461 | }; |
| 4462 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4463 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4464 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4465 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4466 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4467 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4468 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4469 | SetRawInputAt(0, value); |
| 4470 | } |
| 4471 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4472 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4473 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4474 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4475 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4476 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4477 | return true; |
| 4478 | } |
| 4479 | |
| 4480 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4481 | bool CanThrow() const OVERRIDE { return true; } |
| 4482 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4483 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4484 | |
| 4485 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4486 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4487 | }; |
| 4488 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4489 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4490 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4491 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4492 | HInstruction* value, |
| 4493 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4494 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4495 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4496 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4497 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4498 | } |
| 4499 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4500 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4501 | 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] | 4502 | return value << (distance & max_shift_distance); |
| 4503 | } |
| 4504 | |
| 4505 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4506 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4507 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4508 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4509 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4510 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4511 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4512 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4513 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4514 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4515 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4516 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4517 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4518 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4519 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4520 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4521 | UNREACHABLE(); |
| 4522 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4523 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4524 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4525 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4526 | UNREACHABLE(); |
| 4527 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4528 | |
| 4529 | DECLARE_INSTRUCTION(Shl); |
| 4530 | |
| 4531 | private: |
| 4532 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4533 | }; |
| 4534 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4535 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4536 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4537 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4538 | HInstruction* value, |
| 4539 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4540 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4541 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4542 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4543 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4544 | } |
| 4545 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4546 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4547 | 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] | 4548 | return value >> (distance & max_shift_distance); |
| 4549 | } |
| 4550 | |
| 4551 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4552 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4553 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4554 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4555 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4556 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4557 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4558 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4559 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4560 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4561 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4562 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4563 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4564 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4565 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4566 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4567 | UNREACHABLE(); |
| 4568 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4569 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4570 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4571 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4572 | UNREACHABLE(); |
| 4573 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4574 | |
| 4575 | DECLARE_INSTRUCTION(Shr); |
| 4576 | |
| 4577 | private: |
| 4578 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4579 | }; |
| 4580 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4581 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4582 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4583 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4584 | HInstruction* value, |
| 4585 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4586 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4587 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4588 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4589 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4590 | } |
| 4591 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4592 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4593 | 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] | 4594 | typedef typename std::make_unsigned<T>::type V; |
| 4595 | V ux = static_cast<V>(value); |
| 4596 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4597 | } |
| 4598 | |
| 4599 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4600 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4601 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4602 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4603 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4604 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4605 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4606 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4607 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4608 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4609 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4610 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4611 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4612 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4613 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4614 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4615 | UNREACHABLE(); |
| 4616 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4617 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4618 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4619 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4620 | UNREACHABLE(); |
| 4621 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4622 | |
| 4623 | DECLARE_INSTRUCTION(UShr); |
| 4624 | |
| 4625 | private: |
| 4626 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4627 | }; |
| 4628 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4629 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4630 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4631 | HAnd(Primitive::Type result_type, |
| 4632 | HInstruction* left, |
| 4633 | HInstruction* right, |
| 4634 | uint32_t dex_pc = kNoDexPc) |
| 4635 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4636 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4637 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4638 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4639 | 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] | 4640 | |
| 4641 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4642 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4643 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4644 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4645 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4646 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4647 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4648 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4649 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4650 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4651 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4652 | UNREACHABLE(); |
| 4653 | } |
| 4654 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4655 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4656 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4657 | UNREACHABLE(); |
| 4658 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4659 | |
| 4660 | DECLARE_INSTRUCTION(And); |
| 4661 | |
| 4662 | private: |
| 4663 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4664 | }; |
| 4665 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4666 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4667 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4668 | HOr(Primitive::Type result_type, |
| 4669 | HInstruction* left, |
| 4670 | HInstruction* right, |
| 4671 | uint32_t dex_pc = kNoDexPc) |
| 4672 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4673 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4674 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4675 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4676 | 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] | 4677 | |
| 4678 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4679 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4680 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4681 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4682 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4683 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4684 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4685 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4686 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4687 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4688 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4689 | UNREACHABLE(); |
| 4690 | } |
| 4691 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4692 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4693 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4694 | UNREACHABLE(); |
| 4695 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4696 | |
| 4697 | DECLARE_INSTRUCTION(Or); |
| 4698 | |
| 4699 | private: |
| 4700 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4701 | }; |
| 4702 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4703 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4704 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4705 | HXor(Primitive::Type result_type, |
| 4706 | HInstruction* left, |
| 4707 | HInstruction* right, |
| 4708 | uint32_t dex_pc = kNoDexPc) |
| 4709 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4710 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4711 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4712 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4713 | 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] | 4714 | |
| 4715 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4716 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4717 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4718 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4719 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4720 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4721 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4722 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4723 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4724 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4725 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4726 | UNREACHABLE(); |
| 4727 | } |
| 4728 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4729 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4730 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4731 | UNREACHABLE(); |
| 4732 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4733 | |
| 4734 | DECLARE_INSTRUCTION(Xor); |
| 4735 | |
| 4736 | private: |
| 4737 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4738 | }; |
| 4739 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4740 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4741 | public: |
| 4742 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4743 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4744 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4745 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4746 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4747 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4748 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4749 | static T Compute(T value, int32_t distance, int32_t max_shift_value) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4750 | typedef typename std::make_unsigned<T>::type V; |
| 4751 | V ux = static_cast<V>(value); |
| 4752 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4753 | return static_cast<T>(ux); |
| 4754 | } else { |
| 4755 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4756 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4757 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4758 | } |
| 4759 | } |
| 4760 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4761 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4762 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4763 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4764 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4765 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4766 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4767 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4768 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4769 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4770 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4771 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4772 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4773 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4774 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4775 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4776 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4777 | UNREACHABLE(); |
| 4778 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4779 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4780 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4781 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4782 | UNREACHABLE(); |
| 4783 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4784 | |
| 4785 | DECLARE_INSTRUCTION(Ror); |
| 4786 | |
| 4787 | private: |
| 4788 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4789 | }; |
| 4790 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4791 | // The value of a parameter in this method. Its location depends on |
| 4792 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4793 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4794 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4795 | HParameterValue(const DexFile& dex_file, |
| 4796 | uint16_t type_index, |
| 4797 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4798 | Primitive::Type parameter_type, |
| 4799 | bool is_this = false) |
| 4800 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4801 | dex_file_(dex_file), |
| 4802 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4803 | index_(index) { |
| 4804 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4805 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4806 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4807 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4808 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4809 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4810 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4811 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4812 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4813 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4814 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4815 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4816 | DECLARE_INSTRUCTION(ParameterValue); |
| 4817 | |
| 4818 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4819 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4820 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4821 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4822 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4823 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4824 | "Too many packed fields."); |
| 4825 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4826 | const DexFile& dex_file_; |
| 4827 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4828 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4829 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4830 | const uint8_t index_; |
| 4831 | |
| 4832 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4833 | }; |
| 4834 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4835 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4836 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4837 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4838 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4839 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4840 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4841 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4842 | return true; |
| 4843 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4844 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4845 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4846 | |
| 4847 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4848 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4849 | } |
| 4850 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4851 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4852 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4853 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4854 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4855 | UNREACHABLE(); |
| 4856 | } |
| 4857 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4858 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4859 | UNREACHABLE(); |
| 4860 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4861 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4862 | DECLARE_INSTRUCTION(Not); |
| 4863 | |
| 4864 | private: |
| 4865 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4866 | }; |
| 4867 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4868 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4869 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4870 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4871 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4872 | |
| 4873 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4874 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4875 | return true; |
| 4876 | } |
| 4877 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4878 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4879 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4880 | return !x; |
| 4881 | } |
| 4882 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4883 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4884 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4885 | } |
| 4886 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4887 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4888 | UNREACHABLE(); |
| 4889 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4890 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4891 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4892 | UNREACHABLE(); |
| 4893 | } |
| 4894 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4895 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4896 | UNREACHABLE(); |
| 4897 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4898 | |
| 4899 | DECLARE_INSTRUCTION(BooleanNot); |
| 4900 | |
| 4901 | private: |
| 4902 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4903 | }; |
| 4904 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4905 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4906 | public: |
| 4907 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4908 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4909 | : HExpression(result_type, |
| 4910 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4911 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4912 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 4913 | // Invariant: We should never generate a conversion to a Boolean value. |
| 4914 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | HInstruction* GetInput() const { return InputAt(0); } |
| 4918 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4919 | Primitive::Type GetResultType() const { return GetType(); } |
| 4920 | |
| 4921 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4922 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4923 | return true; |
| 4924 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4925 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4926 | // Try to statically evaluate the conversion and return a HConstant |
| 4927 | // containing the result. If the input cannot be converted, return nullptr. |
| 4928 | HConstant* TryStaticEvaluation() const; |
| 4929 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4930 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4931 | Primitive::Type result_type) { |
| 4932 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4933 | // in the compilation process we do not know what architecture we will |
| 4934 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4935 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4936 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4937 | return SideEffects::CanTriggerGC(); |
| 4938 | } |
| 4939 | return SideEffects::None(); |
| 4940 | } |
| 4941 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4942 | DECLARE_INSTRUCTION(TypeConversion); |
| 4943 | |
| 4944 | private: |
| 4945 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4946 | }; |
| 4947 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4948 | static constexpr uint32_t kNoRegNumber = -1; |
| 4949 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4950 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4951 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4952 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4953 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4954 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4955 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4956 | SetRawInputAt(0, value); |
| 4957 | } |
| 4958 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4959 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4960 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4961 | return true; |
| 4962 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4963 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4964 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4965 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4966 | bool CanThrow() const OVERRIDE { return true; } |
| 4967 | |
| 4968 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4969 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4970 | |
| 4971 | DECLARE_INSTRUCTION(NullCheck); |
| 4972 | |
| 4973 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4974 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4975 | }; |
| 4976 | |
| 4977 | class FieldInfo : public ValueObject { |
| 4978 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4979 | FieldInfo(MemberOffset field_offset, |
| 4980 | Primitive::Type field_type, |
| 4981 | bool is_volatile, |
| 4982 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4983 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4984 | const DexFile& dex_file, |
| 4985 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4986 | : field_offset_(field_offset), |
| 4987 | field_type_(field_type), |
| 4988 | is_volatile_(is_volatile), |
| 4989 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4990 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4991 | dex_file_(dex_file), |
| 4992 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4993 | |
| 4994 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4995 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4996 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4997 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4998 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4999 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5000 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5001 | |
| 5002 | private: |
| 5003 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5004 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5005 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5006 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5007 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5008 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5009 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5010 | }; |
| 5011 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5012 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5013 | public: |
| 5014 | HInstanceFieldGet(HInstruction* value, |
| 5015 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5016 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5017 | bool is_volatile, |
| 5018 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5019 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5020 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5021 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5022 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5023 | : HExpression(field_type, |
| 5024 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5025 | dex_pc), |
| 5026 | field_info_(field_offset, |
| 5027 | field_type, |
| 5028 | is_volatile, |
| 5029 | field_idx, |
| 5030 | declaring_class_def_index, |
| 5031 | dex_file, |
| 5032 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5033 | SetRawInputAt(0, value); |
| 5034 | } |
| 5035 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5036 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5037 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5038 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5039 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5040 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5041 | } |
| 5042 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5043 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5044 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5048 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5049 | } |
| 5050 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5051 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5052 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5053 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5054 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5055 | |
| 5056 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5057 | |
| 5058 | private: |
| 5059 | const FieldInfo field_info_; |
| 5060 | |
| 5061 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5062 | }; |
| 5063 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5064 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5065 | public: |
| 5066 | HInstanceFieldSet(HInstruction* object, |
| 5067 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5068 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5069 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5070 | bool is_volatile, |
| 5071 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5072 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5073 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5074 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5075 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5076 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5077 | dex_pc), |
| 5078 | field_info_(field_offset, |
| 5079 | field_type, |
| 5080 | is_volatile, |
| 5081 | field_idx, |
| 5082 | declaring_class_def_index, |
| 5083 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5084 | dex_cache) { |
| 5085 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5086 | SetRawInputAt(0, object); |
| 5087 | SetRawInputAt(1, value); |
| 5088 | } |
| 5089 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5090 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5091 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5092 | } |
| 5093 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5094 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5095 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5096 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5097 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5098 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5099 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5100 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5101 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5102 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5103 | |
| 5104 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5105 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5106 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5107 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5108 | "Too many packed fields."); |
| 5109 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5110 | const FieldInfo field_info_; |
| 5111 | |
| 5112 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5113 | }; |
| 5114 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5115 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5116 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5117 | HArrayGet(HInstruction* array, |
| 5118 | HInstruction* index, |
| 5119 | Primitive::Type type, |
| 5120 | uint32_t dex_pc, |
| 5121 | bool is_string_char_at = false) |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5122 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5123 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5124 | SetRawInputAt(0, array); |
| 5125 | SetRawInputAt(1, index); |
| 5126 | } |
| 5127 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5128 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5129 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5130 | return true; |
| 5131 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5132 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5133 | // TODO: We can be smarter here. |
| 5134 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5135 | // which generates the implicit null check. There are cases when these can be removed |
| 5136 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5137 | // implicit check here (as long as the address falls in the first page). |
| 5138 | return false; |
| 5139 | } |
| 5140 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5141 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5142 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5143 | if (kIsDebugBuild && result) { |
| 5144 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5145 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5146 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5147 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5148 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5149 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5150 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5151 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5152 | } |
| 5153 | } |
| 5154 | return result; |
| 5155 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5156 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5157 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5158 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5159 | HInstruction* GetArray() const { return InputAt(0); } |
| 5160 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5161 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5162 | DECLARE_INSTRUCTION(ArrayGet); |
| 5163 | |
| 5164 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5165 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5166 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5167 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5168 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5169 | // a flag, so that code generators don't need to do the locking. |
| 5170 | static constexpr size_t kFlagIsStringCharAt = kNumberOfExpressionPackedBits; |
| 5171 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5172 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5173 | "Too many packed fields."); |
| 5174 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5175 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5176 | }; |
| 5177 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5178 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5179 | public: |
| 5180 | HArraySet(HInstruction* array, |
| 5181 | HInstruction* index, |
| 5182 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5183 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5184 | uint32_t dex_pc) |
| 5185 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5186 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5187 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5188 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5189 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5190 | SetRawInputAt(0, array); |
| 5191 | SetRawInputAt(1, index); |
| 5192 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5193 | // Make a best guess now, may be refined during SSA building. |
| 5194 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5195 | } |
| 5196 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5197 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5198 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5199 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5200 | } |
| 5201 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5202 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5203 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5204 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5205 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5206 | // TODO: Same as for ArrayGet. |
| 5207 | return false; |
| 5208 | } |
| 5209 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5210 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5211 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5212 | } |
| 5213 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5214 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5215 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5216 | } |
| 5217 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5218 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5219 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5220 | } |
| 5221 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5222 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5223 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5224 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5225 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5226 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5227 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5228 | HInstruction* GetArray() const { return InputAt(0); } |
| 5229 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5230 | HInstruction* GetValue() const { return InputAt(2); } |
| 5231 | |
| 5232 | Primitive::Type GetComponentType() const { |
| 5233 | // The Dex format does not type floating point index operations. Since the |
| 5234 | // `expected_component_type_` is set during building and can therefore not |
| 5235 | // be correct, we also check what is the value type. If it is a floating |
| 5236 | // point type, we must use that type. |
| 5237 | Primitive::Type value_type = GetValue()->GetType(); |
| 5238 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5239 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5240 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5241 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5242 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5243 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5244 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5245 | } |
| 5246 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5247 | void ComputeSideEffects() { |
| 5248 | Primitive::Type type = GetComponentType(); |
| 5249 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5250 | SideEffectsForArchRuntimeCalls(type))); |
| 5251 | } |
| 5252 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5253 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5254 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5255 | } |
| 5256 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5257 | DECLARE_INSTRUCTION(ArraySet); |
| 5258 | |
| 5259 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5260 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5261 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5262 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5263 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5264 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5265 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5266 | // Cached information for the reference_type_info_ so that codegen |
| 5267 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5268 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5269 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5270 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5271 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5272 | using ExpectedComponentTypeField = |
| 5273 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5274 | |
| 5275 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5276 | }; |
| 5277 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5278 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5279 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5280 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5281 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5282 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5283 | // Note that arrays do not change length, so the instruction does not |
| 5284 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5285 | SetRawInputAt(0, array); |
| 5286 | } |
| 5287 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5288 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5289 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5290 | return true; |
| 5291 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5292 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5293 | return obj == InputAt(0); |
| 5294 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5295 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5296 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5297 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5298 | DECLARE_INSTRUCTION(ArrayLength); |
| 5299 | |
| 5300 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5301 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5302 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5303 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5304 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5305 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5306 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5307 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5308 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5309 | "Too many packed fields."); |
| 5310 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5311 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5312 | }; |
| 5313 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5314 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5315 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5316 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5317 | // constructor. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5318 | HBoundsCheck(HInstruction* index, |
| 5319 | HInstruction* length, |
| 5320 | uint32_t dex_pc, |
| 5321 | uint32_t string_char_at_method_index = DexFile::kDexNoIndex) |
| 5322 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc), |
| 5323 | string_char_at_method_index_(string_char_at_method_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5324 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5325 | SetRawInputAt(0, index); |
| 5326 | SetRawInputAt(1, length); |
| 5327 | } |
| 5328 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5329 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5330 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5331 | return true; |
| 5332 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5333 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5334 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5335 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5336 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5337 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5338 | bool IsStringCharAt() const { return GetStringCharAtMethodIndex() != DexFile::kDexNoIndex; } |
| 5339 | uint32_t GetStringCharAtMethodIndex() const { return string_char_at_method_index_; } |
| 5340 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5341 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5342 | |
| 5343 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5344 | |
| 5345 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5346 | // We treat a String as an array, creating the HBoundsCheck from String.charAt() |
| 5347 | // intrinsic in the instruction simplifier. We want to include the String.charAt() |
| 5348 | // in the stack trace if we actually throw the StringIndexOutOfBoundsException, |
| 5349 | // so we need to create an HEnvironment which will be translated to an InlineInfo |
| 5350 | // indicating the extra stack frame. Since we add this HEnvironment quite late, |
| 5351 | // in the PrepareForRegisterAllocation pass, we need to remember the method index |
| 5352 | // from the invoke as we don't want to look again at the dex bytecode. |
| 5353 | uint32_t string_char_at_method_index_; // DexFile::kDexNoIndex if regular array. |
| 5354 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5355 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5356 | }; |
| 5357 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5358 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5359 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5360 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5361 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5362 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5363 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5364 | return true; |
| 5365 | } |
| 5366 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5367 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5368 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5369 | |
| 5370 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5371 | |
| 5372 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5373 | // Only used for code generation, in order to share the same slow path between back edges |
| 5374 | // of a same loop. |
| 5375 | SlowPathCode* slow_path_; |
| 5376 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5377 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5378 | }; |
| 5379 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5380 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5381 | // It ensures that we can generate line number and local variables at this point. |
| 5382 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5383 | public: |
| 5384 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5385 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5386 | |
| 5387 | bool NeedsEnvironment() const OVERRIDE { |
| 5388 | return true; |
| 5389 | } |
| 5390 | |
| 5391 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5392 | |
| 5393 | private: |
| 5394 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5395 | }; |
| 5396 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5397 | /** |
| 5398 | * Instruction to load a Class object. |
| 5399 | */ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5400 | class HLoadClass FINAL : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5401 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5402 | // Determines how to load the Class. |
| 5403 | enum class LoadKind { |
| 5404 | // Use the Class* from the method's own ArtMethod*. |
| 5405 | kReferrersClass, |
| 5406 | |
| 5407 | // Use boot image Class* address that will be known at link time. |
| 5408 | // Used for boot image classes referenced by boot image code in non-PIC mode. |
| 5409 | kBootImageLinkTimeAddress, |
| 5410 | |
| 5411 | // Use PC-relative boot image Class* address that will be known at link time. |
| 5412 | // Used for boot image classes referenced by boot image code in PIC mode. |
| 5413 | kBootImageLinkTimePcRelative, |
| 5414 | |
| 5415 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 5416 | // Used for boot image classes referenced by apps in AOT- and JIT-compiled code. |
| 5417 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5418 | // GetIncludePatchInformation(). |
| 5419 | kBootImageAddress, |
| 5420 | |
| 5421 | // Load from the resolved types array at an absolute address. |
| 5422 | // Used for classes outside the boot image referenced by JIT-compiled code. |
| 5423 | kDexCacheAddress, |
| 5424 | |
| 5425 | // Load from resolved types array in the dex cache using a PC-relative load. |
| 5426 | // Used for classes outside boot image when we know that we can access |
| 5427 | // the dex cache arrays using a PC-relative load. |
| 5428 | kDexCachePcRelative, |
| 5429 | |
| 5430 | // Load from resolved types array accessed through the class loaded from |
| 5431 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5432 | // all other types are unavailable. |
| 5433 | kDexCacheViaMethod, |
| 5434 | |
| 5435 | kLast = kDexCacheViaMethod |
| 5436 | }; |
| 5437 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5438 | HLoadClass(HCurrentMethod* current_method, |
| 5439 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5440 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5441 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5442 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5443 | bool needs_access_check, |
| 5444 | bool is_in_dex_cache) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5445 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5446 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5447 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5448 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5449 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5450 | // Referrers class should not need access check. We never inline unverified |
| 5451 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5452 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5453 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5454 | SetPackedField<LoadKindField>( |
| 5455 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kDexCacheViaMethod); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5456 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5457 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
| 5458 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5459 | } |
| 5460 | |
| 5461 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5462 | DCHECK(HasAddress(load_kind)); |
| 5463 | load_data_.address = address; |
| 5464 | SetLoadKindInternal(load_kind); |
| 5465 | } |
| 5466 | |
| 5467 | void SetLoadKindWithTypeReference(LoadKind load_kind, |
| 5468 | const DexFile& dex_file, |
| 5469 | uint32_t type_index) { |
| 5470 | DCHECK(HasTypeReference(load_kind)); |
| 5471 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5472 | DCHECK_EQ(type_index_, type_index); |
| 5473 | SetLoadKindInternal(load_kind); |
| 5474 | } |
| 5475 | |
| 5476 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5477 | const DexFile& dex_file, |
| 5478 | uint32_t element_index) { |
| 5479 | DCHECK(HasDexCacheReference(load_kind)); |
| 5480 | DCHECK(IsSameDexFile(dex_file_, dex_file)); |
| 5481 | load_data_.dex_cache_element_index = element_index; |
| 5482 | SetLoadKindInternal(load_kind); |
| 5483 | } |
| 5484 | |
| 5485 | LoadKind GetLoadKind() const { |
| 5486 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5487 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5488 | |
| 5489 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5490 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5491 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5492 | |
| 5493 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5494 | |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5495 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5496 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5497 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5498 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5499 | } |
| 5500 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5501 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5502 | // The entrypoint the code generator is going to call does not do |
| 5503 | // clinit of the class. |
| 5504 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5505 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5506 | } |
| 5507 | |
| 5508 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5509 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5510 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5511 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5512 | } |
| 5513 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5514 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5515 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5516 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5517 | } |
| 5518 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5519 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5520 | return loaded_class_rti_; |
| 5521 | } |
| 5522 | |
| 5523 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5524 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5525 | DCHECK(rti.IsExact()); |
| 5526 | loaded_class_rti_ = rti; |
| 5527 | } |
| 5528 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5529 | uint32_t GetTypeIndex() const { return type_index_; } |
| 5530 | const DexFile& GetDexFile() const { return dex_file_; } |
| 5531 | |
| 5532 | uint32_t GetDexCacheElementOffset() const; |
| 5533 | |
| 5534 | uint64_t GetAddress() const { |
| 5535 | DCHECK(HasAddress(GetLoadKind())); |
| 5536 | return load_data_.address; |
| 5537 | } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5538 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5539 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5540 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5541 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5542 | return SideEffects::CanTriggerGC(); |
| 5543 | } |
| 5544 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5545 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5546 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5547 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5548 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5549 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5550 | void MarkInDexCache() { |
| 5551 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5552 | DCHECK(!NeedsEnvironment()); |
| 5553 | RemoveEnvironment(); |
| 5554 | SetSideEffects(SideEffects::None()); |
| 5555 | } |
| 5556 | |
| 5557 | void AddSpecialInput(HInstruction* special_input); |
| 5558 | |
| 5559 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5560 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5561 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5562 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 5563 | } |
| 5564 | |
| 5565 | Primitive::Type GetType() const OVERRIDE { |
| 5566 | return Primitive::kPrimNot; |
| 5567 | } |
| 5568 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5569 | DECLARE_INSTRUCTION(LoadClass); |
| 5570 | |
| 5571 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5572 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5573 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5574 | // Whether this instruction must generate the initialization check. |
| 5575 | // Used for code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5576 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInDexCache + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5577 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 5578 | static constexpr size_t kFieldLoadKindSize = |
| 5579 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5580 | static constexpr size_t kNumberOfLoadClassPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5581 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5582 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 5583 | |
| 5584 | static bool HasTypeReference(LoadKind load_kind) { |
| 5585 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5586 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5587 | load_kind == LoadKind::kDexCacheViaMethod || |
| 5588 | load_kind == LoadKind::kReferrersClass; |
| 5589 | } |
| 5590 | |
| 5591 | static bool HasAddress(LoadKind load_kind) { |
| 5592 | return load_kind == LoadKind::kBootImageAddress || load_kind == LoadKind::kDexCacheAddress; |
| 5593 | } |
| 5594 | |
| 5595 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5596 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5597 | } |
| 5598 | |
| 5599 | void SetLoadKindInternal(LoadKind load_kind); |
| 5600 | |
| 5601 | // The special input is the HCurrentMethod for kDexCacheViaMethod or kReferrersClass. |
| 5602 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5603 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
| 5604 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5605 | |
| 5606 | const uint16_t type_index_; |
| 5607 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5608 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5609 | union { |
| 5610 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
| 5611 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5612 | } load_data_; |
| 5613 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5614 | ReferenceTypeInfo loaded_class_rti_; |
| 5615 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5616 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5617 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5618 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 5619 | |
| 5620 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5621 | inline uint32_t HLoadClass::GetDexCacheElementOffset() const { |
| 5622 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5623 | return load_data_.dex_cache_element_index; |
| 5624 | } |
| 5625 | |
| 5626 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| 5627 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
| 5628 | // The special input is used for PC-relative loads on some architectures. |
| 5629 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 5630 | GetLoadKind() == LoadKind::kDexCachePcRelative) << GetLoadKind(); |
| 5631 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5632 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 5633 | special_input->AddUseAt(this, 0); |
| 5634 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5635 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5636 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5637 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5638 | // Determines how to load the String. |
| 5639 | enum class LoadKind { |
| 5640 | // Use boot image String* address that will be known at link time. |
| 5641 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5642 | kBootImageLinkTimeAddress, |
| 5643 | |
| 5644 | // Use PC-relative boot image String* address that will be known at link time. |
| 5645 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5646 | kBootImageLinkTimePcRelative, |
| 5647 | |
| 5648 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5649 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5650 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5651 | // GetIncludePatchInformation(). |
| 5652 | kBootImageAddress, |
| 5653 | |
| 5654 | // Load from the resolved strings array at an absolute address. |
| 5655 | // Used for strings outside the boot image referenced by JIT-compiled code. |
| 5656 | kDexCacheAddress, |
| 5657 | |
| 5658 | // Load from resolved strings array in the dex cache using a PC-relative load. |
| 5659 | // Used for strings outside boot image when we know that we can access |
| 5660 | // the dex cache arrays using a PC-relative load. |
| 5661 | kDexCachePcRelative, |
| 5662 | |
| 5663 | // Load from resolved strings array accessed through the class loaded from |
| 5664 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5665 | // all other types are unavailable. |
| 5666 | kDexCacheViaMethod, |
| 5667 | |
| 5668 | kLast = kDexCacheViaMethod |
| 5669 | }; |
| 5670 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5671 | HLoadString(HCurrentMethod* current_method, |
| 5672 | uint32_t string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5673 | const DexFile& dex_file, |
| 5674 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5675 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5676 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5677 | string_index_(string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5678 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5679 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
| 5680 | load_data_.ref.dex_file = &dex_file; |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5681 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5682 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5683 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5684 | DCHECK(HasAddress(load_kind)); |
| 5685 | load_data_.address = address; |
| 5686 | SetLoadKindInternal(load_kind); |
| 5687 | } |
| 5688 | |
| 5689 | void SetLoadKindWithStringReference(LoadKind load_kind, |
| 5690 | const DexFile& dex_file, |
| 5691 | uint32_t string_index) { |
| 5692 | DCHECK(HasStringReference(load_kind)); |
| 5693 | load_data_.ref.dex_file = &dex_file; |
| 5694 | string_index_ = string_index; |
| 5695 | SetLoadKindInternal(load_kind); |
| 5696 | } |
| 5697 | |
| 5698 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5699 | const DexFile& dex_file, |
| 5700 | uint32_t element_index) { |
| 5701 | DCHECK(HasDexCacheReference(load_kind)); |
| 5702 | load_data_.ref.dex_file = &dex_file; |
| 5703 | load_data_.ref.dex_cache_element_index = element_index; |
| 5704 | SetLoadKindInternal(load_kind); |
| 5705 | } |
| 5706 | |
| 5707 | LoadKind GetLoadKind() const { |
| 5708 | return GetPackedField<LoadKindField>(); |
| 5709 | } |
| 5710 | |
| 5711 | const DexFile& GetDexFile() const; |
| 5712 | |
| 5713 | uint32_t GetStringIndex() const { |
| 5714 | DCHECK(HasStringReference(GetLoadKind()) || /* For slow paths. */ !IsInDexCache()); |
| 5715 | return string_index_; |
| 5716 | } |
| 5717 | |
| 5718 | uint32_t GetDexCacheElementOffset() const; |
| 5719 | |
| 5720 | uint64_t GetAddress() const { |
| 5721 | DCHECK(HasAddress(GetLoadKind())); |
| 5722 | return load_data_.address; |
| 5723 | } |
| 5724 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5725 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5726 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5727 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5728 | |
| 5729 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5730 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5731 | // Will call the runtime if we need to load the string through |
| 5732 | // the dex cache and the string is not guaranteed to be there yet. |
| 5733 | bool NeedsEnvironment() const OVERRIDE { |
| 5734 | LoadKind load_kind = GetLoadKind(); |
| 5735 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5736 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5737 | load_kind == LoadKind::kBootImageAddress) { |
| 5738 | return false; |
| 5739 | } |
| 5740 | return !IsInDexCache(); |
| 5741 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5742 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5743 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5744 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5745 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5746 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5747 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5748 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5749 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5750 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5751 | return SideEffects::CanTriggerGC(); |
| 5752 | } |
| 5753 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5754 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5755 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5756 | void MarkInDexCache() { |
| 5757 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5758 | DCHECK(!NeedsEnvironment()); |
| 5759 | RemoveEnvironment(); |
Vladimir Marko | ace7a00 | 2016-04-05 11:18:49 +0100 | [diff] [blame] | 5760 | SetSideEffects(SideEffects::None()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5761 | } |
| 5762 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5763 | void AddSpecialInput(HInstruction* special_input); |
| 5764 | |
| 5765 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5766 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5767 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5768 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5769 | } |
| 5770 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5771 | Primitive::Type GetType() const OVERRIDE { |
| 5772 | return Primitive::kPrimNot; |
| 5773 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5774 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5775 | DECLARE_INSTRUCTION(LoadString); |
| 5776 | |
| 5777 | private: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5778 | static constexpr size_t kFlagIsInDexCache = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5779 | static constexpr size_t kFieldLoadKind = kFlagIsInDexCache + 1; |
| 5780 | static constexpr size_t kFieldLoadKindSize = |
| 5781 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5782 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5783 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5784 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5785 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5786 | static bool HasStringReference(LoadKind load_kind) { |
| 5787 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5788 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5789 | load_kind == LoadKind::kDexCacheViaMethod; |
| 5790 | } |
| 5791 | |
| 5792 | static bool HasAddress(LoadKind load_kind) { |
| 5793 | return load_kind == LoadKind::kBootImageAddress || load_kind == LoadKind::kDexCacheAddress; |
| 5794 | } |
| 5795 | |
| 5796 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5797 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5798 | } |
| 5799 | |
| 5800 | void SetLoadKindInternal(LoadKind load_kind); |
| 5801 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5802 | // The special input is the HCurrentMethod for kDexCacheViaMethod. |
| 5803 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| 5804 | // for PC-relative loads, i.e. kDexCachePcRelative or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5805 | HUserRecord<HInstruction*> special_input_; |
| 5806 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5807 | // String index serves also as the hash code and it's also needed for slow-paths, |
| 5808 | // so it must not be overwritten with other load data. |
| 5809 | uint32_t string_index_; |
| 5810 | |
| 5811 | union { |
| 5812 | struct { |
| 5813 | const DexFile* dex_file; // For string reference and dex cache reference. |
| 5814 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
| 5815 | } ref; |
| 5816 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5817 | } load_data_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5818 | |
| 5819 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5820 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5821 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5822 | |
| 5823 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5824 | inline const DexFile& HLoadString::GetDexFile() const { |
| 5825 | DCHECK(HasStringReference(GetLoadKind()) || HasDexCacheReference(GetLoadKind())) |
| 5826 | << GetLoadKind(); |
| 5827 | return *load_data_.ref.dex_file; |
| 5828 | } |
| 5829 | |
| 5830 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5831 | inline uint32_t HLoadString::GetDexCacheElementOffset() const { |
| 5832 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5833 | return load_data_.ref.dex_cache_element_index; |
| 5834 | } |
| 5835 | |
| 5836 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5837 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
| 5838 | // The special input is used for PC-relative loads on some architectures. |
| 5839 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 5840 | GetLoadKind() == LoadKind::kDexCachePcRelative) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5841 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5842 | // so use the GetInputRecords() from the base class to set the input record. |
| 5843 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5844 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5845 | special_input->AddUseAt(this, 0); |
| 5846 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5847 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5848 | /** |
| 5849 | * Performs an initialization check on its Class object input. |
| 5850 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5851 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5852 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5853 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5854 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5855 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5856 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5857 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5858 | SetRawInputAt(0, constant); |
| 5859 | } |
| 5860 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5861 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5862 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5863 | return true; |
| 5864 | } |
| 5865 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5866 | bool NeedsEnvironment() const OVERRIDE { |
| 5867 | // May call runtime to initialize the class. |
| 5868 | return true; |
| 5869 | } |
| 5870 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5871 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5872 | |
| 5873 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5874 | |
| 5875 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5876 | |
| 5877 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5878 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5879 | }; |
| 5880 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5881 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5882 | public: |
| 5883 | HStaticFieldGet(HInstruction* cls, |
| 5884 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5885 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5886 | bool is_volatile, |
| 5887 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5888 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5889 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5890 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5891 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5892 | : HExpression(field_type, |
| 5893 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5894 | dex_pc), |
| 5895 | field_info_(field_offset, |
| 5896 | field_type, |
| 5897 | is_volatile, |
| 5898 | field_idx, |
| 5899 | declaring_class_def_index, |
| 5900 | dex_file, |
| 5901 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5902 | SetRawInputAt(0, cls); |
| 5903 | } |
| 5904 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5905 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5906 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5907 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5908 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5909 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5910 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | size_t ComputeHashCode() const OVERRIDE { |
| 5914 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5915 | } |
| 5916 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5917 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5918 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5919 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5920 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5921 | |
| 5922 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5923 | |
| 5924 | private: |
| 5925 | const FieldInfo field_info_; |
| 5926 | |
| 5927 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5928 | }; |
| 5929 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5930 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5931 | public: |
| 5932 | HStaticFieldSet(HInstruction* cls, |
| 5933 | HInstruction* value, |
| 5934 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5935 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5936 | bool is_volatile, |
| 5937 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5938 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5939 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5940 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5941 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5942 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5943 | dex_pc), |
| 5944 | field_info_(field_offset, |
| 5945 | field_type, |
| 5946 | is_volatile, |
| 5947 | field_idx, |
| 5948 | declaring_class_def_index, |
| 5949 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5950 | dex_cache) { |
| 5951 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5952 | SetRawInputAt(0, cls); |
| 5953 | SetRawInputAt(1, value); |
| 5954 | } |
| 5955 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5956 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5957 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5958 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5959 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5960 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5961 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5962 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5963 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5964 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5965 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5966 | |
| 5967 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5968 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5969 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5970 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5971 | "Too many packed fields."); |
| 5972 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5973 | const FieldInfo field_info_; |
| 5974 | |
| 5975 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5976 | }; |
| 5977 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5978 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5979 | public: |
| 5980 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5981 | Primitive::Type field_type, |
| 5982 | uint32_t field_index, |
| 5983 | uint32_t dex_pc) |
| 5984 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5985 | field_index_(field_index) { |
| 5986 | SetRawInputAt(0, obj); |
| 5987 | } |
| 5988 | |
| 5989 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5990 | bool CanThrow() const OVERRIDE { return true; } |
| 5991 | |
| 5992 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5993 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5994 | |
| 5995 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5996 | |
| 5997 | private: |
| 5998 | const uint32_t field_index_; |
| 5999 | |
| 6000 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 6001 | }; |
| 6002 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6003 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6004 | public: |
| 6005 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6006 | HInstruction* value, |
| 6007 | Primitive::Type field_type, |
| 6008 | uint32_t field_index, |
| 6009 | uint32_t dex_pc) |
| 6010 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6011 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6012 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6013 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6014 | SetRawInputAt(0, obj); |
| 6015 | SetRawInputAt(1, value); |
| 6016 | } |
| 6017 | |
| 6018 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6019 | bool CanThrow() const OVERRIDE { return true; } |
| 6020 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6021 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6022 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6023 | |
| 6024 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6025 | |
| 6026 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6027 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6028 | static constexpr size_t kFieldFieldTypeSize = |
| 6029 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6030 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6031 | kFieldFieldType + kFieldFieldTypeSize; |
| 6032 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6033 | "Too many packed fields."); |
| 6034 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6035 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6036 | const uint32_t field_index_; |
| 6037 | |
| 6038 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 6039 | }; |
| 6040 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6041 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6042 | public: |
| 6043 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 6044 | uint32_t field_index, |
| 6045 | uint32_t dex_pc) |
| 6046 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 6047 | field_index_(field_index) { |
| 6048 | } |
| 6049 | |
| 6050 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6051 | bool CanThrow() const OVERRIDE { return true; } |
| 6052 | |
| 6053 | Primitive::Type GetFieldType() const { return GetType(); } |
| 6054 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6055 | |
| 6056 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6057 | |
| 6058 | private: |
| 6059 | const uint32_t field_index_; |
| 6060 | |
| 6061 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 6062 | }; |
| 6063 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6064 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6065 | public: |
| 6066 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 6067 | Primitive::Type field_type, |
| 6068 | uint32_t field_index, |
| 6069 | uint32_t dex_pc) |
| 6070 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6071 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6072 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 6073 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6074 | SetRawInputAt(0, value); |
| 6075 | } |
| 6076 | |
| 6077 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6078 | bool CanThrow() const OVERRIDE { return true; } |
| 6079 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6080 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6081 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6082 | |
| 6083 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6084 | |
| 6085 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6086 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6087 | static constexpr size_t kFieldFieldTypeSize = |
| 6088 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 6089 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6090 | kFieldFieldType + kFieldFieldTypeSize; |
| 6091 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6092 | "Too many packed fields."); |
| 6093 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 6094 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6095 | const uint32_t field_index_; |
| 6096 | |
| 6097 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6098 | }; |
| 6099 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6100 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6101 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6102 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6103 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6104 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6105 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6106 | bool CanBeNull() const OVERRIDE { return false; } |
| 6107 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6108 | DECLARE_INSTRUCTION(LoadException); |
| 6109 | |
| 6110 | private: |
| 6111 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6112 | }; |
| 6113 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6114 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6115 | // Must not be removed because the runtime expects the TLS to get cleared. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6116 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6117 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6118 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6119 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6120 | |
| 6121 | DECLARE_INSTRUCTION(ClearException); |
| 6122 | |
| 6123 | private: |
| 6124 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6125 | }; |
| 6126 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6127 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6128 | public: |
| 6129 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6130 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6131 | SetRawInputAt(0, exception); |
| 6132 | } |
| 6133 | |
| 6134 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6135 | |
| 6136 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6137 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6138 | bool CanThrow() const OVERRIDE { return true; } |
| 6139 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6140 | |
| 6141 | DECLARE_INSTRUCTION(Throw); |
| 6142 | |
| 6143 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6144 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6145 | }; |
| 6146 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6147 | /** |
| 6148 | * Implementation strategies for the code generator of a HInstanceOf |
| 6149 | * or `HCheckCast`. |
| 6150 | */ |
| 6151 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6152 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6153 | kExactCheck, // Can do a single class compare. |
| 6154 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6155 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6156 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6157 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6158 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6159 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6160 | }; |
| 6161 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6162 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6163 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6164 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6165 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6166 | HInstanceOf(HInstruction* object, |
| 6167 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6168 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6169 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6170 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6171 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6172 | dex_pc) { |
| 6173 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6174 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6175 | SetRawInputAt(0, object); |
| 6176 | SetRawInputAt(1, constant); |
| 6177 | } |
| 6178 | |
| 6179 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6180 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6181 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6182 | return true; |
| 6183 | } |
| 6184 | |
| 6185 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6186 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6187 | } |
| 6188 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6189 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6190 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6191 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6192 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6193 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6194 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6195 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6196 | // Mips currently does runtime calls for any other checks. |
| 6197 | return check_kind != TypeCheckKind::kExactCheck; |
| 6198 | } |
| 6199 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6200 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6201 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6202 | } |
| 6203 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6204 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6205 | |
| 6206 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6207 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6208 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6209 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6210 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6211 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6212 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6213 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6214 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6215 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6216 | }; |
| 6217 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6218 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6219 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6220 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6221 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6222 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6223 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6224 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6225 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6226 | SetRawInputAt(0, input); |
| 6227 | } |
| 6228 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6229 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6230 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6231 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6232 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6233 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6234 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6235 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6236 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6237 | } |
| 6238 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6239 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6240 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6241 | DECLARE_INSTRUCTION(BoundType); |
| 6242 | |
| 6243 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6244 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6245 | // is false then CanBeNull() cannot be true). |
| 6246 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6247 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6248 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6249 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6250 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6251 | // 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] | 6252 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6253 | // It is used to bound the type in cases like: |
| 6254 | // if (x instanceof ClassX) { |
| 6255 | // // uper_bound_ will be ClassX |
| 6256 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6257 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6258 | |
| 6259 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6260 | }; |
| 6261 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6262 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6263 | public: |
| 6264 | HCheckCast(HInstruction* object, |
| 6265 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6266 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6267 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6268 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6269 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6270 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6271 | SetRawInputAt(0, object); |
| 6272 | SetRawInputAt(1, constant); |
| 6273 | } |
| 6274 | |
| 6275 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6276 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6277 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6278 | return true; |
| 6279 | } |
| 6280 | |
| 6281 | bool NeedsEnvironment() const OVERRIDE { |
| 6282 | // Instruction may throw a CheckCastError. |
| 6283 | return true; |
| 6284 | } |
| 6285 | |
| 6286 | bool CanThrow() const OVERRIDE { return true; } |
| 6287 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6288 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6289 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6290 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6291 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6292 | |
| 6293 | DECLARE_INSTRUCTION(CheckCast); |
| 6294 | |
| 6295 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6296 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6297 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6298 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6299 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6300 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6301 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6302 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6303 | |
| 6304 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6305 | }; |
| 6306 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame^] | 6307 | /** |
| 6308 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 6309 | * @details We define the combined barrier types that are actually required |
| 6310 | * by the Java Memory Model, rather than using exactly the terminology from |
| 6311 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 6312 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 6313 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 6314 | * The current recipe is as follows: |
| 6315 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 6316 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 6317 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 6318 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 6319 | * class has final fields. |
| 6320 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 6321 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 6322 | */ |
| 6323 | enum MemBarrierKind { |
| 6324 | kAnyStore, |
| 6325 | kLoadAny, |
| 6326 | kStoreStore, |
| 6327 | kAnyAny, |
| 6328 | kNTStoreStore, |
| 6329 | kLastBarrierKind = kNTStoreStore |
| 6330 | }; |
| 6331 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 6332 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6333 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6334 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6335 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6336 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6337 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6338 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6339 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6340 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6341 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6342 | |
| 6343 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6344 | |
| 6345 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6346 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6347 | static constexpr size_t kFieldBarrierKindSize = |
| 6348 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6349 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6350 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6351 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6352 | "Too many packed fields."); |
| 6353 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6354 | |
| 6355 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6356 | }; |
| 6357 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6358 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6359 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6360 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6361 | kEnter, |
| 6362 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6363 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6364 | }; |
| 6365 | |
| 6366 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6367 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6368 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6369 | dex_pc) { |
| 6370 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6371 | SetRawInputAt(0, object); |
| 6372 | } |
| 6373 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6374 | // Instruction may go into runtime, so we need an environment. |
| 6375 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6376 | |
| 6377 | bool CanThrow() const OVERRIDE { |
| 6378 | // Verifier guarantees that monitor-exit cannot throw. |
| 6379 | // This is important because it allows the HGraphBuilder to remove |
| 6380 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6381 | return IsEnter(); |
| 6382 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6383 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6384 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6385 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6386 | |
| 6387 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6388 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6389 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6390 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6391 | static constexpr size_t kFieldOperationKindSize = |
| 6392 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6393 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6394 | kFieldOperationKind + kFieldOperationKindSize; |
| 6395 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6396 | "Too many packed fields."); |
| 6397 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6398 | |
| 6399 | private: |
| 6400 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6401 | }; |
| 6402 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6403 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6404 | public: |
| 6405 | HSelect(HInstruction* condition, |
| 6406 | HInstruction* true_value, |
| 6407 | HInstruction* false_value, |
| 6408 | uint32_t dex_pc) |
| 6409 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6410 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6411 | |
| 6412 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6413 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6414 | // that architectures which implement HSelect as a conditional move also |
| 6415 | // will not need to invert the condition. |
| 6416 | SetRawInputAt(0, false_value); |
| 6417 | SetRawInputAt(1, true_value); |
| 6418 | SetRawInputAt(2, condition); |
| 6419 | } |
| 6420 | |
| 6421 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6422 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6423 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6424 | |
| 6425 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6426 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6427 | return true; |
| 6428 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6429 | |
| 6430 | bool CanBeNull() const OVERRIDE { |
| 6431 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6432 | } |
| 6433 | |
| 6434 | DECLARE_INSTRUCTION(Select); |
| 6435 | |
| 6436 | private: |
| 6437 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6438 | }; |
| 6439 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6440 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6441 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6442 | MoveOperands(Location source, |
| 6443 | Location destination, |
| 6444 | Primitive::Type type, |
| 6445 | HInstruction* instruction) |
| 6446 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6447 | |
| 6448 | Location GetSource() const { return source_; } |
| 6449 | Location GetDestination() const { return destination_; } |
| 6450 | |
| 6451 | void SetSource(Location value) { source_ = value; } |
| 6452 | void SetDestination(Location value) { destination_ = value; } |
| 6453 | |
| 6454 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6455 | // destination (but not the source). |
| 6456 | Location MarkPending() { |
| 6457 | DCHECK(!IsPending()); |
| 6458 | Location dest = destination_; |
| 6459 | destination_ = Location::NoLocation(); |
| 6460 | return dest; |
| 6461 | } |
| 6462 | |
| 6463 | void ClearPending(Location dest) { |
| 6464 | DCHECK(IsPending()); |
| 6465 | destination_ = dest; |
| 6466 | } |
| 6467 | |
| 6468 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6469 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6470 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6471 | } |
| 6472 | |
| 6473 | // True if this blocks a move from the given location. |
| 6474 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6475 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6476 | } |
| 6477 | |
| 6478 | // A move is redundant if it's been eliminated, if its source and |
| 6479 | // destination are the same, or if its destination is unneeded. |
| 6480 | bool IsRedundant() const { |
| 6481 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6482 | } |
| 6483 | |
| 6484 | // We clear both operands to indicate move that's been eliminated. |
| 6485 | void Eliminate() { |
| 6486 | source_ = destination_ = Location::NoLocation(); |
| 6487 | } |
| 6488 | |
| 6489 | bool IsEliminated() const { |
| 6490 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6491 | return source_.IsInvalid(); |
| 6492 | } |
| 6493 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6494 | Primitive::Type GetType() const { return type_; } |
| 6495 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6496 | bool Is64BitMove() const { |
| 6497 | return Primitive::Is64BitType(type_); |
| 6498 | } |
| 6499 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6500 | HInstruction* GetInstruction() const { return instruction_; } |
| 6501 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6502 | private: |
| 6503 | Location source_; |
| 6504 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6505 | // The type this move is for. |
| 6506 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6507 | // The instruction this move is assocatied with. Null when this move is |
| 6508 | // for moving an input in the expected locations of user (including a phi user). |
| 6509 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6510 | // in the same parallel move. |
| 6511 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6512 | }; |
| 6513 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6514 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6515 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6516 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6517 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6518 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6519 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6520 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6521 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6522 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6523 | moves_.reserve(kDefaultNumberOfMoves); |
| 6524 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6525 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6526 | void AddMove(Location source, |
| 6527 | Location destination, |
| 6528 | Primitive::Type type, |
| 6529 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6530 | DCHECK(source.IsValid()); |
| 6531 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6532 | if (kIsDebugBuild) { |
| 6533 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6534 | for (const MoveOperands& move : moves_) { |
| 6535 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6536 | // Special case the situation where the move is for the spill slot |
| 6537 | // of the instruction. |
| 6538 | if ((GetPrevious() == instruction) |
| 6539 | || ((GetPrevious() == nullptr) |
| 6540 | && instruction->IsPhi() |
| 6541 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6542 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6543 | << "Doing parallel moves for the same instruction."; |
| 6544 | } else { |
| 6545 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6546 | } |
| 6547 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6548 | } |
| 6549 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6550 | for (const MoveOperands& move : moves_) { |
| 6551 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6552 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6553 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6554 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6555 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6556 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6557 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6558 | } |
| 6559 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6560 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6561 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6562 | } |
| 6563 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6564 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6565 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6566 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6567 | |
| 6568 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6569 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6570 | |
| 6571 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6572 | }; |
| 6573 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6574 | } // namespace art |
| 6575 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6576 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6577 | #include "nodes_shared.h" |
| 6578 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6579 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6580 | #include "nodes_arm.h" |
| 6581 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6582 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6583 | #include "nodes_arm64.h" |
| 6584 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 6585 | #ifdef ART_ENABLE_CODEGEN_mips |
| 6586 | #include "nodes_mips.h" |
| 6587 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6588 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6589 | #include "nodes_x86.h" |
| 6590 | #endif |
| 6591 | |
| 6592 | namespace art { |
| 6593 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6594 | class HGraphVisitor : public ValueObject { |
| 6595 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6596 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6597 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6598 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6599 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6600 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6601 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6602 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6603 | void VisitInsertionOrder(); |
| 6604 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6605 | // Visit the graph following dominator tree reverse post-order. |
| 6606 | void VisitReversePostOrder(); |
| 6607 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6608 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6609 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6610 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6611 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6612 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6613 | |
| 6614 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6615 | |
| 6616 | #undef DECLARE_VISIT_INSTRUCTION |
| 6617 | |
| 6618 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6619 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6620 | |
| 6621 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6622 | }; |
| 6623 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6624 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6625 | public: |
| 6626 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6627 | virtual ~HGraphDelegateVisitor() {} |
| 6628 | |
| 6629 | // Visit functions that delegate to to super class. |
| 6630 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6631 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6632 | |
| 6633 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6634 | |
| 6635 | #undef DECLARE_VISIT_INSTRUCTION |
| 6636 | |
| 6637 | private: |
| 6638 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6639 | }; |
| 6640 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6641 | class HInsertionOrderIterator : public ValueObject { |
| 6642 | public: |
| 6643 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 6644 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6645 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 6646 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6647 | void Advance() { ++index_; } |
| 6648 | |
| 6649 | private: |
| 6650 | const HGraph& graph_; |
| 6651 | size_t index_; |
| 6652 | |
| 6653 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 6654 | }; |
| 6655 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6656 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6657 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6658 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 6659 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6660 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6661 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6662 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6663 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 6664 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6665 | void Advance() { ++index_; } |
| 6666 | |
| 6667 | private: |
| 6668 | const HGraph& graph_; |
| 6669 | size_t index_; |
| 6670 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6671 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6672 | }; |
| 6673 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6674 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6675 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6676 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6677 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6678 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6679 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6680 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6681 | |
| 6682 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6683 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6684 | void Advance() { --index_; } |
| 6685 | |
| 6686 | private: |
| 6687 | const HGraph& graph_; |
| 6688 | size_t index_; |
| 6689 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6690 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6691 | }; |
| 6692 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6693 | class HLinearPostOrderIterator : public ValueObject { |
| 6694 | public: |
| 6695 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6696 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6697 | |
| 6698 | bool Done() const { return index_ == 0; } |
| 6699 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6700 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6701 | |
| 6702 | void Advance() { |
| 6703 | --index_; |
| 6704 | DCHECK_GE(index_, 0U); |
| 6705 | } |
| 6706 | |
| 6707 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6708 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6709 | size_t index_; |
| 6710 | |
| 6711 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 6712 | }; |
| 6713 | |
| 6714 | class HLinearOrderIterator : public ValueObject { |
| 6715 | public: |
| 6716 | explicit HLinearOrderIterator(const HGraph& graph) |
| 6717 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 6718 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6719 | bool Done() const { return index_ == order_.size(); } |
| 6720 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6721 | void Advance() { ++index_; } |
| 6722 | |
| 6723 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6724 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6725 | size_t index_; |
| 6726 | |
| 6727 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 6728 | }; |
| 6729 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6730 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6731 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6732 | // block id. |
| 6733 | class HBlocksInLoopIterator : public ValueObject { |
| 6734 | public: |
| 6735 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6736 | : blocks_in_loop_(info.GetBlocks()), |
| 6737 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6738 | index_(0) { |
| 6739 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6740 | Advance(); |
| 6741 | } |
| 6742 | } |
| 6743 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6744 | bool Done() const { return index_ == blocks_.size(); } |
| 6745 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6746 | void Advance() { |
| 6747 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6748 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6749 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6750 | break; |
| 6751 | } |
| 6752 | } |
| 6753 | } |
| 6754 | |
| 6755 | private: |
| 6756 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6757 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6758 | size_t index_; |
| 6759 | |
| 6760 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6761 | }; |
| 6762 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6763 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6764 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6765 | // post order. |
| 6766 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6767 | public: |
| 6768 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6769 | : blocks_in_loop_(info.GetBlocks()), |
| 6770 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6771 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6772 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6773 | Advance(); |
| 6774 | } |
| 6775 | } |
| 6776 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6777 | bool Done() const { return index_ == blocks_.size(); } |
| 6778 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6779 | void Advance() { |
| 6780 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6781 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6782 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6783 | break; |
| 6784 | } |
| 6785 | } |
| 6786 | } |
| 6787 | |
| 6788 | private: |
| 6789 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6790 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6791 | size_t index_; |
| 6792 | |
| 6793 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6794 | }; |
| 6795 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6796 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6797 | if (constant->IsIntConstant()) { |
| 6798 | return constant->AsIntConstant()->GetValue(); |
| 6799 | } else if (constant->IsLongConstant()) { |
| 6800 | return constant->AsLongConstant()->GetValue(); |
| 6801 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6802 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6803 | return 0; |
| 6804 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6805 | } |
| 6806 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6807 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6808 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6809 | inline const H##type* HInstruction::As##type() const { \ |
| 6810 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6811 | } \ |
| 6812 | inline H##type* HInstruction::As##type() { \ |
| 6813 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6814 | } |
| 6815 | |
| 6816 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6817 | #undef INSTRUCTION_TYPE_CHECK |
| 6818 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6819 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6820 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6821 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6822 | size_t number_of_new_blocks, |
| 6823 | size_t after) { |
| 6824 | DCHECK_LT(after, blocks->size()); |
| 6825 | size_t old_size = blocks->size(); |
| 6826 | size_t new_size = old_size + number_of_new_blocks; |
| 6827 | blocks->resize(new_size); |
| 6828 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6829 | } |
| 6830 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6831 | } // namespace art |
| 6832 | |
| 6833 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |