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" |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 28 | #include "dex/compiler_enums.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" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 39 | |
| 40 | namespace art { |
| 41 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 42 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 43 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 45 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 46 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 47 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 48 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 49 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 50 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 51 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 52 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 53 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 54 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 55 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 56 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 57 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 58 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 59 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 60 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 61 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 62 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 63 | namespace mirror { |
| 64 | class DexCache; |
| 65 | } // namespace mirror |
| 66 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 67 | static const int kDefaultNumberOfBlocks = 8; |
| 68 | static const int kDefaultNumberOfSuccessors = 2; |
| 69 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 70 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 71 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 72 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 73 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 74 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 75 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 76 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 77 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 78 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 79 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 80 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 81 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 82 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 83 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 84 | static constexpr uint32_t kNoDexPc = -1; |
| 85 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 86 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 87 | // All types. |
| 88 | kCondEQ, // == |
| 89 | kCondNE, // != |
| 90 | // Signed integers and floating-point numbers. |
| 91 | kCondLT, // < |
| 92 | kCondLE, // <= |
| 93 | kCondGT, // > |
| 94 | kCondGE, // >= |
| 95 | // Unsigned integers. |
| 96 | kCondB, // < |
| 97 | kCondBE, // <= |
| 98 | kCondA, // > |
| 99 | kCondAE, // >= |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 102 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 103 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 104 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 105 | kAnalysisFailThrowCatchLoop, |
| 106 | kAnalysisFailAmbiguousArrayOp, |
| 107 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 110 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 111 | public: |
| 112 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 113 | |
| 114 | void AddInstruction(HInstruction* instruction); |
| 115 | void RemoveInstruction(HInstruction* instruction); |
| 116 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 117 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 118 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 119 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 120 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 121 | // Return true if this list contains `instruction`. |
| 122 | bool Contains(HInstruction* instruction) const; |
| 123 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 124 | // Return true if `instruction1` is found before `instruction2` in |
| 125 | // this instruction list and false otherwise. Abort if none |
| 126 | // of these instructions is found. |
| 127 | bool FoundBefore(const HInstruction* instruction1, |
| 128 | const HInstruction* instruction2) const; |
| 129 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 130 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 131 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 132 | |
| 133 | // Update the block of all instructions to be `block`. |
| 134 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 135 | |
| 136 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 137 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 138 | void Add(const HInstructionList& instruction_list); |
| 139 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 140 | // Return the number of instructions in the list. This is an expensive operation. |
| 141 | size_t CountSize() const; |
| 142 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 143 | private: |
| 144 | HInstruction* first_instruction_; |
| 145 | HInstruction* last_instruction_; |
| 146 | |
| 147 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 148 | friend class HGraph; |
| 149 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 150 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 151 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 152 | |
| 153 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 154 | }; |
| 155 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 156 | class ReferenceTypeInfo : ValueObject { |
| 157 | public: |
| 158 | typedef Handle<mirror::Class> TypeHandle; |
| 159 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 160 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 161 | |
| 162 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 163 | return ReferenceTypeInfo(type_handle, is_exact); |
| 164 | } |
| 165 | |
| 166 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 167 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 168 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 169 | return handle.GetReference() != nullptr; |
| 170 | } |
| 171 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame^] | 172 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 173 | return IsValidHandle(type_handle_); |
| 174 | } |
| 175 | |
| 176 | bool IsExact() const { return is_exact_; } |
| 177 | |
| 178 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 179 | DCHECK(IsValid()); |
| 180 | return GetTypeHandle()->IsObjectClass(); |
| 181 | } |
| 182 | |
| 183 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 184 | DCHECK(IsValid()); |
| 185 | return GetTypeHandle()->IsStringClass(); |
| 186 | } |
| 187 | |
| 188 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 189 | DCHECK(IsValid()); |
| 190 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 191 | } |
| 192 | |
| 193 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 194 | DCHECK(IsValid()); |
| 195 | return GetTypeHandle()->IsInterface(); |
| 196 | } |
| 197 | |
| 198 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 199 | DCHECK(IsValid()); |
| 200 | return GetTypeHandle()->IsArrayClass(); |
| 201 | } |
| 202 | |
| 203 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 204 | DCHECK(IsValid()); |
| 205 | return GetTypeHandle()->IsPrimitiveArray(); |
| 206 | } |
| 207 | |
| 208 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 209 | DCHECK(IsValid()); |
| 210 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 211 | } |
| 212 | |
| 213 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 214 | DCHECK(IsValid()); |
| 215 | if (!IsExact()) return false; |
| 216 | if (!IsArrayClass()) return false; |
| 217 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 218 | } |
| 219 | |
| 220 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 221 | DCHECK(IsValid()); |
| 222 | if (!IsExact()) return false; |
| 223 | if (!IsArrayClass()) return false; |
| 224 | if (!rti.IsArrayClass()) return false; |
| 225 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 226 | rti.GetTypeHandle()->GetComponentType()); |
| 227 | } |
| 228 | |
| 229 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 230 | |
| 231 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 232 | DCHECK(IsValid()); |
| 233 | DCHECK(rti.IsValid()); |
| 234 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 235 | } |
| 236 | |
| 237 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 238 | DCHECK(IsValid()); |
| 239 | DCHECK(rti.IsValid()); |
| 240 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 241 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 242 | } |
| 243 | |
| 244 | // Returns true if the type information provide the same amount of details. |
| 245 | // Note that it does not mean that the instructions have the same actual type |
| 246 | // (because the type can be the result of a merge). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 247 | bool IsEqual(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 248 | if (!IsValid() && !rti.IsValid()) { |
| 249 | // Invalid types are equal. |
| 250 | return true; |
| 251 | } |
| 252 | if (!IsValid() || !rti.IsValid()) { |
| 253 | // One is valid, the other not. |
| 254 | return false; |
| 255 | } |
| 256 | return IsExact() == rti.IsExact() |
| 257 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 258 | } |
| 259 | |
| 260 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 261 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 262 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 263 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 264 | |
| 265 | // The class of the object. |
| 266 | TypeHandle type_handle_; |
| 267 | // Whether or not the type is exact or a superclass of the actual type. |
| 268 | // Whether or not we have any information about this type. |
| 269 | bool is_exact_; |
| 270 | }; |
| 271 | |
| 272 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 273 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 274 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 275 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 276 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 277 | HGraph(ArenaAllocator* arena, |
| 278 | const DexFile& dex_file, |
| 279 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 280 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 281 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 282 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 283 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 284 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 285 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 286 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 287 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 288 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 289 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 290 | entry_block_(nullptr), |
| 291 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 292 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 293 | number_of_vregs_(0), |
| 294 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 295 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 296 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 297 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 298 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 299 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 300 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 301 | dex_file_(dex_file), |
| 302 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 303 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 304 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 305 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 306 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 307 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 308 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 309 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 310 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 311 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 312 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 313 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
| 314 | osr_(osr) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 315 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 316 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 317 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 318 | // Acquires and stores RTI of inexact Object to be used when creating HNullConstant. |
| 319 | void InitializeInexactObjectRTI(StackHandleScopeCollection* handles); |
| 320 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 321 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 322 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 323 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 324 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 325 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 326 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 327 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 328 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 329 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 330 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 331 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 332 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 333 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 334 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 335 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 336 | void ComputeDominanceInformation(); |
| 337 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 338 | void ClearLoopInformation(); |
| 339 | void FindBackEdges(ArenaBitVector* visited); |
| 340 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 341 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 342 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 343 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 344 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 345 | // 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] | 346 | // 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] | 347 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 348 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 349 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 350 | // order and loop information. |
| 351 | void ComputeTryBlockInformation(); |
| 352 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 353 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 354 | // Returns the instruction to replace the invoke expression or null if the |
| 355 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 356 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 357 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 358 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 359 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 360 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 361 | // should be the new back edge. |
| 362 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 363 | HBasicBlock* reference, |
| 364 | bool replace_if_back_edge); |
| 365 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 366 | // Need to add a couple of blocks to test if the loop body is entered and |
| 367 | // put deoptimization instructions, etc. |
| 368 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 369 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 370 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 371 | // other blocks and has no instructions or phis. |
| 372 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 373 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 374 | // Splits the edge between `block` and `successor` while preserving the |
| 375 | // indices in the predecessor/successor lists. If there are multiple edges |
| 376 | // between the blocks, the lowest indices are used. |
| 377 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 378 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 379 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 380 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 381 | void SimplifyLoop(HBasicBlock* header); |
| 382 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 383 | int32_t GetNextInstructionId() { |
| 384 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 385 | return current_instruction_id_++; |
| 386 | } |
| 387 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 388 | int32_t GetCurrentInstructionId() const { |
| 389 | return current_instruction_id_; |
| 390 | } |
| 391 | |
| 392 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 393 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 394 | current_instruction_id_ = id; |
| 395 | } |
| 396 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 397 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 398 | return maximum_number_of_out_vregs_; |
| 399 | } |
| 400 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 401 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 402 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 403 | } |
| 404 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 405 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 406 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 407 | } |
| 408 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 409 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 410 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 413 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 414 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 415 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 416 | } |
| 417 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 418 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 419 | number_of_vregs_ = number_of_vregs; |
| 420 | } |
| 421 | |
| 422 | uint16_t GetNumberOfVRegs() const { |
| 423 | return number_of_vregs_; |
| 424 | } |
| 425 | |
| 426 | void SetNumberOfInVRegs(uint16_t value) { |
| 427 | number_of_in_vregs_ = value; |
| 428 | } |
| 429 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 430 | uint16_t GetNumberOfInVRegs() const { |
| 431 | return number_of_in_vregs_; |
| 432 | } |
| 433 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 434 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 435 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 436 | return number_of_vregs_ - number_of_in_vregs_; |
| 437 | } |
| 438 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 439 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 440 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 441 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 442 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 443 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 444 | return linear_order_; |
| 445 | } |
| 446 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 447 | bool HasBoundsChecks() const { |
| 448 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 449 | } |
| 450 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 451 | void SetHasBoundsChecks(bool value) { |
| 452 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 455 | bool ShouldGenerateConstructorBarrier() const { |
| 456 | return should_generate_constructor_barrier_; |
| 457 | } |
| 458 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 459 | bool IsDebuggable() const { return debuggable_; } |
| 460 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 461 | // 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] | 462 | // already, it is created and inserted into the graph. This method is only for |
| 463 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 464 | 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] | 465 | |
| 466 | // TODO: This is problematic for the consistency of reference type propagation |
| 467 | // because it can be created anytime after the pass and thus it will be left |
| 468 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 469 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 470 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 471 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 472 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 473 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 474 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 475 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 476 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 477 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 478 | 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] | 479 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 480 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 481 | 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] | 482 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 483 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 484 | HCurrentMethod* GetCurrentMethod(); |
| 485 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 486 | const DexFile& GetDexFile() const { |
| 487 | return dex_file_; |
| 488 | } |
| 489 | |
| 490 | uint32_t GetMethodIdx() const { |
| 491 | return method_idx_; |
| 492 | } |
| 493 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 494 | InvokeType GetInvokeType() const { |
| 495 | return invoke_type_; |
| 496 | } |
| 497 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 498 | InstructionSet GetInstructionSet() const { |
| 499 | return instruction_set_; |
| 500 | } |
| 501 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 502 | bool IsCompilingOsr() const { return osr_; } |
| 503 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 504 | bool HasTryCatch() const { return has_try_catch_; } |
| 505 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 506 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 507 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 508 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 509 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 510 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 511 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 512 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 513 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 514 | // The instruction has been inserted into the graph, either as a constant, or |
| 515 | // before cursor. |
| 516 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 517 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 518 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 519 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 520 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 521 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 522 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 523 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 524 | template <class InstructionType, typename ValueType> |
| 525 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 526 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 527 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 528 | // Try to find an existing constant of the given value. |
| 529 | InstructionType* constant = nullptr; |
| 530 | auto cached_constant = cache->find(value); |
| 531 | if (cached_constant != cache->end()) { |
| 532 | constant = cached_constant->second; |
| 533 | } |
| 534 | |
| 535 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 536 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 537 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 538 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 539 | cache->Overwrite(value, constant); |
| 540 | InsertConstant(constant); |
| 541 | } |
| 542 | return constant; |
| 543 | } |
| 544 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 545 | void InsertConstant(HConstant* instruction); |
| 546 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 547 | // Cache a float constant into the graph. This method should only be |
| 548 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 549 | void CacheFloatConstant(HFloatConstant* constant); |
| 550 | |
| 551 | // See CacheFloatConstant comment. |
| 552 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 553 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 554 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 555 | |
| 556 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 557 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 558 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 559 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 560 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 561 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 562 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 563 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 564 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 565 | HBasicBlock* entry_block_; |
| 566 | HBasicBlock* exit_block_; |
| 567 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 568 | // 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] | 569 | uint16_t maximum_number_of_out_vregs_; |
| 570 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 571 | // The number of virtual registers in this method. Contains the parameters. |
| 572 | uint16_t number_of_vregs_; |
| 573 | |
| 574 | // The number of virtual registers used by parameters of this method. |
| 575 | uint16_t number_of_in_vregs_; |
| 576 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 577 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 578 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 579 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 580 | // Has bounds checks. We can totally skip BCE if it's false. |
| 581 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 582 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 583 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 584 | // try/catch-related passes if false. |
| 585 | bool has_try_catch_; |
| 586 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 587 | // Flag whether there are any irreducible loops in the graph. |
| 588 | bool has_irreducible_loops_; |
| 589 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 590 | // Indicates whether the graph should be compiled in a way that |
| 591 | // ensures full debuggability. If false, we can apply more |
| 592 | // aggressive optimizations that may limit the level of debugging. |
| 593 | const bool debuggable_; |
| 594 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 595 | // 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] | 596 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 597 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 598 | // The dex file from which the method is from. |
| 599 | const DexFile& dex_file_; |
| 600 | |
| 601 | // The method index in the dex file. |
| 602 | const uint32_t method_idx_; |
| 603 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 604 | // If inlined, this encodes how the callee is being invoked. |
| 605 | const InvokeType invoke_type_; |
| 606 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 607 | // Whether the graph has been transformed to SSA form. Only used |
| 608 | // in debug mode to ensure we are not using properties only valid |
| 609 | // for non-SSA form (like the number of temporaries). |
| 610 | bool in_ssa_form_; |
| 611 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 612 | const bool should_generate_constructor_barrier_; |
| 613 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 614 | const InstructionSet instruction_set_; |
| 615 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 616 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 617 | HNullConstant* cached_null_constant_; |
| 618 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 619 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 620 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 621 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 622 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 623 | HCurrentMethod* cached_current_method_; |
| 624 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 625 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 626 | // for example for methods whose declaring class could not be resolved |
| 627 | // (such as when the superclass could not be found). |
| 628 | ArtMethod* art_method_; |
| 629 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 630 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 631 | // collection pointer to passes which may create NullConstant. |
| 632 | ReferenceTypeInfo inexact_object_rti_; |
| 633 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 634 | // Whether we are compiling this graph for on stack replacement: this will |
| 635 | // make all loops seen as irreducible and emit special stack maps to mark |
| 636 | // compiled code entries which the interpreter can directly jump to. |
| 637 | const bool osr_; |
| 638 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 639 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 640 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 641 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 642 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 643 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 644 | }; |
| 645 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 646 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 647 | public: |
| 648 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 649 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 650 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 651 | irreducible_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 652 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 653 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 654 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 655 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 656 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 657 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 658 | bool IsIrreducible() const { return irreducible_; } |
| 659 | |
| 660 | void Dump(std::ostream& os); |
| 661 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 662 | HBasicBlock* GetHeader() const { |
| 663 | return header_; |
| 664 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 665 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 666 | void SetHeader(HBasicBlock* block) { |
| 667 | header_ = block; |
| 668 | } |
| 669 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 670 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 671 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 672 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 673 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 674 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 675 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 678 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 679 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 680 | } |
| 681 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 682 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 683 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 684 | } |
| 685 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 686 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 687 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 690 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 691 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 692 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 693 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 694 | } |
| 695 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 696 | // Returns the lifetime position of the back edge that has the |
| 697 | // greatest lifetime position. |
| 698 | size_t GetLifetimeEnd() const; |
| 699 | |
| 700 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 701 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 702 | } |
| 703 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 704 | // Finds blocks that are part of this loop. |
| 705 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 706 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 707 | // Returns whether this loop information contains `block`. |
| 708 | // Note that this loop information *must* be populated before entering this function. |
| 709 | bool Contains(const HBasicBlock& block) const; |
| 710 | |
| 711 | // Returns whether this loop information is an inner loop of `other`. |
| 712 | // Note that `other` *must* be populated before entering this function. |
| 713 | bool IsIn(const HLoopInformation& other) const; |
| 714 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 715 | // Returns true if instruction is not defined within this loop. |
| 716 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 717 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 718 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 719 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 720 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 721 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 722 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 723 | void ClearAllBlocks() { |
| 724 | blocks_.ClearAllBits(); |
| 725 | } |
| 726 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 727 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 728 | // Internal recursive implementation of `Populate`. |
| 729 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 730 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 731 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 732 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 733 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 734 | bool irreducible_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 735 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 736 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 737 | |
| 738 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 739 | }; |
| 740 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 741 | // Stores try/catch information for basic blocks. |
| 742 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 743 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 744 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 745 | public: |
| 746 | // Try block information constructor. |
| 747 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 748 | : try_entry_(&try_entry), |
| 749 | catch_dex_file_(nullptr), |
| 750 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 751 | DCHECK(try_entry_ != nullptr); |
| 752 | } |
| 753 | |
| 754 | // Catch block information constructor. |
| 755 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 756 | : try_entry_(nullptr), |
| 757 | catch_dex_file_(&dex_file), |
| 758 | catch_type_index_(catch_type_index) {} |
| 759 | |
| 760 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 761 | |
| 762 | const HTryBoundary& GetTryEntry() const { |
| 763 | DCHECK(IsTryBlock()); |
| 764 | return *try_entry_; |
| 765 | } |
| 766 | |
| 767 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 768 | |
| 769 | bool IsCatchAllTypeIndex() const { |
| 770 | DCHECK(IsCatchBlock()); |
| 771 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 772 | } |
| 773 | |
| 774 | uint16_t GetCatchTypeIndex() const { |
| 775 | DCHECK(IsCatchBlock()); |
| 776 | return catch_type_index_; |
| 777 | } |
| 778 | |
| 779 | const DexFile& GetCatchDexFile() const { |
| 780 | DCHECK(IsCatchBlock()); |
| 781 | return *catch_dex_file_; |
| 782 | } |
| 783 | |
| 784 | private: |
| 785 | // One of possibly several TryBoundary instructions entering the block's try. |
| 786 | // Only set for try blocks. |
| 787 | const HTryBoundary* try_entry_; |
| 788 | |
| 789 | // Exception type information. Only set for catch blocks. |
| 790 | const DexFile* catch_dex_file_; |
| 791 | const uint16_t catch_type_index_; |
| 792 | }; |
| 793 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 794 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 795 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 796 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 797 | // A block in a method. Contains the list of instructions represented |
| 798 | // as a double linked list. Each block knows its predecessors and |
| 799 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 800 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 801 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 802 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 803 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 804 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 805 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 806 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 807 | loop_information_(nullptr), |
| 808 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 809 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 810 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 811 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 812 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 813 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 814 | try_catch_information_(nullptr) { |
| 815 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 816 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 817 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 818 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 819 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 820 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 821 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 824 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 825 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 826 | } |
| 827 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 828 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 829 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 830 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 831 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 832 | return ContainsElement(successors_, block, start_from); |
| 833 | } |
| 834 | |
| 835 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 836 | return dominated_blocks_; |
| 837 | } |
| 838 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 839 | bool IsEntryBlock() const { |
| 840 | return graph_->GetEntryBlock() == this; |
| 841 | } |
| 842 | |
| 843 | bool IsExitBlock() const { |
| 844 | return graph_->GetExitBlock() == this; |
| 845 | } |
| 846 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 847 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 848 | bool IsSingleTryBoundary() const; |
| 849 | |
| 850 | // Returns true if this block emits nothing but a jump. |
| 851 | bool IsSingleJump() const { |
| 852 | HLoopInformation* loop_info = GetLoopInformation(); |
| 853 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 854 | // Back edges generate a suspend check. |
| 855 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 856 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 857 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 858 | void AddBackEdge(HBasicBlock* back_edge) { |
| 859 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 860 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 861 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 862 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 863 | loop_information_->AddBackEdge(back_edge); |
| 864 | } |
| 865 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 866 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 867 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 868 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 869 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 870 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 871 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 872 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 873 | HBasicBlock* GetDominator() const { return dominator_; } |
| 874 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 875 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 876 | |
| 877 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 878 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 879 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 880 | |
| 881 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 882 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 883 | } |
| 884 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 885 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 886 | |
| 887 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 888 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 891 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 892 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 893 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 894 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 895 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 896 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 897 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 898 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 899 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 900 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 901 | successors_.push_back(block); |
| 902 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 905 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 906 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 907 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 908 | new_block->predecessors_.push_back(this); |
| 909 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 912 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 913 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 914 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 915 | new_block->successors_.push_back(this); |
| 916 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 917 | } |
| 918 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 919 | // Insert `this` between `predecessor` and `successor. This method |
| 920 | // preserves the indicies, and will update the first edge found between |
| 921 | // `predecessor` and `successor`. |
| 922 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 923 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 924 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 925 | successor->predecessors_[predecessor_index] = this; |
| 926 | predecessor->successors_[successor_index] = this; |
| 927 | successors_.push_back(successor); |
| 928 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 929 | } |
| 930 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 931 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 932 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 933 | } |
| 934 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 935 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 936 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 939 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 940 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 944 | predecessors_.push_back(block); |
| 945 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 946 | } |
| 947 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 948 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 949 | DCHECK_EQ(predecessors_.size(), 2u); |
| 950 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 951 | } |
| 952 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 953 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 954 | DCHECK_EQ(successors_.size(), 2u); |
| 955 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 956 | } |
| 957 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 958 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 959 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 960 | } |
| 961 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 962 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 963 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 964 | } |
| 965 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 966 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 967 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 968 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 972 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 973 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | // Returns whether the first occurrence of `predecessor` in the list of |
| 977 | // predecessors is at index `idx`. |
| 978 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 979 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 980 | return GetPredecessorIndexOf(predecessor) == idx; |
| 981 | } |
| 982 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 983 | // Create a new block between this block and its predecessors. The new block |
| 984 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 985 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 986 | // loop and try/catch information are not updated. |
| 987 | HBasicBlock* CreateImmediateDominator(); |
| 988 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 989 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 990 | // created, latter block. Note that this method will add the block to the |
| 991 | // graph, create a Goto at the end of the former block and will create an edge |
| 992 | // 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] | 993 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 994 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 995 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 996 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 997 | // created block. Note that this method just updates raw block information, |
| 998 | // like predecessors, successors, dominators, and instruction list. It does not |
| 999 | // update the graph, reverse post order, loop information, nor make sure the |
| 1000 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1001 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1002 | |
| 1003 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1004 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1005 | |
| 1006 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1007 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1008 | // that this method does not update the graph, reverse post order, loop |
| 1009 | // information, nor make sure the blocks are consistent (for example ending |
| 1010 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1011 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1012 | |
| 1013 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1014 | // of `this` are moved to `other`. |
| 1015 | // Note that this method does not update the graph, reverse post order, loop |
| 1016 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1017 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1018 | void ReplaceWith(HBasicBlock* other); |
| 1019 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1020 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1021 | // order, links to predecessors, successors, dominators and deletes the block |
| 1022 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1023 | // predecessor of `other` and vice versa. |
| 1024 | void MergeWith(HBasicBlock* other); |
| 1025 | |
| 1026 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1027 | // removes it from all loops it is included in and eventually from the graph. |
| 1028 | // The block must not dominate any other block. Predecessors and successors |
| 1029 | // are safely updated. |
| 1030 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1031 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1032 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1033 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1034 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1035 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1036 | // Replace instruction `initial` with `replacement` within this block. |
| 1037 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1038 | HInstruction* replacement); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1039 | void MoveInstructionBefore(HInstruction* insn, HInstruction* cursor); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1040 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1041 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1042 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1043 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1044 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1045 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1046 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1047 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1048 | |
| 1049 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1050 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1051 | } |
| 1052 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1053 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1054 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1055 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1056 | } |
| 1057 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1058 | bool IsFirstPredecessorBackEdge() const { |
| 1059 | DCHECK(IsLoopHeader()); |
| 1060 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1061 | } |
| 1062 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1063 | HLoopInformation* GetLoopInformation() const { |
| 1064 | return loop_information_; |
| 1065 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1066 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1067 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1068 | // 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] | 1069 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1070 | void SetInLoop(HLoopInformation* info) { |
| 1071 | if (IsLoopHeader()) { |
| 1072 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1073 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1074 | loop_information_ = info; |
| 1075 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1076 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1077 | // Note that a non loop header having a loop information means this loop information |
| 1078 | // has already been populated |
| 1079 | loop_information_ = info; |
| 1080 | } else { |
| 1081 | // Block is part of an inner loop. Do not update the loop information. |
| 1082 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1083 | // at this point, because this method is being called while populating `info`. |
| 1084 | } |
| 1085 | } |
| 1086 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1087 | // Raw update of the loop information. |
| 1088 | void SetLoopInformation(HLoopInformation* info) { |
| 1089 | loop_information_ = info; |
| 1090 | } |
| 1091 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1092 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1093 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1094 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1095 | |
| 1096 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1097 | try_catch_information_ = try_catch_information; |
| 1098 | } |
| 1099 | |
| 1100 | bool IsTryBlock() const { |
| 1101 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1102 | } |
| 1103 | |
| 1104 | bool IsCatchBlock() const { |
| 1105 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1106 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1107 | |
| 1108 | // Returns the try entry that this block's successors should have. They will |
| 1109 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1110 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1111 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1112 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1113 | bool HasThrowingInstructions() const; |
| 1114 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1115 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1116 | bool Dominates(HBasicBlock* block) const; |
| 1117 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1118 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1119 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1120 | |
| 1121 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1122 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1123 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1124 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1125 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1126 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1127 | bool HasSinglePhi() const; |
| 1128 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1129 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1130 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1131 | ArenaVector<HBasicBlock*> predecessors_; |
| 1132 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1133 | HInstructionList instructions_; |
| 1134 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1135 | HLoopInformation* loop_information_; |
| 1136 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1137 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1138 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1139 | // The dex program counter of the first instruction of this block. |
| 1140 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1141 | size_t lifetime_start_; |
| 1142 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1143 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1144 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1145 | friend class HGraph; |
| 1146 | friend class HInstruction; |
| 1147 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1148 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1149 | }; |
| 1150 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1151 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1152 | // from the innermost to the outermost. |
| 1153 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1154 | public: |
| 1155 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1156 | : current_(block.GetLoopInformation()) {} |
| 1157 | |
| 1158 | bool Done() const { return current_ == nullptr; } |
| 1159 | |
| 1160 | void Advance() { |
| 1161 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1162 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | HLoopInformation* Current() const { |
| 1166 | DCHECK(!Done()); |
| 1167 | return current_; |
| 1168 | } |
| 1169 | |
| 1170 | private: |
| 1171 | HLoopInformation* current_; |
| 1172 | |
| 1173 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1174 | }; |
| 1175 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1176 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1177 | M(Above, Condition) \ |
| 1178 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1179 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1180 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1181 | M(ArrayGet, Instruction) \ |
| 1182 | M(ArrayLength, Instruction) \ |
| 1183 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1184 | M(Below, Condition) \ |
| 1185 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1186 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1187 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1188 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1189 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1190 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1191 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1192 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1193 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1194 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1195 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1196 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1197 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1198 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1199 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1200 | M(Exit, Instruction) \ |
| 1201 | M(FloatConstant, Constant) \ |
| 1202 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1203 | M(GreaterThan, Condition) \ |
| 1204 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1205 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1206 | M(InstanceFieldGet, Instruction) \ |
| 1207 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1208 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1209 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1210 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1211 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1212 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1213 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1214 | M(LessThan, Condition) \ |
| 1215 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1216 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1217 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1218 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1219 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1220 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1221 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1222 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1223 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1224 | M(Neg, UnaryOperation) \ |
| 1225 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1226 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1227 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1228 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1229 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1230 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1231 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1232 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1233 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1234 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1235 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1236 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1237 | M(Return, Instruction) \ |
| 1238 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1239 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1240 | M(Shl, BinaryOperation) \ |
| 1241 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1242 | M(StaticFieldGet, Instruction) \ |
| 1243 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1244 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1245 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1246 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1247 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1248 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1249 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1250 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1251 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1252 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1253 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1254 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1255 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1256 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1257 | /* |
| 1258 | * Instructions, shared across several (not all) architectures. |
| 1259 | */ |
| 1260 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1261 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1262 | #else |
| 1263 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1264 | M(BitwiseNegatedRight, Instruction) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1265 | M(MultiplyAccumulate, Instruction) |
| 1266 | #endif |
| 1267 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1268 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1269 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1270 | #else |
| 1271 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1272 | M(ArmDexCacheArraysBase, Instruction) |
| 1273 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1274 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1275 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1276 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1277 | #else |
| 1278 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1279 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1280 | M(Arm64IntermediateAddress, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1281 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1282 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1283 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1284 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1285 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1286 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1287 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1288 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1289 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1290 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1291 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1292 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1293 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1294 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1295 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1296 | |
| 1297 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1298 | |
| 1299 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1300 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1301 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1302 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1303 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1304 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1305 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1306 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1307 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1308 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1309 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1310 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1311 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1312 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1313 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1314 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1315 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1316 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1317 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1318 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1319 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1320 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1321 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1322 | #undef FORWARD_DECLARATION |
| 1323 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1324 | #define DECLARE_INSTRUCTION(type) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1325 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1326 | const char* DebugName() const OVERRIDE { return #type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1327 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1328 | return other->Is##type(); \ |
| 1329 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1330 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1331 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1332 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1333 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1334 | const H##type* As##type() const { return this; } \ |
| 1335 | H##type* As##type() { return this; } |
| 1336 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1337 | template <typename T> class HUseList; |
| 1338 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1339 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1340 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1341 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1342 | HUseListNode* GetPrevious() const { return prev_; } |
| 1343 | HUseListNode* GetNext() const { return next_; } |
| 1344 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1345 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1346 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1347 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1348 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1349 | HUseListNode(T user, size_t index) |
| 1350 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1351 | |
| 1352 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1353 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1354 | HUseListNode<T>* prev_; |
| 1355 | HUseListNode<T>* next_; |
| 1356 | |
| 1357 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1358 | |
| 1359 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1360 | }; |
| 1361 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1362 | template <typename T> |
| 1363 | class HUseList : public ValueObject { |
| 1364 | public: |
| 1365 | HUseList() : first_(nullptr) {} |
| 1366 | |
| 1367 | void Clear() { |
| 1368 | first_ = nullptr; |
| 1369 | } |
| 1370 | |
| 1371 | // Adds a new entry at the beginning of the use list and returns |
| 1372 | // the newly created node. |
| 1373 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1374 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1375 | if (IsEmpty()) { |
| 1376 | first_ = new_node; |
| 1377 | } else { |
| 1378 | first_->prev_ = new_node; |
| 1379 | new_node->next_ = first_; |
| 1380 | first_ = new_node; |
| 1381 | } |
| 1382 | return new_node; |
| 1383 | } |
| 1384 | |
| 1385 | HUseListNode<T>* GetFirst() const { |
| 1386 | return first_; |
| 1387 | } |
| 1388 | |
| 1389 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1390 | DCHECK(node != nullptr); |
| 1391 | DCHECK(Contains(node)); |
| 1392 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1393 | if (node->prev_ != nullptr) { |
| 1394 | node->prev_->next_ = node->next_; |
| 1395 | } |
| 1396 | if (node->next_ != nullptr) { |
| 1397 | node->next_->prev_ = node->prev_; |
| 1398 | } |
| 1399 | if (node == first_) { |
| 1400 | first_ = node->next_; |
| 1401 | } |
| 1402 | } |
| 1403 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1404 | bool Contains(const HUseListNode<T>* node) const { |
| 1405 | if (node == nullptr) { |
| 1406 | return false; |
| 1407 | } |
| 1408 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1409 | if (current == node) { |
| 1410 | return true; |
| 1411 | } |
| 1412 | } |
| 1413 | return false; |
| 1414 | } |
| 1415 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1416 | bool IsEmpty() const { |
| 1417 | return first_ == nullptr; |
| 1418 | } |
| 1419 | |
| 1420 | bool HasOnlyOneUse() const { |
| 1421 | return first_ != nullptr && first_->next_ == nullptr; |
| 1422 | } |
| 1423 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1424 | size_t SizeSlow() const { |
| 1425 | size_t count = 0; |
| 1426 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1427 | ++count; |
| 1428 | } |
| 1429 | return count; |
| 1430 | } |
| 1431 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1432 | private: |
| 1433 | HUseListNode<T>* first_; |
| 1434 | }; |
| 1435 | |
| 1436 | template<typename T> |
| 1437 | class HUseIterator : public ValueObject { |
| 1438 | public: |
| 1439 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1440 | |
| 1441 | bool Done() const { return current_ == nullptr; } |
| 1442 | |
| 1443 | void Advance() { |
| 1444 | DCHECK(!Done()); |
| 1445 | current_ = current_->GetNext(); |
| 1446 | } |
| 1447 | |
| 1448 | HUseListNode<T>* Current() const { |
| 1449 | DCHECK(!Done()); |
| 1450 | return current_; |
| 1451 | } |
| 1452 | |
| 1453 | private: |
| 1454 | HUseListNode<T>* current_; |
| 1455 | |
| 1456 | friend class HValue; |
| 1457 | }; |
| 1458 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1459 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1460 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1461 | // by the used instructions. |
| 1462 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1463 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1464 | public: |
| 1465 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1466 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1467 | |
| 1468 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1469 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1470 | DCHECK(instruction_ != nullptr); |
| 1471 | DCHECK(use_node_ != nullptr); |
| 1472 | DCHECK(old_record.use_node_ == nullptr); |
| 1473 | } |
| 1474 | |
| 1475 | HInstruction* GetInstruction() const { return instruction_; } |
| 1476 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1477 | |
| 1478 | private: |
| 1479 | // Instruction used by the user. |
| 1480 | HInstruction* instruction_; |
| 1481 | |
| 1482 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1483 | HUseListNode<T>* use_node_; |
| 1484 | }; |
| 1485 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1486 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1487 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1488 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1489 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1490 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1491 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1492 | * modify the value of a reference field read [although it may modify the |
| 1493 | * reference fetch prior to reading the field, which is represented by its own |
| 1494 | * write/read dependence]). The analysis makes conservative points-to |
| 1495 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1496 | * the same, and any reference read depends on any reference read without |
| 1497 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1498 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1499 | * The internal representation uses 38-bit and is described in the table below. |
| 1500 | * The first line indicates the side effect, and for field/array accesses the |
| 1501 | * second line indicates the type of the access (in the order of the |
| 1502 | * Primitive::Type enum). |
| 1503 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1504 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1505 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1506 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1507 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1508 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1509 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1510 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1511 | * |
| 1512 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1513 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1514 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1515 | class SideEffects : public ValueObject { |
| 1516 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1517 | SideEffects() : flags_(0) {} |
| 1518 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1519 | static SideEffects None() { |
| 1520 | return SideEffects(0); |
| 1521 | } |
| 1522 | |
| 1523 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1524 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1525 | } |
| 1526 | |
| 1527 | static SideEffects AllChanges() { |
| 1528 | return SideEffects(kAllChangeBits); |
| 1529 | } |
| 1530 | |
| 1531 | static SideEffects AllDependencies() { |
| 1532 | return SideEffects(kAllDependOnBits); |
| 1533 | } |
| 1534 | |
| 1535 | static SideEffects AllExceptGCDependency() { |
| 1536 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1537 | } |
| 1538 | |
| 1539 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1540 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1541 | } |
| 1542 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1543 | static SideEffects AllWrites() { |
| 1544 | return SideEffects(kAllWrites); |
| 1545 | } |
| 1546 | |
| 1547 | static SideEffects AllReads() { |
| 1548 | return SideEffects(kAllReads); |
| 1549 | } |
| 1550 | |
| 1551 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1552 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1553 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1554 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1555 | } |
| 1556 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1557 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1558 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1559 | } |
| 1560 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1561 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1562 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1563 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1564 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1568 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1571 | static SideEffects CanTriggerGC() { |
| 1572 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1573 | } |
| 1574 | |
| 1575 | static SideEffects DependsOnGC() { |
| 1576 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1577 | } |
| 1578 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1579 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1580 | SideEffects Union(SideEffects other) const { |
| 1581 | return SideEffects(flags_ | other.flags_); |
| 1582 | } |
| 1583 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1584 | SideEffects Exclusion(SideEffects other) const { |
| 1585 | return SideEffects(flags_ & ~other.flags_); |
| 1586 | } |
| 1587 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1588 | void Add(SideEffects other) { |
| 1589 | flags_ |= other.flags_; |
| 1590 | } |
| 1591 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1592 | bool Includes(SideEffects other) const { |
| 1593 | return (other.flags_ & flags_) == other.flags_; |
| 1594 | } |
| 1595 | |
| 1596 | bool HasSideEffects() const { |
| 1597 | return (flags_ & kAllChangeBits); |
| 1598 | } |
| 1599 | |
| 1600 | bool HasDependencies() const { |
| 1601 | return (flags_ & kAllDependOnBits); |
| 1602 | } |
| 1603 | |
| 1604 | // Returns true if there are no side effects or dependencies. |
| 1605 | bool DoesNothing() const { |
| 1606 | return flags_ == 0; |
| 1607 | } |
| 1608 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1609 | // Returns true if something is written. |
| 1610 | bool DoesAnyWrite() const { |
| 1611 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1612 | } |
| 1613 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1614 | // Returns true if something is read. |
| 1615 | bool DoesAnyRead() const { |
| 1616 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1617 | } |
| 1618 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1619 | // Returns true if potentially everything is written and read |
| 1620 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1621 | bool DoesAllReadWrite() const { |
| 1622 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1623 | } |
| 1624 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1625 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1626 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1629 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1630 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1631 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1632 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1636 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1637 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1638 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1639 | for (int s = kLastBit; s >= 0; s--) { |
| 1640 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1641 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1642 | // This is a bit for the GC side effect. |
| 1643 | if (current_bit_is_set) { |
| 1644 | flags += "GC"; |
| 1645 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1646 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1647 | } else { |
| 1648 | // This is a bit for the array/field analysis. |
| 1649 | // The underscore character stands for the 'can trigger GC' bit. |
| 1650 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1651 | if (current_bit_is_set) { |
| 1652 | flags += kDebug[s]; |
| 1653 | } |
| 1654 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1655 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1656 | flags += "|"; |
| 1657 | } |
| 1658 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1659 | } |
| 1660 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1663 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1664 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1665 | private: |
| 1666 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1667 | |
| 1668 | static constexpr int kFieldWriteOffset = 0; |
| 1669 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1670 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1671 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1672 | |
| 1673 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1674 | |
| 1675 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1676 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1677 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1678 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1679 | |
| 1680 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1681 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1682 | |
| 1683 | // Aliases. |
| 1684 | |
| 1685 | static_assert(kChangeBits == kDependOnBits, |
| 1686 | "the 'change' bits should match the 'depend on' bits."); |
| 1687 | |
| 1688 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1689 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1690 | static constexpr uint64_t kAllWrites = |
| 1691 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1692 | static constexpr uint64_t kAllReads = |
| 1693 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1694 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1695 | // Translates type to bit flag. |
| 1696 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1697 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1698 | const uint64_t one = 1; |
| 1699 | const int shift = type; // 0-based consecutive enum |
| 1700 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1701 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1702 | return one << (type + offset); |
| 1703 | } |
| 1704 | |
| 1705 | // Private constructor on direct flags value. |
| 1706 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1707 | |
| 1708 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1709 | }; |
| 1710 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1711 | // 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] | 1712 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1713 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1714 | HEnvironment(ArenaAllocator* arena, |
| 1715 | size_t number_of_vregs, |
| 1716 | const DexFile& dex_file, |
| 1717 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1718 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1719 | InvokeType invoke_type, |
| 1720 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1721 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1722 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1723 | parent_(nullptr), |
| 1724 | dex_file_(dex_file), |
| 1725 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1726 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1727 | invoke_type_(invoke_type), |
| 1728 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1729 | } |
| 1730 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1731 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1732 | : HEnvironment(arena, |
| 1733 | to_copy.Size(), |
| 1734 | to_copy.GetDexFile(), |
| 1735 | to_copy.GetMethodIdx(), |
| 1736 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1737 | to_copy.GetInvokeType(), |
| 1738 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1739 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1740 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1741 | if (parent_ != nullptr) { |
| 1742 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1743 | } else { |
| 1744 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1745 | parent_->CopyFrom(parent); |
| 1746 | if (parent->GetParent() != nullptr) { |
| 1747 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1748 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1749 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1752 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1753 | void CopyFrom(HEnvironment* environment); |
| 1754 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1755 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1756 | // input to the loop phi instead. This is for inserting instructions that |
| 1757 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1758 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1759 | |
| 1760 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1761 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1765 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1768 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1769 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1770 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1771 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1772 | HEnvironment* GetParent() const { return parent_; } |
| 1773 | |
| 1774 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1775 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1779 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | uint32_t GetDexPc() const { |
| 1783 | return dex_pc_; |
| 1784 | } |
| 1785 | |
| 1786 | uint32_t GetMethodIdx() const { |
| 1787 | return method_idx_; |
| 1788 | } |
| 1789 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1790 | InvokeType GetInvokeType() const { |
| 1791 | return invoke_type_; |
| 1792 | } |
| 1793 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1794 | const DexFile& GetDexFile() const { |
| 1795 | return dex_file_; |
| 1796 | } |
| 1797 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1798 | HInstruction* GetHolder() const { |
| 1799 | return holder_; |
| 1800 | } |
| 1801 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1802 | |
| 1803 | bool IsFromInlinedInvoke() const { |
| 1804 | return GetParent() != nullptr; |
| 1805 | } |
| 1806 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1807 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1808 | // Record instructions' use entries of this environment for constant-time removal. |
| 1809 | // It should only be called by HInstruction when a new environment use is added. |
| 1810 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1811 | DCHECK(env_use->GetUser() == this); |
| 1812 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1813 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1814 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1815 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1816 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1817 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1818 | HEnvironment* parent_; |
| 1819 | const DexFile& dex_file_; |
| 1820 | const uint32_t method_idx_; |
| 1821 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1822 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1823 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1824 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1825 | HInstruction* const holder_; |
| 1826 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1827 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1828 | |
| 1829 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1830 | }; |
| 1831 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1832 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1833 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1834 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1835 | : previous_(nullptr), |
| 1836 | next_(nullptr), |
| 1837 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1838 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1839 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1840 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1841 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1842 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1843 | locations_(nullptr), |
| 1844 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1845 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1846 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1847 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1848 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1849 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1850 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1851 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1852 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1853 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1854 | enum InstructionKind { |
| 1855 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1856 | }; |
| 1857 | #undef DECLARE_KIND |
| 1858 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1859 | HInstruction* GetNext() const { return next_; } |
| 1860 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1861 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1862 | HInstruction* GetNextDisregardingMoves() const; |
| 1863 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1864 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1865 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1866 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1867 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1868 | bool IsInBlock() const { return block_ != nullptr; } |
| 1869 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1870 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1871 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1872 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1873 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1874 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1875 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1876 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1877 | |
| 1878 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1879 | virtual const char* DebugName() const = 0; |
| 1880 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1881 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1882 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1883 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1884 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1885 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1886 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1887 | |
| 1888 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1889 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1890 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1891 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1892 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1893 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1894 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1895 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1896 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1897 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1898 | // Does not apply for all instructions, but having this at top level greatly |
| 1899 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1900 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1901 | virtual bool CanBeNull() const { |
| 1902 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1903 | return true; |
| 1904 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1905 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1906 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1907 | return false; |
| 1908 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1909 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1910 | virtual bool IsActualObject() const { |
| 1911 | return GetType() == Primitive::kPrimNot; |
| 1912 | } |
| 1913 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1914 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1915 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1916 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1917 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1918 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame^] | 1919 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1920 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1921 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1922 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1923 | DCHECK(user != nullptr); |
| 1924 | HUseListNode<HInstruction*>* use = |
| 1925 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1926 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1929 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1930 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1931 | HUseListNode<HEnvironment*>* env_use = |
| 1932 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1933 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1934 | } |
| 1935 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1936 | void RemoveAsUserOfInput(size_t input) { |
| 1937 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1938 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1939 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1940 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1941 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1942 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1943 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1944 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1945 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1946 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1947 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1948 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1949 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1950 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1951 | // Does this instruction strictly dominate `other_instruction`? |
| 1952 | // Returns false if this instruction and `other_instruction` are the same. |
| 1953 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1954 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1955 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1956 | int GetId() const { return id_; } |
| 1957 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1958 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1959 | int GetSsaIndex() const { return ssa_index_; } |
| 1960 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1961 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1962 | |
| 1963 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1964 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1965 | // Set the `environment_` field. Raw because this method does not |
| 1966 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1967 | void SetRawEnvironment(HEnvironment* environment) { |
| 1968 | DCHECK(environment_ == nullptr); |
| 1969 | DCHECK_EQ(environment->GetHolder(), this); |
| 1970 | environment_ = environment; |
| 1971 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1972 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1973 | void RemoveEnvironment(); |
| 1974 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1975 | // Set the environment of this instruction, copying it from `environment`. While |
| 1976 | // copying, the uses lists are being updated. |
| 1977 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1978 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1979 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1980 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1981 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1982 | if (environment->GetParent() != nullptr) { |
| 1983 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1984 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1985 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1986 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1987 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1988 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1989 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1990 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1991 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1992 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1993 | if (environment->GetParent() != nullptr) { |
| 1994 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1995 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1998 | // Returns the number of entries in the environment. Typically, that is the |
| 1999 | // number of dex registers in a method. It could be more in case of inlining. |
| 2000 | size_t EnvironmentSize() const; |
| 2001 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2002 | LocationSummary* GetLocations() const { return locations_; } |
| 2003 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2004 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2005 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2006 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2007 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2008 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2009 | // uses of this instruction by `other` are *not* updated. |
| 2010 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2011 | ReplaceWith(other); |
| 2012 | other->ReplaceInput(this, use_index); |
| 2013 | } |
| 2014 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2015 | // Move `this` instruction before `cursor`. |
| 2016 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2017 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2018 | // Move `this` before its first user and out of any loops. If there is no |
| 2019 | // out-of-loop user that dominates all other users, move the instruction |
| 2020 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2021 | // |
| 2022 | // This can be used only on non-throwing instructions with no side effects that |
| 2023 | // have at least one use but no environment uses. |
| 2024 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2025 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2026 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2027 | bool Is##type() const; \ |
| 2028 | const H##type* As##type() const; \ |
| 2029 | H##type* As##type(); |
| 2030 | |
| 2031 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2032 | #undef INSTRUCTION_TYPE_CHECK |
| 2033 | |
| 2034 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2035 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2036 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2037 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2038 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2039 | #undef INSTRUCTION_TYPE_CHECK |
| 2040 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2041 | // Returns whether the instruction can be moved within the graph. |
| 2042 | virtual bool CanBeMoved() const { return false; } |
| 2043 | |
| 2044 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2045 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2046 | return false; |
| 2047 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2048 | |
| 2049 | // Returns whether any data encoded in the two instructions is equal. |
| 2050 | // This method does not look at the inputs. Both instructions must be |
| 2051 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2052 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2053 | return false; |
| 2054 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2055 | |
| 2056 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2057 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2058 | // 2) Their inputs are identical. |
| 2059 | bool Equals(HInstruction* other) const; |
| 2060 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2061 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2062 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2063 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2064 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2065 | InstructionKind GetKind() const PURE; |
| 2066 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2067 | |
| 2068 | virtual size_t ComputeHashCode() const { |
| 2069 | size_t result = GetKind(); |
| 2070 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2071 | result = (result * 31) + InputAt(i)->GetId(); |
| 2072 | } |
| 2073 | return result; |
| 2074 | } |
| 2075 | |
| 2076 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2077 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2078 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2079 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2080 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2081 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2082 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2083 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2084 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2085 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2086 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2087 | |
| 2088 | // Returns whether the code generation of the instruction will require to have access |
| 2089 | // to the current method. Such instructions are: |
| 2090 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2091 | // to walk the stack and have the current method stored at a specific stack address. |
| 2092 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2093 | // fields of the current method. |
| 2094 | bool NeedsCurrentMethod() const { |
| 2095 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2096 | } |
| 2097 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2098 | // Returns whether the code generation of the instruction will require to have access |
| 2099 | // to the dex cache of the current method's declaring class via the current method. |
| 2100 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2101 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2102 | // Does this instruction have any use in an environment before |
| 2103 | // control flow hits 'other'? |
| 2104 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2105 | |
| 2106 | // Remove all references to environment uses of this instruction. |
| 2107 | // The caller must ensure that this is safe to do. |
| 2108 | void RemoveEnvironmentUsers(); |
| 2109 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2110 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2111 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2112 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2113 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2114 | // If set, the machine code for this instruction is assumed to be generated by |
| 2115 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2116 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2117 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2118 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2119 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2120 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2121 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2122 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 2123 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2124 | uint32_t GetPackedFields() const { |
| 2125 | return packed_fields_; |
| 2126 | } |
| 2127 | |
| 2128 | template <size_t flag> |
| 2129 | bool GetPackedFlag() const { |
| 2130 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2131 | } |
| 2132 | |
| 2133 | template <size_t flag> |
| 2134 | void SetPackedFlag(bool value = true) { |
| 2135 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2136 | } |
| 2137 | |
| 2138 | template <typename BitFieldType> |
| 2139 | typename BitFieldType::value_type GetPackedField() const { |
| 2140 | return BitFieldType::Decode(packed_fields_); |
| 2141 | } |
| 2142 | |
| 2143 | template <typename BitFieldType> |
| 2144 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2145 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2146 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2147 | } |
| 2148 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2149 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2150 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2151 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2152 | HInstruction* previous_; |
| 2153 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2154 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2155 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2156 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2157 | // An instruction gets an id when it is added to the graph. |
| 2158 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2159 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2160 | int id_; |
| 2161 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2162 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2163 | int ssa_index_; |
| 2164 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2165 | // Packed fields. |
| 2166 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2167 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2168 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2169 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2170 | |
| 2171 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2172 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2173 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2174 | // The environment associated with this instruction. Not null if the instruction |
| 2175 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2176 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2177 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2178 | // Set by the code generator. |
| 2179 | LocationSummary* locations_; |
| 2180 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2181 | // Set by the liveness analysis. |
| 2182 | LiveInterval* live_interval_; |
| 2183 | |
| 2184 | // Set by the liveness analysis, this is the position in a linear |
| 2185 | // order of blocks where this instruction's live interval start. |
| 2186 | size_t lifetime_position_; |
| 2187 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2188 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2189 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2190 | // The reference handle part of the reference type info. |
| 2191 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2192 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2193 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2194 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2195 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2196 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2197 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2198 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2199 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2200 | |
| 2201 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2202 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2203 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2204 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2205 | class HInputIterator : public ValueObject { |
| 2206 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2207 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2208 | |
| 2209 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2210 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2211 | void Advance() { index_++; } |
| 2212 | |
| 2213 | private: |
| 2214 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2215 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2216 | |
| 2217 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2218 | }; |
| 2219 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2220 | class HInstructionIterator : public ValueObject { |
| 2221 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2222 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2223 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2224 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2225 | } |
| 2226 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2227 | bool Done() const { return instruction_ == nullptr; } |
| 2228 | HInstruction* Current() const { return instruction_; } |
| 2229 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2230 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2231 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | private: |
| 2235 | HInstruction* instruction_; |
| 2236 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2237 | |
| 2238 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2239 | }; |
| 2240 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2241 | class HBackwardInstructionIterator : public ValueObject { |
| 2242 | public: |
| 2243 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2244 | : instruction_(instructions.last_instruction_) { |
| 2245 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2246 | } |
| 2247 | |
| 2248 | bool Done() const { return instruction_ == nullptr; } |
| 2249 | HInstruction* Current() const { return instruction_; } |
| 2250 | void Advance() { |
| 2251 | instruction_ = next_; |
| 2252 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2253 | } |
| 2254 | |
| 2255 | private: |
| 2256 | HInstruction* instruction_; |
| 2257 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2258 | |
| 2259 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2260 | }; |
| 2261 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2262 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2263 | class HTemplateInstruction: public HInstruction { |
| 2264 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2265 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2266 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2267 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2268 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2269 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2270 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2271 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2272 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2273 | DCHECK_LT(i, N); |
| 2274 | return inputs_[i]; |
| 2275 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2276 | |
| 2277 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2278 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2279 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2280 | } |
| 2281 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2282 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2283 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2284 | |
| 2285 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2286 | }; |
| 2287 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2288 | // HTemplateInstruction specialization for N=0. |
| 2289 | template<> |
| 2290 | class HTemplateInstruction<0>: public HInstruction { |
| 2291 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2292 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2293 | : HInstruction(side_effects, dex_pc) {} |
| 2294 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2295 | virtual ~HTemplateInstruction() {} |
| 2296 | |
| 2297 | size_t InputCount() const OVERRIDE { return 0; } |
| 2298 | |
| 2299 | protected: |
| 2300 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2301 | LOG(FATAL) << "Unreachable"; |
| 2302 | UNREACHABLE(); |
| 2303 | } |
| 2304 | |
| 2305 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2306 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2307 | LOG(FATAL) << "Unreachable"; |
| 2308 | UNREACHABLE(); |
| 2309 | } |
| 2310 | |
| 2311 | private: |
| 2312 | friend class SsaBuilder; |
| 2313 | }; |
| 2314 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2315 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2316 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2317 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2318 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2319 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2320 | this->template SetPackedField<TypeField>(type); |
| 2321 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2322 | virtual ~HExpression() {} |
| 2323 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2324 | Primitive::Type GetType() const OVERRIDE { |
| 2325 | return TypeField::Decode(this->GetPackedFields()); |
| 2326 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2327 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2328 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2329 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2330 | static constexpr size_t kFieldTypeSize = |
| 2331 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2332 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2333 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2334 | "Too many packed fields."); |
| 2335 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2336 | }; |
| 2337 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2338 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2339 | // instruction that branches to the exit block. |
| 2340 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2341 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2342 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2343 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2344 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2345 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2346 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2347 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2348 | |
| 2349 | private: |
| 2350 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2351 | }; |
| 2352 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2353 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2354 | // instruction that branches to the exit block. |
| 2355 | class HReturn : public HTemplateInstruction<1> { |
| 2356 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2357 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2358 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2359 | SetRawInputAt(0, value); |
| 2360 | } |
| 2361 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2362 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2363 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2364 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2365 | |
| 2366 | private: |
| 2367 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2368 | }; |
| 2369 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2370 | class HPhi : public HInstruction { |
| 2371 | public: |
| 2372 | HPhi(ArenaAllocator* arena, |
| 2373 | uint32_t reg_number, |
| 2374 | size_t number_of_inputs, |
| 2375 | Primitive::Type type, |
| 2376 | uint32_t dex_pc = kNoDexPc) |
| 2377 | : HInstruction(SideEffects::None(), dex_pc), |
| 2378 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
| 2379 | reg_number_(reg_number) { |
| 2380 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2381 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2382 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2383 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2384 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2385 | SetPackedFlag<kFlagIsLive>(true); |
| 2386 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2387 | } |
| 2388 | |
| 2389 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2390 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2391 | return Primitive::PrimitiveKind(type); |
| 2392 | } |
| 2393 | |
| 2394 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2395 | |
| 2396 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
| 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 | |
| 2423 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 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 | |
| 2446 | protected: |
| 2447 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 2448 | return inputs_[index]; |
| 2449 | } |
| 2450 | |
| 2451 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
| 2452 | inputs_[index] = input; |
| 2453 | } |
| 2454 | |
| 2455 | private: |
| 2456 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2457 | static constexpr size_t kFieldTypeSize = |
| 2458 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2459 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2460 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2461 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2462 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2463 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2464 | |
| 2465 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
| 2466 | const uint32_t reg_number_; |
| 2467 | |
| 2468 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2469 | }; |
| 2470 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2471 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2472 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2473 | // exit block. |
| 2474 | class HExit : public HTemplateInstruction<0> { |
| 2475 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2476 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2477 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2478 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2479 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2480 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2481 | |
| 2482 | private: |
| 2483 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2484 | }; |
| 2485 | |
| 2486 | // Jumps from one block to another. |
| 2487 | class HGoto : public HTemplateInstruction<0> { |
| 2488 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2489 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2490 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2491 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2492 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2493 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2494 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2495 | } |
| 2496 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2497 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2498 | |
| 2499 | private: |
| 2500 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2501 | }; |
| 2502 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2503 | class HConstant : public HExpression<0> { |
| 2504 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2505 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2506 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2507 | |
| 2508 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2509 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2510 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2511 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2512 | // Is this constant 0 in the arithmetic sense? |
| 2513 | virtual bool IsArithmeticZero() const { return false; } |
| 2514 | // Is this constant a 0-bit pattern? |
| 2515 | virtual bool IsZeroBitPattern() const { return false; } |
| 2516 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2517 | virtual bool IsOne() const { return false; } |
| 2518 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2519 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2520 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2521 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2522 | |
| 2523 | private: |
| 2524 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2525 | }; |
| 2526 | |
| 2527 | class HNullConstant : public HConstant { |
| 2528 | public: |
| 2529 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2530 | return true; |
| 2531 | } |
| 2532 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2533 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2534 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2535 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2536 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2537 | // The null constant representation is a 0-bit pattern. |
| 2538 | virtual bool IsZeroBitPattern() const { return true; } |
| 2539 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2540 | DECLARE_INSTRUCTION(NullConstant); |
| 2541 | |
| 2542 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2543 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2544 | |
| 2545 | friend class HGraph; |
| 2546 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2547 | }; |
| 2548 | |
| 2549 | // Constants of the type int. Those can be from Dex instructions, or |
| 2550 | // synthesized (for example with the if-eqz instruction). |
| 2551 | class HIntConstant : public HConstant { |
| 2552 | public: |
| 2553 | int32_t GetValue() const { return value_; } |
| 2554 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2555 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2556 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2557 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2558 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2559 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2560 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2561 | return other->AsIntConstant()->value_ == value_; |
| 2562 | } |
| 2563 | |
| 2564 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2565 | |
| 2566 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2567 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2568 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2569 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2570 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2571 | // Integer constants are used to encode Boolean values as well, |
| 2572 | // where 1 means true and 0 means false. |
| 2573 | bool IsTrue() const { return GetValue() == 1; } |
| 2574 | bool IsFalse() const { return GetValue() == 0; } |
| 2575 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2576 | DECLARE_INSTRUCTION(IntConstant); |
| 2577 | |
| 2578 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2579 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2580 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2581 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2582 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2583 | |
| 2584 | const int32_t value_; |
| 2585 | |
| 2586 | friend class HGraph; |
| 2587 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2588 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2589 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2590 | }; |
| 2591 | |
| 2592 | class HLongConstant : public HConstant { |
| 2593 | public: |
| 2594 | int64_t GetValue() const { return value_; } |
| 2595 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2596 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2597 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2598 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2599 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2600 | return other->AsLongConstant()->value_ == value_; |
| 2601 | } |
| 2602 | |
| 2603 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2604 | |
| 2605 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2606 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2607 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2608 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2609 | |
| 2610 | DECLARE_INSTRUCTION(LongConstant); |
| 2611 | |
| 2612 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2613 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2614 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2615 | |
| 2616 | const int64_t value_; |
| 2617 | |
| 2618 | friend class HGraph; |
| 2619 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2620 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2621 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2622 | class HFloatConstant : public HConstant { |
| 2623 | public: |
| 2624 | float GetValue() const { return value_; } |
| 2625 | |
| 2626 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2627 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2628 | } |
| 2629 | |
| 2630 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2631 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2632 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2633 | } |
| 2634 | |
| 2635 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2636 | |
| 2637 | bool IsMinusOne() const OVERRIDE { |
| 2638 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2639 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2640 | bool IsArithmeticZero() const OVERRIDE { |
| 2641 | return std::fpclassify(value_) == FP_ZERO; |
| 2642 | } |
| 2643 | bool IsArithmeticPositiveZero() const { |
| 2644 | return IsArithmeticZero() && !std::signbit(value_); |
| 2645 | } |
| 2646 | bool IsArithmeticNegativeZero() const { |
| 2647 | return IsArithmeticZero() && std::signbit(value_); |
| 2648 | } |
| 2649 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2650 | 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] | 2651 | } |
| 2652 | bool IsOne() const OVERRIDE { |
| 2653 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2654 | } |
| 2655 | bool IsNaN() const { |
| 2656 | return std::isnan(value_); |
| 2657 | } |
| 2658 | |
| 2659 | DECLARE_INSTRUCTION(FloatConstant); |
| 2660 | |
| 2661 | private: |
| 2662 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2663 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2664 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2665 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2666 | |
| 2667 | const float value_; |
| 2668 | |
| 2669 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2670 | friend class SsaBuilder; |
| 2671 | friend class HGraph; |
| 2672 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2673 | }; |
| 2674 | |
| 2675 | class HDoubleConstant : public HConstant { |
| 2676 | public: |
| 2677 | double GetValue() const { return value_; } |
| 2678 | |
| 2679 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2680 | |
| 2681 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2682 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2683 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2684 | } |
| 2685 | |
| 2686 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2687 | |
| 2688 | bool IsMinusOne() const OVERRIDE { |
| 2689 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2690 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2691 | bool IsArithmeticZero() const OVERRIDE { |
| 2692 | return std::fpclassify(value_) == FP_ZERO; |
| 2693 | } |
| 2694 | bool IsArithmeticPositiveZero() const { |
| 2695 | return IsArithmeticZero() && !std::signbit(value_); |
| 2696 | } |
| 2697 | bool IsArithmeticNegativeZero() const { |
| 2698 | return IsArithmeticZero() && std::signbit(value_); |
| 2699 | } |
| 2700 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2701 | 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] | 2702 | } |
| 2703 | bool IsOne() const OVERRIDE { |
| 2704 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2705 | } |
| 2706 | bool IsNaN() const { |
| 2707 | return std::isnan(value_); |
| 2708 | } |
| 2709 | |
| 2710 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2711 | |
| 2712 | private: |
| 2713 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2714 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2715 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2716 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2717 | |
| 2718 | const double value_; |
| 2719 | |
| 2720 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2721 | friend class SsaBuilder; |
| 2722 | friend class HGraph; |
| 2723 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2724 | }; |
| 2725 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2726 | // Conditional branch. A block ending with an HIf instruction must have |
| 2727 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2728 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2729 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2730 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2731 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2732 | SetRawInputAt(0, input); |
| 2733 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2734 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2735 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2736 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2737 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2738 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2742 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2743 | } |
| 2744 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2745 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2746 | |
| 2747 | private: |
| 2748 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2749 | }; |
| 2750 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2751 | |
| 2752 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2753 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2754 | // non-exceptional control flow. |
| 2755 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2756 | // higher indices in no particular order. |
| 2757 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2758 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2759 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2760 | kEntry, |
| 2761 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2762 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2763 | }; |
| 2764 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2765 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2766 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2767 | SetPackedField<BoundaryKindField>(kind); |
| 2768 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2769 | |
| 2770 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2771 | |
| 2772 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2773 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2774 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2775 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2776 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2777 | } |
| 2778 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2779 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2780 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2781 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2782 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2783 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | // If not present already, adds `handler` to its block's list of exception |
| 2787 | // handlers. |
| 2788 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2789 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2790 | GetBlock()->AddSuccessor(handler); |
| 2791 | } |
| 2792 | } |
| 2793 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2794 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2795 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2796 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2797 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2798 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2799 | DECLARE_INSTRUCTION(TryBoundary); |
| 2800 | |
| 2801 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2802 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2803 | static constexpr size_t kFieldBoundaryKindSize = |
| 2804 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2805 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2806 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2807 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2808 | "Too many packed fields."); |
| 2809 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2810 | |
| 2811 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2812 | }; |
| 2813 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2814 | // Deoptimize to interpreter, upon checking a condition. |
| 2815 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2816 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2817 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2818 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2819 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2820 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2821 | SetRawInputAt(0, cond); |
| 2822 | } |
| 2823 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2824 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2825 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2826 | return true; |
| 2827 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2828 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2829 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2830 | |
| 2831 | DECLARE_INSTRUCTION(Deoptimize); |
| 2832 | |
| 2833 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2834 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2835 | }; |
| 2836 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2837 | // Represents the ArtMethod that was passed as a first argument to |
| 2838 | // the method. It is used by instructions that depend on it, like |
| 2839 | // instructions that work with the dex cache. |
| 2840 | class HCurrentMethod : public HExpression<0> { |
| 2841 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2842 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2843 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2844 | |
| 2845 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2846 | |
| 2847 | private: |
| 2848 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2849 | }; |
| 2850 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2851 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2852 | // of a class. |
| 2853 | class HClassTableGet : public HExpression<1> { |
| 2854 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2855 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2856 | kVTable, |
| 2857 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2858 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2859 | }; |
| 2860 | HClassTableGet(HInstruction* cls, |
| 2861 | Primitive::Type type, |
| 2862 | TableKind kind, |
| 2863 | size_t index, |
| 2864 | uint32_t dex_pc) |
| 2865 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2866 | index_(index) { |
| 2867 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2868 | SetRawInputAt(0, cls); |
| 2869 | } |
| 2870 | |
| 2871 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2872 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2873 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2874 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2877 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2878 | size_t GetIndex() const { return index_; } |
| 2879 | |
| 2880 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2881 | |
| 2882 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2883 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2884 | static constexpr size_t kFieldTableKindSize = |
| 2885 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2886 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2887 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2888 | "Too many packed fields."); |
| 2889 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2890 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2891 | // The index of the ArtMethod in the table. |
| 2892 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2893 | |
| 2894 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2895 | }; |
| 2896 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2897 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2898 | // have one successor for each entry in the switch table, and the final successor |
| 2899 | // will be the block containing the next Dex opcode. |
| 2900 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2901 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2902 | HPackedSwitch(int32_t start_value, |
| 2903 | uint32_t num_entries, |
| 2904 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2905 | uint32_t dex_pc = kNoDexPc) |
| 2906 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2907 | start_value_(start_value), |
| 2908 | num_entries_(num_entries) { |
| 2909 | SetRawInputAt(0, input); |
| 2910 | } |
| 2911 | |
| 2912 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2913 | |
| 2914 | int32_t GetStartValue() const { return start_value_; } |
| 2915 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2916 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2917 | |
| 2918 | HBasicBlock* GetDefaultBlock() const { |
| 2919 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2920 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2921 | } |
| 2922 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2923 | |
| 2924 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2925 | const int32_t start_value_; |
| 2926 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2927 | |
| 2928 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2929 | }; |
| 2930 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2931 | class HUnaryOperation : public HExpression<1> { |
| 2932 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2933 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2934 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2935 | SetRawInputAt(0, input); |
| 2936 | } |
| 2937 | |
| 2938 | HInstruction* GetInput() const { return InputAt(0); } |
| 2939 | Primitive::Type GetResultType() const { return GetType(); } |
| 2940 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2941 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2942 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2943 | return true; |
| 2944 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2945 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2946 | // Try to statically evaluate `this` and return a HConstant |
| 2947 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2948 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2949 | HConstant* TryStaticEvaluation() const; |
| 2950 | |
| 2951 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2952 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2953 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2954 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 2955 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2956 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2957 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2958 | |
| 2959 | private: |
| 2960 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2961 | }; |
| 2962 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2963 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2964 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2965 | HBinaryOperation(Primitive::Type result_type, |
| 2966 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2967 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2968 | SideEffects side_effects = SideEffects::None(), |
| 2969 | uint32_t dex_pc = kNoDexPc) |
| 2970 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2971 | SetRawInputAt(0, left); |
| 2972 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2973 | } |
| 2974 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2975 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2976 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2977 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2978 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2979 | virtual bool IsCommutative() const { return false; } |
| 2980 | |
| 2981 | // Put constant on the right. |
| 2982 | // Returns whether order is changed. |
| 2983 | bool OrderInputsWithConstantOnTheRight() { |
| 2984 | HInstruction* left = InputAt(0); |
| 2985 | HInstruction* right = InputAt(1); |
| 2986 | if (left->IsConstant() && !right->IsConstant()) { |
| 2987 | ReplaceInput(right, 0); |
| 2988 | ReplaceInput(left, 1); |
| 2989 | return true; |
| 2990 | } |
| 2991 | return false; |
| 2992 | } |
| 2993 | |
| 2994 | // Order inputs by instruction id, but favor constant on the right side. |
| 2995 | // This helps GVN for commutative ops. |
| 2996 | void OrderInputs() { |
| 2997 | DCHECK(IsCommutative()); |
| 2998 | HInstruction* left = InputAt(0); |
| 2999 | HInstruction* right = InputAt(1); |
| 3000 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3001 | return; |
| 3002 | } |
| 3003 | if (OrderInputsWithConstantOnTheRight()) { |
| 3004 | return; |
| 3005 | } |
| 3006 | // Order according to instruction id. |
| 3007 | if (left->GetId() > right->GetId()) { |
| 3008 | ReplaceInput(right, 0); |
| 3009 | ReplaceInput(left, 1); |
| 3010 | } |
| 3011 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3012 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3013 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3014 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3015 | return true; |
| 3016 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3017 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3018 | // Try to statically evaluate `this` and return a HConstant |
| 3019 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3020 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3021 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3022 | |
| 3023 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3024 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3025 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3026 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3027 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3028 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3029 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3030 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3031 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3032 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3033 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3034 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3035 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3036 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3037 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3038 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3039 | // 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] | 3040 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3041 | HConstant* GetConstantRight() const; |
| 3042 | |
| 3043 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3044 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3045 | HInstruction* GetLeastConstantLeft() const; |
| 3046 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3047 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3048 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3049 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3050 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3051 | }; |
| 3052 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3053 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3054 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3055 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3056 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3057 | kGtBias, // return 1 for NaN comparisons |
| 3058 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3059 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3060 | }; |
| 3061 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3062 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3063 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3064 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3065 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3066 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3067 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3068 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3069 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3070 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3071 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3072 | // `instruction`, and disregard moves in between. |
| 3073 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3074 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3075 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3076 | |
| 3077 | virtual IfCondition GetCondition() const = 0; |
| 3078 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3079 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3080 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3081 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3082 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3083 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3084 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3085 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3086 | |
| 3087 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3088 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3089 | } |
| 3090 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3091 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3092 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3093 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3094 | if (if_cond == kCondNE) { |
| 3095 | return true; |
| 3096 | } else if (if_cond == kCondEQ) { |
| 3097 | return false; |
| 3098 | } |
| 3099 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3100 | } |
| 3101 | |
| 3102 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3103 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3104 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3105 | if (if_cond == kCondEQ) { |
| 3106 | return true; |
| 3107 | } else if (if_cond == kCondNE) { |
| 3108 | return false; |
| 3109 | } |
| 3110 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3111 | } |
| 3112 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3113 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3114 | // Needed if we merge a HCompare into a HCondition. |
| 3115 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3116 | static constexpr size_t kFieldComparisonBiasSize = |
| 3117 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3118 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3119 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3120 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3121 | using ComparisonBiasField = |
| 3122 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3123 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3124 | template <typename T> |
| 3125 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3126 | |
| 3127 | template <typename T> |
| 3128 | int32_t CompareFP(T x, T y) const { |
| 3129 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3130 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3131 | // Handle the bias. |
| 3132 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3133 | } |
| 3134 | |
| 3135 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3136 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3137 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3138 | } |
| 3139 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3140 | private: |
| 3141 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3142 | }; |
| 3143 | |
| 3144 | // Instruction to check if two inputs are equal to each other. |
| 3145 | class HEqual : public HCondition { |
| 3146 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3147 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3148 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3149 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3150 | bool IsCommutative() const OVERRIDE { return true; } |
| 3151 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3152 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3153 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3154 | return MakeConstantCondition(true, GetDexPc()); |
| 3155 | } |
| 3156 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3157 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3158 | } |
| 3159 | // In the following Evaluate methods, a HCompare instruction has |
| 3160 | // been merged into this HEqual instruction; evaluate it as |
| 3161 | // `Compare(x, y) == 0`. |
| 3162 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3163 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3164 | GetDexPc()); |
| 3165 | } |
| 3166 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3167 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3168 | } |
| 3169 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3170 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3171 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3172 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3173 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3174 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3175 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3176 | return kCondEQ; |
| 3177 | } |
| 3178 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3179 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3180 | return kCondNE; |
| 3181 | } |
| 3182 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3183 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3184 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 3185 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3186 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3187 | }; |
| 3188 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3189 | class HNotEqual : public HCondition { |
| 3190 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3191 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3192 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3193 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3194 | bool IsCommutative() const OVERRIDE { return true; } |
| 3195 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3196 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3197 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3198 | return MakeConstantCondition(false, GetDexPc()); |
| 3199 | } |
| 3200 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3201 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3202 | } |
| 3203 | // In the following Evaluate methods, a HCompare instruction has |
| 3204 | // been merged into this HNotEqual instruction; evaluate it as |
| 3205 | // `Compare(x, y) != 0`. |
| 3206 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3207 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3208 | } |
| 3209 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3210 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3211 | } |
| 3212 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3213 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3214 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3215 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3216 | DECLARE_INSTRUCTION(NotEqual); |
| 3217 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3218 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3219 | return kCondNE; |
| 3220 | } |
| 3221 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3222 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3223 | return kCondEQ; |
| 3224 | } |
| 3225 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3226 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3227 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 3228 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3229 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3230 | }; |
| 3231 | |
| 3232 | class HLessThan : public HCondition { |
| 3233 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3234 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3235 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3236 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3237 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3238 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3239 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3240 | // In the following Evaluate methods, a HCompare instruction has |
| 3241 | // been merged into this HLessThan instruction; evaluate it as |
| 3242 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3243 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3244 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3245 | } |
| 3246 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3247 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3248 | } |
| 3249 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3250 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3251 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3252 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3253 | DECLARE_INSTRUCTION(LessThan); |
| 3254 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3255 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3256 | return kCondLT; |
| 3257 | } |
| 3258 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3259 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3260 | return kCondGE; |
| 3261 | } |
| 3262 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3263 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3264 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 3265 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3266 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3267 | }; |
| 3268 | |
| 3269 | class HLessThanOrEqual : public HCondition { |
| 3270 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3271 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3272 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3273 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3274 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3275 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3276 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3277 | // In the following Evaluate methods, a HCompare instruction has |
| 3278 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3279 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3280 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3281 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3282 | } |
| 3283 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3284 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3285 | } |
| 3286 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3287 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3288 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3289 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3290 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3291 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3292 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3293 | return kCondLE; |
| 3294 | } |
| 3295 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3296 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3297 | return kCondGT; |
| 3298 | } |
| 3299 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3300 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3301 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 3302 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3303 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3304 | }; |
| 3305 | |
| 3306 | class HGreaterThan : public HCondition { |
| 3307 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3308 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3309 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3310 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3311 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3312 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3313 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3314 | // In the following Evaluate methods, a HCompare instruction has |
| 3315 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3316 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3317 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3318 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3319 | } |
| 3320 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3321 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3322 | } |
| 3323 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3324 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3325 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3326 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3327 | DECLARE_INSTRUCTION(GreaterThan); |
| 3328 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3329 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3330 | return kCondGT; |
| 3331 | } |
| 3332 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3333 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3334 | return kCondLE; |
| 3335 | } |
| 3336 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3337 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3338 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3339 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3340 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3341 | }; |
| 3342 | |
| 3343 | class HGreaterThanOrEqual : public HCondition { |
| 3344 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3345 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3346 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3347 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3348 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3349 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3350 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3351 | // In the following Evaluate methods, a HCompare instruction has |
| 3352 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3353 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3354 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3355 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3356 | } |
| 3357 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3358 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3359 | } |
| 3360 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3361 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3362 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3363 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3364 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3365 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3366 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3367 | return kCondGE; |
| 3368 | } |
| 3369 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3370 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3371 | return kCondLT; |
| 3372 | } |
| 3373 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3374 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3375 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3376 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3377 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3378 | }; |
| 3379 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3380 | class HBelow : public HCondition { |
| 3381 | public: |
| 3382 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3383 | : HCondition(first, second, dex_pc) {} |
| 3384 | |
| 3385 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3386 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3387 | } |
| 3388 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3389 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3390 | } |
| 3391 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3392 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3393 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3394 | UNREACHABLE(); |
| 3395 | } |
| 3396 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3397 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3398 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3399 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | DECLARE_INSTRUCTION(Below); |
| 3403 | |
| 3404 | IfCondition GetCondition() const OVERRIDE { |
| 3405 | return kCondB; |
| 3406 | } |
| 3407 | |
| 3408 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3409 | return kCondAE; |
| 3410 | } |
| 3411 | |
| 3412 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3413 | template <typename T> bool Compute(T x, T y) const { |
| 3414 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3415 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3416 | |
| 3417 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3418 | }; |
| 3419 | |
| 3420 | class HBelowOrEqual : public HCondition { |
| 3421 | public: |
| 3422 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3423 | : HCondition(first, second, dex_pc) {} |
| 3424 | |
| 3425 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3426 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3427 | } |
| 3428 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3429 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3430 | } |
| 3431 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3432 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3433 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3434 | UNREACHABLE(); |
| 3435 | } |
| 3436 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3437 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3438 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3439 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3443 | |
| 3444 | IfCondition GetCondition() const OVERRIDE { |
| 3445 | return kCondBE; |
| 3446 | } |
| 3447 | |
| 3448 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3449 | return kCondA; |
| 3450 | } |
| 3451 | |
| 3452 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3453 | template <typename T> bool Compute(T x, T y) const { |
| 3454 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3455 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3456 | |
| 3457 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3458 | }; |
| 3459 | |
| 3460 | class HAbove : public HCondition { |
| 3461 | public: |
| 3462 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3463 | : HCondition(first, second, dex_pc) {} |
| 3464 | |
| 3465 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3466 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3467 | } |
| 3468 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3469 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3470 | } |
| 3471 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3472 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3473 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3474 | UNREACHABLE(); |
| 3475 | } |
| 3476 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3477 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3478 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3479 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3480 | } |
| 3481 | |
| 3482 | DECLARE_INSTRUCTION(Above); |
| 3483 | |
| 3484 | IfCondition GetCondition() const OVERRIDE { |
| 3485 | return kCondA; |
| 3486 | } |
| 3487 | |
| 3488 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3489 | return kCondBE; |
| 3490 | } |
| 3491 | |
| 3492 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3493 | template <typename T> bool Compute(T x, T y) const { |
| 3494 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3495 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3496 | |
| 3497 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3498 | }; |
| 3499 | |
| 3500 | class HAboveOrEqual : public HCondition { |
| 3501 | public: |
| 3502 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3503 | : HCondition(first, second, dex_pc) {} |
| 3504 | |
| 3505 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3506 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3507 | } |
| 3508 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3509 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3510 | } |
| 3511 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3512 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3513 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3514 | UNREACHABLE(); |
| 3515 | } |
| 3516 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3517 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3518 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3519 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3523 | |
| 3524 | IfCondition GetCondition() const OVERRIDE { |
| 3525 | return kCondAE; |
| 3526 | } |
| 3527 | |
| 3528 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3529 | return kCondB; |
| 3530 | } |
| 3531 | |
| 3532 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3533 | template <typename T> bool Compute(T x, T y) const { |
| 3534 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3535 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3536 | |
| 3537 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3538 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3539 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3540 | // Instruction to check how two inputs compare to each other. |
| 3541 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3542 | class HCompare : public HBinaryOperation { |
| 3543 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3544 | // Note that `comparison_type` is the type of comparison performed |
| 3545 | // between the comparison's inputs, not the type of the instantiated |
| 3546 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3547 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3548 | HInstruction* first, |
| 3549 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3550 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3551 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3552 | : HBinaryOperation(Primitive::kPrimInt, |
| 3553 | first, |
| 3554 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3555 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3556 | dex_pc) { |
| 3557 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3558 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3559 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3560 | } |
| 3561 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3562 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3563 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3564 | |
| 3565 | template <typename T> |
| 3566 | int32_t ComputeFP(T x, T y) const { |
| 3567 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3568 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3569 | // Handle the bias. |
| 3570 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3571 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3572 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3573 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3574 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3575 | // reach this code path when processing a freshly built HIR |
| 3576 | // graph. However HCompare integer instructions can be synthesized |
| 3577 | // by the instruction simplifier to implement IntegerCompare and |
| 3578 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3579 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3580 | } |
| 3581 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3582 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3583 | } |
| 3584 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3585 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3586 | } |
| 3587 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3588 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3589 | } |
| 3590 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3591 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3592 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3593 | } |
| 3594 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3595 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3596 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3597 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3598 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3599 | bool IsGtBias() const { |
| 3600 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3601 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3602 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3603 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3604 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3605 | // Comparisons do not require a runtime call in any back end. |
| 3606 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3607 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3608 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3609 | DECLARE_INSTRUCTION(Compare); |
| 3610 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3611 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3612 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3613 | static constexpr size_t kFieldComparisonBiasSize = |
| 3614 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3615 | static constexpr size_t kNumberOfComparePackedBits = |
| 3616 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3617 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3618 | using ComparisonBiasField = |
| 3619 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3620 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3621 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3622 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3623 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3624 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3625 | } |
| 3626 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3627 | private: |
| 3628 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3629 | }; |
| 3630 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3631 | class HNewInstance : public HExpression<2> { |
| 3632 | public: |
| 3633 | HNewInstance(HInstruction* cls, |
| 3634 | HCurrentMethod* current_method, |
| 3635 | uint32_t dex_pc, |
| 3636 | uint16_t type_index, |
| 3637 | const DexFile& dex_file, |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3638 | bool needs_access_check, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3639 | bool finalizable, |
| 3640 | QuickEntrypointEnum entrypoint) |
| 3641 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3642 | type_index_(type_index), |
| 3643 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3644 | entrypoint_(entrypoint) { |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3645 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3646 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3647 | SetRawInputAt(0, cls); |
| 3648 | SetRawInputAt(1, current_method); |
| 3649 | } |
| 3650 | |
| 3651 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3652 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3653 | |
| 3654 | // Calls runtime so needs an environment. |
| 3655 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3656 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3657 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3658 | bool CanThrow() const OVERRIDE { return true; } |
| 3659 | |
| 3660 | // Needs to call into runtime to make sure it's instantiable/accessible. |
| 3661 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3662 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3663 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3664 | |
| 3665 | bool CanBeNull() const OVERRIDE { return false; } |
| 3666 | |
| 3667 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3668 | |
| 3669 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3670 | entrypoint_ = entrypoint; |
| 3671 | } |
| 3672 | |
| 3673 | bool IsStringAlloc() const; |
| 3674 | |
| 3675 | DECLARE_INSTRUCTION(NewInstance); |
| 3676 | |
| 3677 | private: |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3678 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfExpressionPackedBits; |
| 3679 | static constexpr size_t kFlagFinalizable = kFlagNeedsAccessCheck + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3680 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3681 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3682 | "Too many packed fields."); |
| 3683 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3684 | const uint16_t type_index_; |
| 3685 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3686 | QuickEntrypointEnum entrypoint_; |
| 3687 | |
| 3688 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3689 | }; |
| 3690 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3691 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3692 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3693 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3694 | #include "intrinsics_list.h" |
| 3695 | kNone, |
| 3696 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3697 | #undef INTRINSICS_LIST |
| 3698 | #undef OPTIMIZING_INTRINSICS |
| 3699 | }; |
| 3700 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3701 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3702 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3703 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3704 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3705 | }; |
| 3706 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3707 | enum IntrinsicSideEffects { |
| 3708 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3709 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3710 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3711 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3712 | }; |
| 3713 | |
| 3714 | enum IntrinsicExceptions { |
| 3715 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3716 | kCanThrow // Intrinsic may throw exceptions. |
| 3717 | }; |
| 3718 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3719 | class HInvoke : public HInstruction { |
| 3720 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3721 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3722 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3723 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3724 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3725 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3726 | SetRawInputAt(index, argument); |
| 3727 | } |
| 3728 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3729 | // Return the number of arguments. This number can be lower than |
| 3730 | // the number of inputs returned by InputCount(), as some invoke |
| 3731 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3732 | // inputs at the end of their list of inputs. |
| 3733 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3734 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3735 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3736 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3737 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3738 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3739 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3740 | InvokeType GetOriginalInvokeType() const { |
| 3741 | return GetPackedField<OriginalInvokeTypeField>(); |
| 3742 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3743 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3744 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3745 | return intrinsic_; |
| 3746 | } |
| 3747 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3748 | void SetIntrinsic(Intrinsics intrinsic, |
| 3749 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3750 | IntrinsicSideEffects side_effects, |
| 3751 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3752 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3753 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3754 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3755 | } |
| 3756 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3757 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3758 | |
| 3759 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3760 | |
| 3761 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3762 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3763 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3764 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3765 | uint32_t* GetIntrinsicOptimizations() { |
| 3766 | return &intrinsic_optimizations_; |
| 3767 | } |
| 3768 | |
| 3769 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3770 | return &intrinsic_optimizations_; |
| 3771 | } |
| 3772 | |
| 3773 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3774 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3775 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3776 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3777 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3778 | static constexpr size_t kFieldOriginalInvokeType = kNumberOfGenericPackedBits; |
| 3779 | static constexpr size_t kFieldOriginalInvokeTypeSize = |
| 3780 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3781 | static constexpr size_t kFieldReturnType = |
| 3782 | kFieldOriginalInvokeType + kFieldOriginalInvokeTypeSize; |
| 3783 | static constexpr size_t kFieldReturnTypeSize = |
| 3784 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3785 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3786 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3787 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3788 | using OriginalInvokeTypeField = |
| 3789 | BitField<InvokeType, kFieldOriginalInvokeType, kFieldOriginalInvokeTypeSize>; |
| 3790 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3791 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3792 | HInvoke(ArenaAllocator* arena, |
| 3793 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3794 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3795 | Primitive::Type return_type, |
| 3796 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3797 | uint32_t dex_method_index, |
| 3798 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3799 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3800 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3801 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3802 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3803 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3804 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3805 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3806 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3807 | SetPackedField<ReturnTypeField>(return_type); |
| 3808 | SetPackedField<OriginalInvokeTypeField>(original_invoke_type); |
| 3809 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3810 | } |
| 3811 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3812 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3813 | return inputs_[index]; |
| 3814 | } |
| 3815 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3816 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3817 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3818 | } |
| 3819 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3820 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3821 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3822 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3823 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3824 | const uint32_t dex_method_index_; |
| 3825 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3826 | |
| 3827 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3828 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3829 | |
| 3830 | private: |
| 3831 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3832 | }; |
| 3833 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3834 | class HInvokeUnresolved : public HInvoke { |
| 3835 | public: |
| 3836 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3837 | uint32_t number_of_arguments, |
| 3838 | Primitive::Type return_type, |
| 3839 | uint32_t dex_pc, |
| 3840 | uint32_t dex_method_index, |
| 3841 | InvokeType invoke_type) |
| 3842 | : HInvoke(arena, |
| 3843 | number_of_arguments, |
| 3844 | 0u /* number_of_other_inputs */, |
| 3845 | return_type, |
| 3846 | dex_pc, |
| 3847 | dex_method_index, |
| 3848 | invoke_type) { |
| 3849 | } |
| 3850 | |
| 3851 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3852 | |
| 3853 | private: |
| 3854 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3855 | }; |
| 3856 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3857 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3858 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3859 | // Requirements of this method call regarding the class |
| 3860 | // initialization (clinit) check of its declaring class. |
| 3861 | enum class ClinitCheckRequirement { |
| 3862 | kNone, // Class already initialized. |
| 3863 | kExplicit, // Static call having explicit clinit check as last input. |
| 3864 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3865 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3866 | }; |
| 3867 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3868 | // Determines how to load the target ArtMethod*. |
| 3869 | enum class MethodLoadKind { |
| 3870 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3871 | kStringInit, |
| 3872 | |
| 3873 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3874 | kRecursive, |
| 3875 | |
| 3876 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3877 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3878 | kDirectAddress, |
| 3879 | |
| 3880 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3881 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3882 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3883 | // the image relocatable or not. |
| 3884 | kDirectAddressWithFixup, |
| 3885 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3886 | // 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] | 3887 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3888 | // may cause class initialization (the entry may point to a resolution method), |
| 3889 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3890 | kDexCachePcRelative, |
| 3891 | |
| 3892 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3893 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3894 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3895 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3896 | kDexCacheViaMethod, |
| 3897 | }; |
| 3898 | |
| 3899 | // Determines the location of the code pointer. |
| 3900 | enum class CodePtrLocation { |
| 3901 | // Recursive call, use local PC-relative call instruction. |
| 3902 | kCallSelf, |
| 3903 | |
| 3904 | // Use PC-relative call instruction patched at link time. |
| 3905 | // Used for calls within an oat file, boot->boot or app->app. |
| 3906 | kCallPCRelative, |
| 3907 | |
| 3908 | // Call to a known target address, embed the direct address in code. |
| 3909 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3910 | kCallDirect, |
| 3911 | |
| 3912 | // Call to a target address that will be known at link time, embed the direct |
| 3913 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3914 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3915 | // the image relocatable or not. |
| 3916 | kCallDirectWithFixup, |
| 3917 | |
| 3918 | // Use code pointer from the ArtMethod*. |
| 3919 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3920 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3921 | kCallArtMethod, |
| 3922 | }; |
| 3923 | |
| 3924 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3925 | MethodLoadKind method_load_kind; |
| 3926 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3927 | // The method load data holds |
| 3928 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3929 | // Note that there are multiple string init methods, each having its own offset. |
| 3930 | // - the method address for kDirectAddress |
| 3931 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3932 | uint64_t method_load_data; |
| 3933 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3934 | }; |
| 3935 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3936 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3937 | uint32_t number_of_arguments, |
| 3938 | Primitive::Type return_type, |
| 3939 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3940 | uint32_t method_index, |
| 3941 | MethodReference target_method, |
| 3942 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3943 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3944 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3945 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3946 | : HInvoke(arena, |
| 3947 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3948 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3949 | // potentially one other if the clinit check is explicit, and potentially |
| 3950 | // one other if the method is a string factory. |
| 3951 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3952 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3953 | return_type, |
| 3954 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3955 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3956 | original_invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3957 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3958 | dispatch_info_(dispatch_info) { |
| 3959 | SetPackedField<OptimizedInvokeTypeField>(optimized_invoke_type); |
| 3960 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 3961 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3962 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3963 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3964 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3965 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3966 | |
| 3967 | // Using the current method is the default and once we find a better |
| 3968 | // method load kind, we should not go back to using the current method. |
| 3969 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3970 | |
| 3971 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3972 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3973 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3974 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3975 | dispatch_info_ = dispatch_info; |
| 3976 | } |
| 3977 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3978 | void AddSpecialInput(HInstruction* input) { |
| 3979 | // We allow only one special input. |
| 3980 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3981 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3982 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3983 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3984 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3985 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3986 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3987 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3988 | // TODO: for intrinsics we can generate implicit null checks. |
| 3989 | return false; |
| 3990 | } |
| 3991 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3992 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3993 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3994 | } |
| 3995 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3996 | // Get the index of the special input, if any. |
| 3997 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3998 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 3999 | // method pointer; otherwise there may be one platform-specific special input, |
| 4000 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4001 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4002 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4003 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4004 | InvokeType GetOptimizedInvokeType() const { |
| 4005 | return GetPackedField<OptimizedInvokeTypeField>(); |
| 4006 | } |
| 4007 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4008 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4009 | SetPackedField<OptimizedInvokeTypeField>(invoke_type); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4010 | } |
| 4011 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4012 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4013 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4014 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4015 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4016 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4017 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4018 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4019 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 4020 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4021 | bool HasCurrentMethodInput() const { |
| 4022 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4023 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4024 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4025 | return true; |
| 4026 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4027 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4028 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4029 | return false; |
| 4030 | } |
| 4031 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4032 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 4033 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4034 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4035 | |
| 4036 | int32_t GetStringInitOffset() const { |
| 4037 | DCHECK(IsStringInit()); |
| 4038 | return dispatch_info_.method_load_data; |
| 4039 | } |
| 4040 | |
| 4041 | uint64_t GetMethodAddress() const { |
| 4042 | DCHECK(HasMethodAddress()); |
| 4043 | return dispatch_info_.method_load_data; |
| 4044 | } |
| 4045 | |
| 4046 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4047 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4048 | return dispatch_info_.method_load_data; |
| 4049 | } |
| 4050 | |
| 4051 | uint64_t GetDirectCodePtr() const { |
| 4052 | DCHECK(HasDirectCodePtr()); |
| 4053 | return dispatch_info_.direct_code_ptr; |
| 4054 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4055 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4056 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4057 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4058 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4059 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4060 | // Is this instruction a call to a static method? |
| 4061 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4062 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4063 | } |
| 4064 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4065 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4066 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4067 | // instruction; only relevant for static calls with explicit clinit check. |
| 4068 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4069 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 4070 | size_t last_input_index = InputCount() - 1; |
| 4071 | HInstruction* last_input = InputAt(last_input_index); |
| 4072 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4073 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4074 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4075 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4076 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4077 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | // 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] | 4081 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4082 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4083 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | // Is this a call to a static method whose declaring class has an |
| 4087 | // implicit intialization check requirement? |
| 4088 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4089 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4090 | } |
| 4091 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4092 | // Does this method load kind need the current method as an input? |
| 4093 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4094 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4095 | } |
| 4096 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4097 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4098 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4099 | protected: |
| 4100 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 4101 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 4102 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 4103 | HInstruction* input = input_record.GetInstruction(); |
| 4104 | // `input` is the last input of a static invoke marked as having |
| 4105 | // an explicit clinit check. It must either be: |
| 4106 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4107 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4108 | DCHECK(input != nullptr); |
| 4109 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 4110 | } |
| 4111 | return input_record; |
| 4112 | } |
| 4113 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4114 | void InsertInputAt(size_t index, HInstruction* input); |
| 4115 | void RemoveInputAt(size_t index); |
| 4116 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4117 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4118 | static constexpr size_t kFieldOptimizedInvokeType = kNumberOfInvokePackedBits; |
| 4119 | static constexpr size_t kFieldOptimizedInvokeTypeSize = |
| 4120 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4121 | static constexpr size_t kFieldClinitCheckRequirement = |
| 4122 | kFieldOptimizedInvokeType + kFieldOptimizedInvokeTypeSize; |
| 4123 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4124 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4125 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4126 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4127 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4128 | "Too many packed fields."); |
| 4129 | using OptimizedInvokeTypeField = |
| 4130 | BitField<InvokeType, kFieldOptimizedInvokeType, kFieldOptimizedInvokeTypeSize>; |
| 4131 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4132 | kFieldClinitCheckRequirement, |
| 4133 | kFieldClinitCheckRequirementSize>; |
| 4134 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4135 | // The target method may refer to different dex file or method index than the original |
| 4136 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 4137 | // in derived class to increase visibility. |
| 4138 | MethodReference target_method_; |
| 4139 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4140 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4141 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4142 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4143 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4144 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4145 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4146 | class HInvokeVirtual : public HInvoke { |
| 4147 | public: |
| 4148 | HInvokeVirtual(ArenaAllocator* arena, |
| 4149 | uint32_t number_of_arguments, |
| 4150 | Primitive::Type return_type, |
| 4151 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4152 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4153 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4154 | : 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] | 4155 | vtable_index_(vtable_index) {} |
| 4156 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4157 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4158 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4159 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4160 | } |
| 4161 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4162 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4163 | |
| 4164 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4165 | |
| 4166 | private: |
| 4167 | const uint32_t vtable_index_; |
| 4168 | |
| 4169 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4170 | }; |
| 4171 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4172 | class HInvokeInterface : public HInvoke { |
| 4173 | public: |
| 4174 | HInvokeInterface(ArenaAllocator* arena, |
| 4175 | uint32_t number_of_arguments, |
| 4176 | Primitive::Type return_type, |
| 4177 | uint32_t dex_pc, |
| 4178 | uint32_t dex_method_index, |
| 4179 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4180 | : 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] | 4181 | imt_index_(imt_index) {} |
| 4182 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4183 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4184 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4185 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4186 | } |
| 4187 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4188 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4189 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4190 | |
| 4191 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4192 | |
| 4193 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4194 | const uint32_t imt_index_; |
| 4195 | |
| 4196 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4197 | }; |
| 4198 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4199 | class HNeg : public HUnaryOperation { |
| 4200 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4201 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4202 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4203 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4204 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4205 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4206 | template <typename T> T Compute(T x) const { return -x; } |
| 4207 | |
| 4208 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4209 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4210 | } |
| 4211 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4212 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4213 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4214 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4215 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4216 | } |
| 4217 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4218 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4219 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4220 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4221 | DECLARE_INSTRUCTION(Neg); |
| 4222 | |
| 4223 | private: |
| 4224 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4225 | }; |
| 4226 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4227 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4228 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4229 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4230 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4231 | uint32_t dex_pc, |
| 4232 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4233 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4234 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4235 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4236 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4237 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4238 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4239 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4240 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4241 | } |
| 4242 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4243 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4244 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4245 | |
| 4246 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4247 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4248 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4249 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4250 | bool CanThrow() const OVERRIDE { return true; } |
| 4251 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4252 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4253 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4254 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4255 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4256 | DECLARE_INSTRUCTION(NewArray); |
| 4257 | |
| 4258 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4259 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4260 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4261 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4262 | |
| 4263 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4264 | }; |
| 4265 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4266 | class HAdd : public HBinaryOperation { |
| 4267 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4268 | HAdd(Primitive::Type result_type, |
| 4269 | HInstruction* left, |
| 4270 | HInstruction* right, |
| 4271 | uint32_t dex_pc = kNoDexPc) |
| 4272 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4273 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4274 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4275 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4276 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 4277 | |
| 4278 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4279 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4280 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4281 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4282 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4283 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4284 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4285 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4286 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4287 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4288 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4289 | } |
| 4290 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4291 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4292 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4293 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4294 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4295 | DECLARE_INSTRUCTION(Add); |
| 4296 | |
| 4297 | private: |
| 4298 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4299 | }; |
| 4300 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4301 | class HSub : public HBinaryOperation { |
| 4302 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4303 | HSub(Primitive::Type result_type, |
| 4304 | HInstruction* left, |
| 4305 | HInstruction* right, |
| 4306 | uint32_t dex_pc = kNoDexPc) |
| 4307 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4308 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4309 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 4310 | |
| 4311 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4312 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4313 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4314 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4315 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4316 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4317 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4318 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4319 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4320 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4321 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4322 | } |
| 4323 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4324 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4325 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4326 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4327 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4328 | DECLARE_INSTRUCTION(Sub); |
| 4329 | |
| 4330 | private: |
| 4331 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4332 | }; |
| 4333 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4334 | class HMul : public HBinaryOperation { |
| 4335 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4336 | HMul(Primitive::Type result_type, |
| 4337 | HInstruction* left, |
| 4338 | HInstruction* right, |
| 4339 | uint32_t dex_pc = kNoDexPc) |
| 4340 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4341 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4342 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4343 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4344 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 4345 | |
| 4346 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4347 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4348 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4349 | } |
| 4350 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4351 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4352 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4353 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4354 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4355 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4356 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4357 | } |
| 4358 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4359 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4360 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4361 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4362 | |
| 4363 | DECLARE_INSTRUCTION(Mul); |
| 4364 | |
| 4365 | private: |
| 4366 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4367 | }; |
| 4368 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4369 | class HDiv : public HBinaryOperation { |
| 4370 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4371 | HDiv(Primitive::Type result_type, |
| 4372 | HInstruction* left, |
| 4373 | HInstruction* right, |
| 4374 | uint32_t dex_pc) |
| 4375 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4376 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4377 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4378 | T ComputeIntegral(T x, T y) const { |
| 4379 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4380 | // Our graph structure ensures we never have 0 for `y` during |
| 4381 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4382 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4383 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4384 | return (y == -1) ? -x : x / y; |
| 4385 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4386 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4387 | template <typename T> |
| 4388 | T ComputeFP(T x, T y) const { |
| 4389 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4390 | return x / y; |
| 4391 | } |
| 4392 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4393 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4394 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4395 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4396 | } |
| 4397 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4398 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4399 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4400 | } |
| 4401 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4402 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4403 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4404 | } |
| 4405 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4406 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4407 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4408 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4409 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4410 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4411 | // The generated code can use a runtime call. |
| 4412 | return SideEffects::CanTriggerGC(); |
| 4413 | } |
| 4414 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4415 | DECLARE_INSTRUCTION(Div); |
| 4416 | |
| 4417 | private: |
| 4418 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4419 | }; |
| 4420 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4421 | class HRem : public HBinaryOperation { |
| 4422 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4423 | HRem(Primitive::Type result_type, |
| 4424 | HInstruction* left, |
| 4425 | HInstruction* right, |
| 4426 | uint32_t dex_pc) |
| 4427 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4428 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4429 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4430 | T ComputeIntegral(T x, T y) const { |
| 4431 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4432 | // Our graph structure ensures we never have 0 for `y` during |
| 4433 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4434 | DCHECK_NE(y, 0); |
| 4435 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4436 | return (y == -1) ? 0 : x % y; |
| 4437 | } |
| 4438 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4439 | template <typename T> |
| 4440 | T ComputeFP(T x, T y) const { |
| 4441 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4442 | return std::fmod(x, y); |
| 4443 | } |
| 4444 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4445 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4446 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4447 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4448 | } |
| 4449 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4450 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4451 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4452 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4453 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4454 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4455 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4456 | } |
| 4457 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4458 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4459 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4460 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4461 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4462 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4463 | return SideEffects::CanTriggerGC(); |
| 4464 | } |
| 4465 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4466 | DECLARE_INSTRUCTION(Rem); |
| 4467 | |
| 4468 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4469 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4470 | }; |
| 4471 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4472 | class HDivZeroCheck : public HExpression<1> { |
| 4473 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4474 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4475 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4476 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4477 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4478 | SetRawInputAt(0, value); |
| 4479 | } |
| 4480 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4481 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4482 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4483 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4484 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4485 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4486 | return true; |
| 4487 | } |
| 4488 | |
| 4489 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4490 | bool CanThrow() const OVERRIDE { return true; } |
| 4491 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4492 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4493 | |
| 4494 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4495 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4496 | }; |
| 4497 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4498 | class HShl : public HBinaryOperation { |
| 4499 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4500 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4501 | HInstruction* value, |
| 4502 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4503 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4504 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4505 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4506 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4507 | } |
| 4508 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4509 | template <typename T> |
| 4510 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4511 | return value << (distance & max_shift_distance); |
| 4512 | } |
| 4513 | |
| 4514 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4515 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4516 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
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(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4519 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4520 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4521 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4522 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4523 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4524 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4525 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4526 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4527 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4528 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4529 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4530 | UNREACHABLE(); |
| 4531 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4532 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4533 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4534 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4535 | UNREACHABLE(); |
| 4536 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4537 | |
| 4538 | DECLARE_INSTRUCTION(Shl); |
| 4539 | |
| 4540 | private: |
| 4541 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4542 | }; |
| 4543 | |
| 4544 | class HShr : public HBinaryOperation { |
| 4545 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4546 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4547 | HInstruction* value, |
| 4548 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4549 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4550 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4551 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4552 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4553 | } |
| 4554 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4555 | template <typename T> |
| 4556 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4557 | return value >> (distance & max_shift_distance); |
| 4558 | } |
| 4559 | |
| 4560 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4561 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4562 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
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(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4565 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4566 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4567 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4568 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4569 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4570 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4571 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4572 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4573 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4574 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4575 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4576 | UNREACHABLE(); |
| 4577 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4578 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4579 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4580 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4581 | UNREACHABLE(); |
| 4582 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4583 | |
| 4584 | DECLARE_INSTRUCTION(Shr); |
| 4585 | |
| 4586 | private: |
| 4587 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4588 | }; |
| 4589 | |
| 4590 | class HUShr : public HBinaryOperation { |
| 4591 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4592 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4593 | HInstruction* value, |
| 4594 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4595 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4596 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4597 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4598 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4599 | } |
| 4600 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4601 | template <typename T> |
| 4602 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4603 | typedef typename std::make_unsigned<T>::type V; |
| 4604 | V ux = static_cast<V>(value); |
| 4605 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4606 | } |
| 4607 | |
| 4608 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4609 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4610 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4611 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4612 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4613 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4614 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4615 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4616 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4617 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4618 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4619 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4620 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4621 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4622 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4623 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4624 | UNREACHABLE(); |
| 4625 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4626 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4627 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4628 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4629 | UNREACHABLE(); |
| 4630 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4631 | |
| 4632 | DECLARE_INSTRUCTION(UShr); |
| 4633 | |
| 4634 | private: |
| 4635 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4636 | }; |
| 4637 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4638 | class HAnd : public HBinaryOperation { |
| 4639 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4640 | HAnd(Primitive::Type result_type, |
| 4641 | HInstruction* left, |
| 4642 | HInstruction* right, |
| 4643 | uint32_t dex_pc = kNoDexPc) |
| 4644 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4645 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4646 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4647 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4648 | template <typename T> T Compute(T x, T y) const { return x & y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4649 | |
| 4650 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4651 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4652 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4653 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4654 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4655 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4656 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4657 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4658 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4659 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4660 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4661 | UNREACHABLE(); |
| 4662 | } |
| 4663 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4664 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4665 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4666 | UNREACHABLE(); |
| 4667 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4668 | |
| 4669 | DECLARE_INSTRUCTION(And); |
| 4670 | |
| 4671 | private: |
| 4672 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4673 | }; |
| 4674 | |
| 4675 | class HOr : public HBinaryOperation { |
| 4676 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4677 | HOr(Primitive::Type result_type, |
| 4678 | HInstruction* left, |
| 4679 | HInstruction* right, |
| 4680 | uint32_t dex_pc = kNoDexPc) |
| 4681 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4682 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4683 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4684 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4685 | template <typename T> T Compute(T x, T y) const { return x | y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4686 | |
| 4687 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4688 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4689 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4690 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4691 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4692 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4693 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4694 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4695 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4696 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4697 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4698 | UNREACHABLE(); |
| 4699 | } |
| 4700 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4701 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4702 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4703 | UNREACHABLE(); |
| 4704 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4705 | |
| 4706 | DECLARE_INSTRUCTION(Or); |
| 4707 | |
| 4708 | private: |
| 4709 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4710 | }; |
| 4711 | |
| 4712 | class HXor : public HBinaryOperation { |
| 4713 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4714 | HXor(Primitive::Type result_type, |
| 4715 | HInstruction* left, |
| 4716 | HInstruction* right, |
| 4717 | uint32_t dex_pc = kNoDexPc) |
| 4718 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4719 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4720 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4721 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4722 | template <typename T> T Compute(T x, T y) const { return x ^ y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4723 | |
| 4724 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4725 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4726 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4727 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4728 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4729 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4730 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4731 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4732 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4733 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4734 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4735 | UNREACHABLE(); |
| 4736 | } |
| 4737 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4738 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4739 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4740 | UNREACHABLE(); |
| 4741 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4742 | |
| 4743 | DECLARE_INSTRUCTION(Xor); |
| 4744 | |
| 4745 | private: |
| 4746 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4747 | }; |
| 4748 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4749 | class HRor : public HBinaryOperation { |
| 4750 | public: |
| 4751 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4752 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4753 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4754 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4755 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4756 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4757 | template <typename T> |
| 4758 | T Compute(T value, int32_t distance, int32_t max_shift_value) const { |
| 4759 | typedef typename std::make_unsigned<T>::type V; |
| 4760 | V ux = static_cast<V>(value); |
| 4761 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4762 | return static_cast<T>(ux); |
| 4763 | } else { |
| 4764 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4765 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4766 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4767 | } |
| 4768 | } |
| 4769 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4770 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4771 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4772 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
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(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4775 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4776 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4777 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4778 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4779 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4780 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4781 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4782 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4783 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4784 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4785 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4786 | UNREACHABLE(); |
| 4787 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4788 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4789 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4790 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4791 | UNREACHABLE(); |
| 4792 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4793 | |
| 4794 | DECLARE_INSTRUCTION(Ror); |
| 4795 | |
| 4796 | private: |
| 4797 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4798 | }; |
| 4799 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4800 | // The value of a parameter in this method. Its location depends on |
| 4801 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4802 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4803 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4804 | HParameterValue(const DexFile& dex_file, |
| 4805 | uint16_t type_index, |
| 4806 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4807 | Primitive::Type parameter_type, |
| 4808 | bool is_this = false) |
| 4809 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4810 | dex_file_(dex_file), |
| 4811 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4812 | index_(index) { |
| 4813 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4814 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4815 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4816 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4817 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4818 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4819 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4820 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4821 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4822 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4823 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4824 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4825 | DECLARE_INSTRUCTION(ParameterValue); |
| 4826 | |
| 4827 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4828 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4829 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4830 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4831 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4832 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4833 | "Too many packed fields."); |
| 4834 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4835 | const DexFile& dex_file_; |
| 4836 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4837 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4838 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4839 | const uint8_t index_; |
| 4840 | |
| 4841 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4842 | }; |
| 4843 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4844 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4845 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4846 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4847 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4848 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4849 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4850 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4851 | return true; |
| 4852 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4853 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4854 | template <typename T> T Compute(T x) const { return ~x; } |
| 4855 | |
| 4856 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4857 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4858 | } |
| 4859 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4860 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4861 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4862 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4863 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4864 | UNREACHABLE(); |
| 4865 | } |
| 4866 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4867 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4868 | UNREACHABLE(); |
| 4869 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4870 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4871 | DECLARE_INSTRUCTION(Not); |
| 4872 | |
| 4873 | private: |
| 4874 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4875 | }; |
| 4876 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4877 | class HBooleanNot : public HUnaryOperation { |
| 4878 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4879 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4880 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4881 | |
| 4882 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4883 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4884 | return true; |
| 4885 | } |
| 4886 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4887 | template <typename T> bool Compute(T x) const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4888 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4889 | return !x; |
| 4890 | } |
| 4891 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4892 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4893 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4894 | } |
| 4895 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4896 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4897 | UNREACHABLE(); |
| 4898 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4899 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4900 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4901 | UNREACHABLE(); |
| 4902 | } |
| 4903 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4904 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4905 | UNREACHABLE(); |
| 4906 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4907 | |
| 4908 | DECLARE_INSTRUCTION(BooleanNot); |
| 4909 | |
| 4910 | private: |
| 4911 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4912 | }; |
| 4913 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4914 | class HTypeConversion : public HExpression<1> { |
| 4915 | public: |
| 4916 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4917 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4918 | : HExpression(result_type, |
| 4919 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4920 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4921 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 4922 | // Invariant: We should never generate a conversion to a Boolean value. |
| 4923 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | HInstruction* GetInput() const { return InputAt(0); } |
| 4927 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4928 | Primitive::Type GetResultType() const { return GetType(); } |
| 4929 | |
| 4930 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4931 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4932 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4933 | // Try to statically evaluate the conversion and return a HConstant |
| 4934 | // containing the result. If the input cannot be converted, return nullptr. |
| 4935 | HConstant* TryStaticEvaluation() const; |
| 4936 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4937 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4938 | Primitive::Type result_type) { |
| 4939 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4940 | // in the compilation process we do not know what architecture we will |
| 4941 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4942 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4943 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4944 | return SideEffects::CanTriggerGC(); |
| 4945 | } |
| 4946 | return SideEffects::None(); |
| 4947 | } |
| 4948 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4949 | DECLARE_INSTRUCTION(TypeConversion); |
| 4950 | |
| 4951 | private: |
| 4952 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4953 | }; |
| 4954 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4955 | static constexpr uint32_t kNoRegNumber = -1; |
| 4956 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4957 | class HNullCheck : public HExpression<1> { |
| 4958 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4959 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4960 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4961 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4962 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4963 | SetRawInputAt(0, value); |
| 4964 | } |
| 4965 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4966 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4967 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4968 | return true; |
| 4969 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4970 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4971 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4972 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4973 | bool CanThrow() const OVERRIDE { return true; } |
| 4974 | |
| 4975 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4976 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4977 | |
| 4978 | DECLARE_INSTRUCTION(NullCheck); |
| 4979 | |
| 4980 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4981 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4982 | }; |
| 4983 | |
| 4984 | class FieldInfo : public ValueObject { |
| 4985 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4986 | FieldInfo(MemberOffset field_offset, |
| 4987 | Primitive::Type field_type, |
| 4988 | bool is_volatile, |
| 4989 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4990 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4991 | const DexFile& dex_file, |
| 4992 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4993 | : field_offset_(field_offset), |
| 4994 | field_type_(field_type), |
| 4995 | is_volatile_(is_volatile), |
| 4996 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4997 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4998 | dex_file_(dex_file), |
| 4999 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5000 | |
| 5001 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5002 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5003 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5004 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5005 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5006 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5007 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5008 | |
| 5009 | private: |
| 5010 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5011 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5012 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5013 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5014 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5015 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5016 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5017 | }; |
| 5018 | |
| 5019 | class HInstanceFieldGet : public HExpression<1> { |
| 5020 | public: |
| 5021 | HInstanceFieldGet(HInstruction* value, |
| 5022 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5023 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5024 | bool is_volatile, |
| 5025 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5026 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5027 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5028 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5029 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5030 | : HExpression(field_type, |
| 5031 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5032 | dex_pc), |
| 5033 | field_info_(field_offset, |
| 5034 | field_type, |
| 5035 | is_volatile, |
| 5036 | field_idx, |
| 5037 | declaring_class_def_index, |
| 5038 | dex_file, |
| 5039 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5040 | SetRawInputAt(0, value); |
| 5041 | } |
| 5042 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5043 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5044 | |
| 5045 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5046 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 5047 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5048 | } |
| 5049 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5050 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5051 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5052 | } |
| 5053 | |
| 5054 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5055 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5056 | } |
| 5057 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5058 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5059 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5060 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5061 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5062 | |
| 5063 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5064 | |
| 5065 | private: |
| 5066 | const FieldInfo field_info_; |
| 5067 | |
| 5068 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5069 | }; |
| 5070 | |
| 5071 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 5072 | public: |
| 5073 | HInstanceFieldSet(HInstruction* object, |
| 5074 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5075 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5076 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5077 | bool is_volatile, |
| 5078 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5079 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5080 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5081 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5082 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5083 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5084 | dex_pc), |
| 5085 | field_info_(field_offset, |
| 5086 | field_type, |
| 5087 | is_volatile, |
| 5088 | field_idx, |
| 5089 | declaring_class_def_index, |
| 5090 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5091 | dex_cache) { |
| 5092 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5093 | SetRawInputAt(0, object); |
| 5094 | SetRawInputAt(1, value); |
| 5095 | } |
| 5096 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5097 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5098 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5099 | } |
| 5100 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5101 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5102 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5103 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5104 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5105 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5106 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5107 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5108 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5109 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5110 | |
| 5111 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5112 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5113 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5114 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5115 | "Too many packed fields."); |
| 5116 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5117 | const FieldInfo field_info_; |
| 5118 | |
| 5119 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5120 | }; |
| 5121 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5122 | class HArrayGet : public HExpression<2> { |
| 5123 | public: |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5124 | HArrayGet(HInstruction* array, HInstruction* index, Primitive::Type type, uint32_t dex_pc) |
| 5125 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5126 | SetRawInputAt(0, array); |
| 5127 | SetRawInputAt(1, index); |
| 5128 | } |
| 5129 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5130 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5131 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5132 | return true; |
| 5133 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5134 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5135 | // TODO: We can be smarter here. |
| 5136 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5137 | // which generates the implicit null check. There are cases when these can be removed |
| 5138 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5139 | // implicit check here (as long as the address falls in the first page). |
| 5140 | return false; |
| 5141 | } |
| 5142 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5143 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5144 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5145 | if (kIsDebugBuild && result) { |
| 5146 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5147 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5148 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5149 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5150 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5151 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5152 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5153 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5154 | } |
| 5155 | } |
| 5156 | return result; |
| 5157 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 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: |
| 5165 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5166 | }; |
| 5167 | |
| 5168 | class HArraySet : public HTemplateInstruction<3> { |
| 5169 | public: |
| 5170 | HArraySet(HInstruction* array, |
| 5171 | HInstruction* index, |
| 5172 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5173 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5174 | uint32_t dex_pc) |
| 5175 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5176 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5177 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5178 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5179 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5180 | SetRawInputAt(0, array); |
| 5181 | SetRawInputAt(1, index); |
| 5182 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5183 | // Make a best guess now, may be refined during SSA building. |
| 5184 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5185 | } |
| 5186 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5187 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5188 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5189 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5190 | } |
| 5191 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5192 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5193 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5194 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5195 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5196 | // TODO: Same as for ArrayGet. |
| 5197 | return false; |
| 5198 | } |
| 5199 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5200 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5201 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5202 | } |
| 5203 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5204 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5205 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5206 | } |
| 5207 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5208 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5209 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5210 | } |
| 5211 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5212 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5213 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5214 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5215 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5216 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5217 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5218 | HInstruction* GetArray() const { return InputAt(0); } |
| 5219 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5220 | HInstruction* GetValue() const { return InputAt(2); } |
| 5221 | |
| 5222 | Primitive::Type GetComponentType() const { |
| 5223 | // The Dex format does not type floating point index operations. Since the |
| 5224 | // `expected_component_type_` is set during building and can therefore not |
| 5225 | // be correct, we also check what is the value type. If it is a floating |
| 5226 | // point type, we must use that type. |
| 5227 | Primitive::Type value_type = GetValue()->GetType(); |
| 5228 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5229 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5230 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5231 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5232 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5233 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5234 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5235 | } |
| 5236 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5237 | void ComputeSideEffects() { |
| 5238 | Primitive::Type type = GetComponentType(); |
| 5239 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5240 | SideEffectsForArchRuntimeCalls(type))); |
| 5241 | } |
| 5242 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5243 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5244 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5245 | } |
| 5246 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5247 | DECLARE_INSTRUCTION(ArraySet); |
| 5248 | |
| 5249 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5250 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5251 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5252 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5253 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5254 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5255 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5256 | // Cached information for the reference_type_info_ so that codegen |
| 5257 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5258 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5259 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5260 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5261 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5262 | using ExpectedComponentTypeField = |
| 5263 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5264 | |
| 5265 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5266 | }; |
| 5267 | |
| 5268 | class HArrayLength : public HExpression<1> { |
| 5269 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 5270 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5271 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5272 | // Note that arrays do not change length, so the instruction does not |
| 5273 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5274 | SetRawInputAt(0, array); |
| 5275 | } |
| 5276 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5277 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5278 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5279 | return true; |
| 5280 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5281 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5282 | return obj == InputAt(0); |
| 5283 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5284 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5285 | DECLARE_INSTRUCTION(ArrayLength); |
| 5286 | |
| 5287 | private: |
| 5288 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5289 | }; |
| 5290 | |
| 5291 | class HBoundsCheck : public HExpression<2> { |
| 5292 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5293 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5294 | // constructor. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5295 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5296 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5297 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5298 | SetRawInputAt(0, index); |
| 5299 | SetRawInputAt(1, length); |
| 5300 | } |
| 5301 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5302 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5303 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5304 | return true; |
| 5305 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5306 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5307 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5308 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5309 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5310 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5311 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5312 | |
| 5313 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5314 | |
| 5315 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5316 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5317 | }; |
| 5318 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5319 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 5320 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5321 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5322 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5323 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5324 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5325 | return true; |
| 5326 | } |
| 5327 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5328 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5329 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5330 | |
| 5331 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5332 | |
| 5333 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5334 | // Only used for code generation, in order to share the same slow path between back edges |
| 5335 | // of a same loop. |
| 5336 | SlowPathCode* slow_path_; |
| 5337 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5338 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5339 | }; |
| 5340 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5341 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5342 | // It ensures that we can generate line number and local variables at this point. |
| 5343 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5344 | public: |
| 5345 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5346 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5347 | |
| 5348 | bool NeedsEnvironment() const OVERRIDE { |
| 5349 | return true; |
| 5350 | } |
| 5351 | |
| 5352 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5353 | |
| 5354 | private: |
| 5355 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5356 | }; |
| 5357 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5358 | /** |
| 5359 | * Instruction to load a Class object. |
| 5360 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5361 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5362 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5363 | HLoadClass(HCurrentMethod* current_method, |
| 5364 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5365 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5366 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5367 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5368 | bool needs_access_check, |
| 5369 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5370 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5371 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5372 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5373 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5374 | // Referrers class should not need access check. We never inline unverified |
| 5375 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5376 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5377 | |
| 5378 | SetPackedFlag<kFlagIsReferrersClass>(is_referrers_class); |
| 5379 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5380 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
| 5381 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5382 | SetRawInputAt(0, current_method); |
| 5383 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5384 | |
| 5385 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5386 | |
| 5387 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 5388 | // Note that we don't need to test for generate_clinit_check_. |
| 5389 | // Whether or not we need to generate the clinit check is processed in |
| 5390 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5391 | return other->AsLoadClass()->type_index_ == type_index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5392 | other->AsLoadClass()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5396 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5397 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5398 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5399 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5400 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5401 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5402 | } |
| 5403 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5404 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5405 | // The entrypoint the code generator is going to call does not do |
| 5406 | // clinit of the class. |
| 5407 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5408 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5409 | } |
| 5410 | |
| 5411 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5412 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5413 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5414 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5415 | } |
| 5416 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5417 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5418 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5419 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5420 | } |
| 5421 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5422 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5423 | return loaded_class_rti_; |
| 5424 | } |
| 5425 | |
| 5426 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5427 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5428 | DCHECK(rti.IsExact()); |
| 5429 | loaded_class_rti_ = rti; |
| 5430 | } |
| 5431 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5432 | const DexFile& GetDexFile() { return dex_file_; } |
| 5433 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5434 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5435 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5436 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5437 | return SideEffects::CanTriggerGC(); |
| 5438 | } |
| 5439 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5440 | bool IsReferrersClass() const { return GetPackedFlag<kFlagIsReferrersClass>(); } |
| 5441 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5442 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5443 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5444 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5445 | DECLARE_INSTRUCTION(LoadClass); |
| 5446 | |
| 5447 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5448 | static constexpr size_t kFlagIsReferrersClass = kNumberOfExpressionPackedBits; |
| 5449 | static constexpr size_t kFlagNeedsAccessCheck = kFlagIsReferrersClass + 1; |
| 5450 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5451 | // Whether this instruction must generate the initialization check. |
| 5452 | // Used for code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5453 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInDexCache + 1; |
| 5454 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagGenerateClInitCheck + 1; |
| 5455 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5456 | |
| 5457 | const uint16_t type_index_; |
| 5458 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5459 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5460 | ReferenceTypeInfo loaded_class_rti_; |
| 5461 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5462 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5463 | }; |
| 5464 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5465 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5466 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5467 | // Determines how to load the String. |
| 5468 | enum class LoadKind { |
| 5469 | // Use boot image String* address that will be known at link time. |
| 5470 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5471 | kBootImageLinkTimeAddress, |
| 5472 | |
| 5473 | // Use PC-relative boot image String* address that will be known at link time. |
| 5474 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5475 | kBootImageLinkTimePcRelative, |
| 5476 | |
| 5477 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5478 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5479 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5480 | // GetIncludePatchInformation(). |
| 5481 | kBootImageAddress, |
| 5482 | |
| 5483 | // Load from the resolved strings array at an absolute address. |
| 5484 | // Used for strings outside the boot image referenced by JIT-compiled code. |
| 5485 | kDexCacheAddress, |
| 5486 | |
| 5487 | // Load from resolved strings array in the dex cache using a PC-relative load. |
| 5488 | // Used for strings outside boot image when we know that we can access |
| 5489 | // the dex cache arrays using a PC-relative load. |
| 5490 | kDexCachePcRelative, |
| 5491 | |
| 5492 | // Load from resolved strings array accessed through the class loaded from |
| 5493 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5494 | // all other types are unavailable. |
| 5495 | kDexCacheViaMethod, |
| 5496 | |
| 5497 | kLast = kDexCacheViaMethod |
| 5498 | }; |
| 5499 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5500 | HLoadString(HCurrentMethod* current_method, |
| 5501 | uint32_t string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5502 | const DexFile& dex_file, |
| 5503 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5504 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5505 | string_index_(string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5506 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5507 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
| 5508 | load_data_.ref.dex_file = &dex_file; |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5509 | SetRawInputAt(0, current_method); |
| 5510 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5511 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5512 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5513 | DCHECK(HasAddress(load_kind)); |
| 5514 | load_data_.address = address; |
| 5515 | SetLoadKindInternal(load_kind); |
| 5516 | } |
| 5517 | |
| 5518 | void SetLoadKindWithStringReference(LoadKind load_kind, |
| 5519 | const DexFile& dex_file, |
| 5520 | uint32_t string_index) { |
| 5521 | DCHECK(HasStringReference(load_kind)); |
| 5522 | load_data_.ref.dex_file = &dex_file; |
| 5523 | string_index_ = string_index; |
| 5524 | SetLoadKindInternal(load_kind); |
| 5525 | } |
| 5526 | |
| 5527 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5528 | const DexFile& dex_file, |
| 5529 | uint32_t element_index) { |
| 5530 | DCHECK(HasDexCacheReference(load_kind)); |
| 5531 | load_data_.ref.dex_file = &dex_file; |
| 5532 | load_data_.ref.dex_cache_element_index = element_index; |
| 5533 | SetLoadKindInternal(load_kind); |
| 5534 | } |
| 5535 | |
| 5536 | LoadKind GetLoadKind() const { |
| 5537 | return GetPackedField<LoadKindField>(); |
| 5538 | } |
| 5539 | |
| 5540 | const DexFile& GetDexFile() const; |
| 5541 | |
| 5542 | uint32_t GetStringIndex() const { |
| 5543 | DCHECK(HasStringReference(GetLoadKind()) || /* For slow paths. */ !IsInDexCache()); |
| 5544 | return string_index_; |
| 5545 | } |
| 5546 | |
| 5547 | uint32_t GetDexCacheElementOffset() const; |
| 5548 | |
| 5549 | uint64_t GetAddress() const { |
| 5550 | DCHECK(HasAddress(GetLoadKind())); |
| 5551 | return load_data_.address; |
| 5552 | } |
| 5553 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5554 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5555 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5556 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5557 | |
| 5558 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5559 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5560 | // Will call the runtime if we need to load the string through |
| 5561 | // the dex cache and the string is not guaranteed to be there yet. |
| 5562 | bool NeedsEnvironment() const OVERRIDE { |
| 5563 | LoadKind load_kind = GetLoadKind(); |
| 5564 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5565 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5566 | load_kind == LoadKind::kBootImageAddress) { |
| 5567 | return false; |
| 5568 | } |
| 5569 | return !IsInDexCache(); |
| 5570 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5571 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5572 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5573 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5574 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5575 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5576 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5577 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5578 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5579 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5580 | return SideEffects::CanTriggerGC(); |
| 5581 | } |
| 5582 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5583 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5584 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5585 | void MarkInDexCache() { |
| 5586 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5587 | DCHECK(!NeedsEnvironment()); |
| 5588 | RemoveEnvironment(); |
| 5589 | } |
| 5590 | |
| 5591 | size_t InputCount() const OVERRIDE { |
| 5592 | return (InputAt(0) != nullptr) ? 1u : 0u; |
| 5593 | } |
| 5594 | |
| 5595 | void AddSpecialInput(HInstruction* special_input); |
| 5596 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5597 | DECLARE_INSTRUCTION(LoadString); |
| 5598 | |
| 5599 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5600 | static constexpr size_t kFlagIsInDexCache = kNumberOfExpressionPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5601 | static constexpr size_t kFieldLoadKind = kFlagIsInDexCache + 1; |
| 5602 | static constexpr size_t kFieldLoadKindSize = |
| 5603 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5604 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5605 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5606 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5607 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5608 | static bool HasStringReference(LoadKind load_kind) { |
| 5609 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5610 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5611 | load_kind == LoadKind::kDexCacheViaMethod; |
| 5612 | } |
| 5613 | |
| 5614 | static bool HasAddress(LoadKind load_kind) { |
| 5615 | return load_kind == LoadKind::kBootImageAddress || load_kind == LoadKind::kDexCacheAddress; |
| 5616 | } |
| 5617 | |
| 5618 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5619 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5620 | } |
| 5621 | |
| 5622 | void SetLoadKindInternal(LoadKind load_kind); |
| 5623 | |
| 5624 | // String index serves also as the hash code and it's also needed for slow-paths, |
| 5625 | // so it must not be overwritten with other load data. |
| 5626 | uint32_t string_index_; |
| 5627 | |
| 5628 | union { |
| 5629 | struct { |
| 5630 | const DexFile* dex_file; // For string reference and dex cache reference. |
| 5631 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
| 5632 | } ref; |
| 5633 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5634 | } load_data_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5635 | |
| 5636 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5637 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5638 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5639 | |
| 5640 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5641 | inline const DexFile& HLoadString::GetDexFile() const { |
| 5642 | DCHECK(HasStringReference(GetLoadKind()) || HasDexCacheReference(GetLoadKind())) |
| 5643 | << GetLoadKind(); |
| 5644 | return *load_data_.ref.dex_file; |
| 5645 | } |
| 5646 | |
| 5647 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5648 | inline uint32_t HLoadString::GetDexCacheElementOffset() const { |
| 5649 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5650 | return load_data_.ref.dex_cache_element_index; |
| 5651 | } |
| 5652 | |
| 5653 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5654 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
| 5655 | // The special input is used for PC-relative loads on some architectures. |
| 5656 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 5657 | GetLoadKind() == LoadKind::kDexCachePcRelative) << GetLoadKind(); |
| 5658 | DCHECK(InputAt(0) == nullptr); |
| 5659 | SetRawInputAt(0u, special_input); |
| 5660 | special_input->AddUseAt(this, 0); |
| 5661 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5662 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5663 | /** |
| 5664 | * Performs an initialization check on its Class object input. |
| 5665 | */ |
| 5666 | class HClinitCheck : public HExpression<1> { |
| 5667 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5668 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5669 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5670 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5671 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5672 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5673 | SetRawInputAt(0, constant); |
| 5674 | } |
| 5675 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5676 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5677 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5678 | return true; |
| 5679 | } |
| 5680 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5681 | bool NeedsEnvironment() const OVERRIDE { |
| 5682 | // May call runtime to initialize the class. |
| 5683 | return true; |
| 5684 | } |
| 5685 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5686 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5687 | |
| 5688 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5689 | |
| 5690 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5691 | |
| 5692 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5693 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5694 | }; |
| 5695 | |
| 5696 | class HStaticFieldGet : public HExpression<1> { |
| 5697 | public: |
| 5698 | HStaticFieldGet(HInstruction* cls, |
| 5699 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5700 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5701 | bool is_volatile, |
| 5702 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5703 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5704 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5705 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5706 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5707 | : HExpression(field_type, |
| 5708 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5709 | dex_pc), |
| 5710 | field_info_(field_offset, |
| 5711 | field_type, |
| 5712 | is_volatile, |
| 5713 | field_idx, |
| 5714 | declaring_class_def_index, |
| 5715 | dex_file, |
| 5716 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5717 | SetRawInputAt(0, cls); |
| 5718 | } |
| 5719 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5720 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5721 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5722 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5723 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5724 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5725 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5726 | } |
| 5727 | |
| 5728 | size_t ComputeHashCode() const OVERRIDE { |
| 5729 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5730 | } |
| 5731 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5732 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5733 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5734 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5735 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5736 | |
| 5737 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5738 | |
| 5739 | private: |
| 5740 | const FieldInfo field_info_; |
| 5741 | |
| 5742 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5743 | }; |
| 5744 | |
| 5745 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5746 | public: |
| 5747 | HStaticFieldSet(HInstruction* cls, |
| 5748 | HInstruction* value, |
| 5749 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5750 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5751 | bool is_volatile, |
| 5752 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5753 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5754 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5755 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5756 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5757 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5758 | dex_pc), |
| 5759 | field_info_(field_offset, |
| 5760 | field_type, |
| 5761 | is_volatile, |
| 5762 | field_idx, |
| 5763 | declaring_class_def_index, |
| 5764 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5765 | dex_cache) { |
| 5766 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5767 | SetRawInputAt(0, cls); |
| 5768 | SetRawInputAt(1, value); |
| 5769 | } |
| 5770 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5771 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5772 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5773 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5774 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5775 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5776 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5777 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5778 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5779 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5780 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5781 | |
| 5782 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5783 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5784 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5785 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5786 | "Too many packed fields."); |
| 5787 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5788 | const FieldInfo field_info_; |
| 5789 | |
| 5790 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5791 | }; |
| 5792 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5793 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5794 | public: |
| 5795 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5796 | Primitive::Type field_type, |
| 5797 | uint32_t field_index, |
| 5798 | uint32_t dex_pc) |
| 5799 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5800 | field_index_(field_index) { |
| 5801 | SetRawInputAt(0, obj); |
| 5802 | } |
| 5803 | |
| 5804 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5805 | bool CanThrow() const OVERRIDE { return true; } |
| 5806 | |
| 5807 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5808 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5809 | |
| 5810 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5811 | |
| 5812 | private: |
| 5813 | const uint32_t field_index_; |
| 5814 | |
| 5815 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5816 | }; |
| 5817 | |
| 5818 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5819 | public: |
| 5820 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5821 | HInstruction* value, |
| 5822 | Primitive::Type field_type, |
| 5823 | uint32_t field_index, |
| 5824 | uint32_t dex_pc) |
| 5825 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5826 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5827 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5828 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5829 | SetRawInputAt(0, obj); |
| 5830 | SetRawInputAt(1, value); |
| 5831 | } |
| 5832 | |
| 5833 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5834 | bool CanThrow() const OVERRIDE { return true; } |
| 5835 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5836 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5837 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5838 | |
| 5839 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5840 | |
| 5841 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5842 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5843 | static constexpr size_t kFieldFieldTypeSize = |
| 5844 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5845 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5846 | kFieldFieldType + kFieldFieldTypeSize; |
| 5847 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5848 | "Too many packed fields."); |
| 5849 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5850 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5851 | const uint32_t field_index_; |
| 5852 | |
| 5853 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5854 | }; |
| 5855 | |
| 5856 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5857 | public: |
| 5858 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5859 | uint32_t field_index, |
| 5860 | uint32_t dex_pc) |
| 5861 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5862 | field_index_(field_index) { |
| 5863 | } |
| 5864 | |
| 5865 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5866 | bool CanThrow() const OVERRIDE { return true; } |
| 5867 | |
| 5868 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5869 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5870 | |
| 5871 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5872 | |
| 5873 | private: |
| 5874 | const uint32_t field_index_; |
| 5875 | |
| 5876 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5877 | }; |
| 5878 | |
| 5879 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5880 | public: |
| 5881 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5882 | Primitive::Type field_type, |
| 5883 | uint32_t field_index, |
| 5884 | uint32_t dex_pc) |
| 5885 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5886 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5887 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5888 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5889 | SetRawInputAt(0, value); |
| 5890 | } |
| 5891 | |
| 5892 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5893 | bool CanThrow() const OVERRIDE { return true; } |
| 5894 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5895 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5896 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5897 | |
| 5898 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5899 | |
| 5900 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5901 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5902 | static constexpr size_t kFieldFieldTypeSize = |
| 5903 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5904 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5905 | kFieldFieldType + kFieldFieldTypeSize; |
| 5906 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5907 | "Too many packed fields."); |
| 5908 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5909 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5910 | const uint32_t field_index_; |
| 5911 | |
| 5912 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5913 | }; |
| 5914 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5915 | // Implement the move-exception DEX instruction. |
| 5916 | class HLoadException : public HExpression<0> { |
| 5917 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5918 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5919 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5920 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5921 | bool CanBeNull() const OVERRIDE { return false; } |
| 5922 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5923 | DECLARE_INSTRUCTION(LoadException); |
| 5924 | |
| 5925 | private: |
| 5926 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5927 | }; |
| 5928 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5929 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5930 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5931 | class HClearException : public HTemplateInstruction<0> { |
| 5932 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5933 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5934 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5935 | |
| 5936 | DECLARE_INSTRUCTION(ClearException); |
| 5937 | |
| 5938 | private: |
| 5939 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5940 | }; |
| 5941 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5942 | class HThrow : public HTemplateInstruction<1> { |
| 5943 | public: |
| 5944 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5945 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5946 | SetRawInputAt(0, exception); |
| 5947 | } |
| 5948 | |
| 5949 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5950 | |
| 5951 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5952 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5953 | bool CanThrow() const OVERRIDE { return true; } |
| 5954 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5955 | |
| 5956 | DECLARE_INSTRUCTION(Throw); |
| 5957 | |
| 5958 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5959 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5960 | }; |
| 5961 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5962 | /** |
| 5963 | * Implementation strategies for the code generator of a HInstanceOf |
| 5964 | * or `HCheckCast`. |
| 5965 | */ |
| 5966 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5967 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5968 | kExactCheck, // Can do a single class compare. |
| 5969 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5970 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5971 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5972 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5973 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 5974 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5975 | }; |
| 5976 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5977 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 5978 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5979 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5980 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5981 | HInstanceOf(HInstruction* object, |
| 5982 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5983 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5984 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5985 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5986 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5987 | dex_pc) { |
| 5988 | SetPackedField<TypeCheckKindField>(check_kind); |
| 5989 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5990 | SetRawInputAt(0, object); |
| 5991 | SetRawInputAt(1, constant); |
| 5992 | } |
| 5993 | |
| 5994 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5995 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5996 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5997 | return true; |
| 5998 | } |
| 5999 | |
| 6000 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6001 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6002 | } |
| 6003 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6004 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6005 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6006 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6007 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6008 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6009 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6010 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6011 | // Mips currently does runtime calls for any other checks. |
| 6012 | return check_kind != TypeCheckKind::kExactCheck; |
| 6013 | } |
| 6014 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6015 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6016 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6017 | } |
| 6018 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6019 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6020 | |
| 6021 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6022 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6023 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6024 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6025 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6026 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6027 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6028 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6029 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6030 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6031 | }; |
| 6032 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6033 | class HBoundType : public HExpression<1> { |
| 6034 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6035 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6036 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6037 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6038 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6039 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6040 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6041 | SetRawInputAt(0, input); |
| 6042 | } |
| 6043 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6044 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6045 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6046 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6047 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6048 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6049 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6050 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6051 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6052 | } |
| 6053 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6054 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6055 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6056 | DECLARE_INSTRUCTION(BoundType); |
| 6057 | |
| 6058 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6059 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6060 | // is false then CanBeNull() cannot be true). |
| 6061 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6062 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6063 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6064 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6065 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6066 | // 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] | 6067 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6068 | // It is used to bound the type in cases like: |
| 6069 | // if (x instanceof ClassX) { |
| 6070 | // // uper_bound_ will be ClassX |
| 6071 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6072 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6073 | |
| 6074 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6075 | }; |
| 6076 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6077 | class HCheckCast : public HTemplateInstruction<2> { |
| 6078 | public: |
| 6079 | HCheckCast(HInstruction* object, |
| 6080 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6081 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6082 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6083 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6084 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6085 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6086 | SetRawInputAt(0, object); |
| 6087 | SetRawInputAt(1, constant); |
| 6088 | } |
| 6089 | |
| 6090 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6091 | |
| 6092 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6093 | return true; |
| 6094 | } |
| 6095 | |
| 6096 | bool NeedsEnvironment() const OVERRIDE { |
| 6097 | // Instruction may throw a CheckCastError. |
| 6098 | return true; |
| 6099 | } |
| 6100 | |
| 6101 | bool CanThrow() const OVERRIDE { return true; } |
| 6102 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6103 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6104 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6105 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6106 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6107 | |
| 6108 | DECLARE_INSTRUCTION(CheckCast); |
| 6109 | |
| 6110 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6111 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6112 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6113 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6114 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6115 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6116 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6117 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6118 | |
| 6119 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6120 | }; |
| 6121 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6122 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 6123 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6124 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6125 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6126 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6127 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6128 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6129 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6130 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6131 | |
| 6132 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6133 | |
| 6134 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6135 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6136 | static constexpr size_t kFieldBarrierKindSize = |
| 6137 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6138 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6139 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6140 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6141 | "Too many packed fields."); |
| 6142 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6143 | |
| 6144 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6145 | }; |
| 6146 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6147 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 6148 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6149 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6150 | kEnter, |
| 6151 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6152 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6153 | }; |
| 6154 | |
| 6155 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6156 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6157 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6158 | dex_pc) { |
| 6159 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6160 | SetRawInputAt(0, object); |
| 6161 | } |
| 6162 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6163 | // Instruction may go into runtime, so we need an environment. |
| 6164 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6165 | |
| 6166 | bool CanThrow() const OVERRIDE { |
| 6167 | // Verifier guarantees that monitor-exit cannot throw. |
| 6168 | // This is important because it allows the HGraphBuilder to remove |
| 6169 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6170 | return IsEnter(); |
| 6171 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6172 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6173 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6174 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6175 | |
| 6176 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6177 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6178 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6179 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6180 | static constexpr size_t kFieldOperationKindSize = |
| 6181 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6182 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6183 | kFieldOperationKind + kFieldOperationKindSize; |
| 6184 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6185 | "Too many packed fields."); |
| 6186 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6187 | |
| 6188 | private: |
| 6189 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6190 | }; |
| 6191 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6192 | class HSelect : public HExpression<3> { |
| 6193 | public: |
| 6194 | HSelect(HInstruction* condition, |
| 6195 | HInstruction* true_value, |
| 6196 | HInstruction* false_value, |
| 6197 | uint32_t dex_pc) |
| 6198 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6199 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6200 | |
| 6201 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6202 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6203 | // that architectures which implement HSelect as a conditional move also |
| 6204 | // will not need to invert the condition. |
| 6205 | SetRawInputAt(0, false_value); |
| 6206 | SetRawInputAt(1, true_value); |
| 6207 | SetRawInputAt(2, condition); |
| 6208 | } |
| 6209 | |
| 6210 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6211 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6212 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6213 | |
| 6214 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6215 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
| 6216 | |
| 6217 | bool CanBeNull() const OVERRIDE { |
| 6218 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6219 | } |
| 6220 | |
| 6221 | DECLARE_INSTRUCTION(Select); |
| 6222 | |
| 6223 | private: |
| 6224 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6225 | }; |
| 6226 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6227 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6228 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6229 | MoveOperands(Location source, |
| 6230 | Location destination, |
| 6231 | Primitive::Type type, |
| 6232 | HInstruction* instruction) |
| 6233 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6234 | |
| 6235 | Location GetSource() const { return source_; } |
| 6236 | Location GetDestination() const { return destination_; } |
| 6237 | |
| 6238 | void SetSource(Location value) { source_ = value; } |
| 6239 | void SetDestination(Location value) { destination_ = value; } |
| 6240 | |
| 6241 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6242 | // destination (but not the source). |
| 6243 | Location MarkPending() { |
| 6244 | DCHECK(!IsPending()); |
| 6245 | Location dest = destination_; |
| 6246 | destination_ = Location::NoLocation(); |
| 6247 | return dest; |
| 6248 | } |
| 6249 | |
| 6250 | void ClearPending(Location dest) { |
| 6251 | DCHECK(IsPending()); |
| 6252 | destination_ = dest; |
| 6253 | } |
| 6254 | |
| 6255 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6256 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6257 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | // True if this blocks a move from the given location. |
| 6261 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6262 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | // A move is redundant if it's been eliminated, if its source and |
| 6266 | // destination are the same, or if its destination is unneeded. |
| 6267 | bool IsRedundant() const { |
| 6268 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6269 | } |
| 6270 | |
| 6271 | // We clear both operands to indicate move that's been eliminated. |
| 6272 | void Eliminate() { |
| 6273 | source_ = destination_ = Location::NoLocation(); |
| 6274 | } |
| 6275 | |
| 6276 | bool IsEliminated() const { |
| 6277 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6278 | return source_.IsInvalid(); |
| 6279 | } |
| 6280 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6281 | Primitive::Type GetType() const { return type_; } |
| 6282 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6283 | bool Is64BitMove() const { |
| 6284 | return Primitive::Is64BitType(type_); |
| 6285 | } |
| 6286 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6287 | HInstruction* GetInstruction() const { return instruction_; } |
| 6288 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6289 | private: |
| 6290 | Location source_; |
| 6291 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6292 | // The type this move is for. |
| 6293 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6294 | // The instruction this move is assocatied with. Null when this move is |
| 6295 | // for moving an input in the expected locations of user (including a phi user). |
| 6296 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6297 | // in the same parallel move. |
| 6298 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6299 | }; |
| 6300 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6301 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6302 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6303 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6304 | |
| 6305 | class HParallelMove : public HTemplateInstruction<0> { |
| 6306 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6307 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6308 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6309 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6310 | moves_.reserve(kDefaultNumberOfMoves); |
| 6311 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6312 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6313 | void AddMove(Location source, |
| 6314 | Location destination, |
| 6315 | Primitive::Type type, |
| 6316 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6317 | DCHECK(source.IsValid()); |
| 6318 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6319 | if (kIsDebugBuild) { |
| 6320 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6321 | for (const MoveOperands& move : moves_) { |
| 6322 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6323 | // Special case the situation where the move is for the spill slot |
| 6324 | // of the instruction. |
| 6325 | if ((GetPrevious() == instruction) |
| 6326 | || ((GetPrevious() == nullptr) |
| 6327 | && instruction->IsPhi() |
| 6328 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6329 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6330 | << "Doing parallel moves for the same instruction."; |
| 6331 | } else { |
| 6332 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6333 | } |
| 6334 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6335 | } |
| 6336 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6337 | for (const MoveOperands& move : moves_) { |
| 6338 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6339 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6340 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6341 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6342 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6343 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6344 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6345 | } |
| 6346 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6347 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6348 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6349 | } |
| 6350 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6351 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6352 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6353 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6354 | |
| 6355 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6356 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6357 | |
| 6358 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6359 | }; |
| 6360 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6361 | } // namespace art |
| 6362 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6363 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6364 | #include "nodes_shared.h" |
| 6365 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6366 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6367 | #include "nodes_arm.h" |
| 6368 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6369 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6370 | #include "nodes_arm64.h" |
| 6371 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6372 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6373 | #include "nodes_x86.h" |
| 6374 | #endif |
| 6375 | |
| 6376 | namespace art { |
| 6377 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6378 | class HGraphVisitor : public ValueObject { |
| 6379 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6380 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6381 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6382 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6383 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6384 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6385 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6386 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6387 | void VisitInsertionOrder(); |
| 6388 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6389 | // Visit the graph following dominator tree reverse post-order. |
| 6390 | void VisitReversePostOrder(); |
| 6391 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6392 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6393 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6394 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6395 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6396 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6397 | |
| 6398 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6399 | |
| 6400 | #undef DECLARE_VISIT_INSTRUCTION |
| 6401 | |
| 6402 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6403 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6404 | |
| 6405 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6406 | }; |
| 6407 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6408 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6409 | public: |
| 6410 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6411 | virtual ~HGraphDelegateVisitor() {} |
| 6412 | |
| 6413 | // Visit functions that delegate to to super class. |
| 6414 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6415 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6416 | |
| 6417 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6418 | |
| 6419 | #undef DECLARE_VISIT_INSTRUCTION |
| 6420 | |
| 6421 | private: |
| 6422 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6423 | }; |
| 6424 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6425 | class HInsertionOrderIterator : public ValueObject { |
| 6426 | public: |
| 6427 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 6428 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6429 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 6430 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6431 | void Advance() { ++index_; } |
| 6432 | |
| 6433 | private: |
| 6434 | const HGraph& graph_; |
| 6435 | size_t index_; |
| 6436 | |
| 6437 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 6438 | }; |
| 6439 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6440 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6441 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6442 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 6443 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6444 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6445 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6446 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6447 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 6448 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6449 | void Advance() { ++index_; } |
| 6450 | |
| 6451 | private: |
| 6452 | const HGraph& graph_; |
| 6453 | size_t index_; |
| 6454 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6455 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6456 | }; |
| 6457 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6458 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6459 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6460 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6461 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6462 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6463 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6464 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6465 | |
| 6466 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6467 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6468 | void Advance() { --index_; } |
| 6469 | |
| 6470 | private: |
| 6471 | const HGraph& graph_; |
| 6472 | size_t index_; |
| 6473 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6474 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6475 | }; |
| 6476 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6477 | class HLinearPostOrderIterator : public ValueObject { |
| 6478 | public: |
| 6479 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6480 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6481 | |
| 6482 | bool Done() const { return index_ == 0; } |
| 6483 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6484 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6485 | |
| 6486 | void Advance() { |
| 6487 | --index_; |
| 6488 | DCHECK_GE(index_, 0U); |
| 6489 | } |
| 6490 | |
| 6491 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6492 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6493 | size_t index_; |
| 6494 | |
| 6495 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 6496 | }; |
| 6497 | |
| 6498 | class HLinearOrderIterator : public ValueObject { |
| 6499 | public: |
| 6500 | explicit HLinearOrderIterator(const HGraph& graph) |
| 6501 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 6502 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6503 | bool Done() const { return index_ == order_.size(); } |
| 6504 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6505 | void Advance() { ++index_; } |
| 6506 | |
| 6507 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6508 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6509 | size_t index_; |
| 6510 | |
| 6511 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 6512 | }; |
| 6513 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6514 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6515 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6516 | // block id. |
| 6517 | class HBlocksInLoopIterator : public ValueObject { |
| 6518 | public: |
| 6519 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6520 | : blocks_in_loop_(info.GetBlocks()), |
| 6521 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6522 | index_(0) { |
| 6523 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6524 | Advance(); |
| 6525 | } |
| 6526 | } |
| 6527 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6528 | bool Done() const { return index_ == blocks_.size(); } |
| 6529 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6530 | void Advance() { |
| 6531 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6532 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6533 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6534 | break; |
| 6535 | } |
| 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | private: |
| 6540 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6541 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6542 | size_t index_; |
| 6543 | |
| 6544 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6545 | }; |
| 6546 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6547 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6548 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6549 | // post order. |
| 6550 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6551 | public: |
| 6552 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6553 | : blocks_in_loop_(info.GetBlocks()), |
| 6554 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6555 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6556 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6557 | Advance(); |
| 6558 | } |
| 6559 | } |
| 6560 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6561 | bool Done() const { return index_ == blocks_.size(); } |
| 6562 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6563 | void Advance() { |
| 6564 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6565 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6566 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6567 | break; |
| 6568 | } |
| 6569 | } |
| 6570 | } |
| 6571 | |
| 6572 | private: |
| 6573 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6574 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6575 | size_t index_; |
| 6576 | |
| 6577 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6578 | }; |
| 6579 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6580 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6581 | if (constant->IsIntConstant()) { |
| 6582 | return constant->AsIntConstant()->GetValue(); |
| 6583 | } else if (constant->IsLongConstant()) { |
| 6584 | return constant->AsLongConstant()->GetValue(); |
| 6585 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6586 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6587 | return 0; |
| 6588 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6589 | } |
| 6590 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6591 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 6592 | // For the purposes of the compiler, the dex files must actually be the same object |
| 6593 | // if we want to safely treat them as the same. This is especially important for JIT |
| 6594 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 6595 | // times and provide different class resolution but no two class loaders should ever |
| 6596 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 6597 | // all sorts of weird failures. |
| 6598 | return &lhs == &rhs; |
| 6599 | } |
| 6600 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6601 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6602 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6603 | inline const H##type* HInstruction::As##type() const { \ |
| 6604 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6605 | } \ |
| 6606 | inline H##type* HInstruction::As##type() { \ |
| 6607 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6608 | } |
| 6609 | |
| 6610 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6611 | #undef INSTRUCTION_TYPE_CHECK |
| 6612 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6613 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6614 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6615 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6616 | size_t number_of_new_blocks, |
| 6617 | size_t after) { |
| 6618 | DCHECK_LT(after, blocks->size()); |
| 6619 | size_t old_size = blocks->size(); |
| 6620 | size_t new_size = old_size + number_of_new_blocks; |
| 6621 | blocks->resize(new_size); |
| 6622 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6623 | } |
| 6624 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6625 | } // namespace art |
| 6626 | |
| 6627 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |