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 | |
| 172 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 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 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 430 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 431 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 432 | return number_of_vregs_ - number_of_in_vregs_; |
| 433 | } |
| 434 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 435 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 436 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 437 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 438 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 439 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 440 | return linear_order_; |
| 441 | } |
| 442 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 443 | bool HasBoundsChecks() const { |
| 444 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 447 | void SetHasBoundsChecks(bool value) { |
| 448 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 449 | } |
| 450 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 451 | bool ShouldGenerateConstructorBarrier() const { |
| 452 | return should_generate_constructor_barrier_; |
| 453 | } |
| 454 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 455 | bool IsDebuggable() const { return debuggable_; } |
| 456 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 457 | // 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] | 458 | // already, it is created and inserted into the graph. This method is only for |
| 459 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 460 | 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] | 461 | |
| 462 | // TODO: This is problematic for the consistency of reference type propagation |
| 463 | // because it can be created anytime after the pass and thus it will be left |
| 464 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 465 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 466 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 467 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 468 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 469 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 470 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 471 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 472 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 473 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 474 | 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] | 475 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 476 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 477 | 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] | 478 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 479 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 480 | HCurrentMethod* GetCurrentMethod(); |
| 481 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 482 | const DexFile& GetDexFile() const { |
| 483 | return dex_file_; |
| 484 | } |
| 485 | |
| 486 | uint32_t GetMethodIdx() const { |
| 487 | return method_idx_; |
| 488 | } |
| 489 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 490 | InvokeType GetInvokeType() const { |
| 491 | return invoke_type_; |
| 492 | } |
| 493 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 494 | InstructionSet GetInstructionSet() const { |
| 495 | return instruction_set_; |
| 496 | } |
| 497 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 498 | bool IsCompilingOsr() const { return osr_; } |
| 499 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 500 | bool HasTryCatch() const { return has_try_catch_; } |
| 501 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 502 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 503 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 504 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 505 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 506 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 507 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 508 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 509 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 510 | // The instruction has been inserted into the graph, either as a constant, or |
| 511 | // before cursor. |
| 512 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 513 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 514 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 515 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 516 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 517 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 518 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 519 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 520 | template <class InstructionType, typename ValueType> |
| 521 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 522 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 523 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 524 | // Try to find an existing constant of the given value. |
| 525 | InstructionType* constant = nullptr; |
| 526 | auto cached_constant = cache->find(value); |
| 527 | if (cached_constant != cache->end()) { |
| 528 | constant = cached_constant->second; |
| 529 | } |
| 530 | |
| 531 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 532 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 533 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 534 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 535 | cache->Overwrite(value, constant); |
| 536 | InsertConstant(constant); |
| 537 | } |
| 538 | return constant; |
| 539 | } |
| 540 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 541 | void InsertConstant(HConstant* instruction); |
| 542 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 543 | // Cache a float constant into the graph. This method should only be |
| 544 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 545 | void CacheFloatConstant(HFloatConstant* constant); |
| 546 | |
| 547 | // See CacheFloatConstant comment. |
| 548 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 549 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 550 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 551 | |
| 552 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 553 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 554 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 555 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 556 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 557 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 558 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 559 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 560 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 561 | HBasicBlock* entry_block_; |
| 562 | HBasicBlock* exit_block_; |
| 563 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 564 | // 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] | 565 | uint16_t maximum_number_of_out_vregs_; |
| 566 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 567 | // The number of virtual registers in this method. Contains the parameters. |
| 568 | uint16_t number_of_vregs_; |
| 569 | |
| 570 | // The number of virtual registers used by parameters of this method. |
| 571 | uint16_t number_of_in_vregs_; |
| 572 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 573 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 574 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 575 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 576 | // Has bounds checks. We can totally skip BCE if it's false. |
| 577 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 578 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 579 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 580 | // try/catch-related passes if false. |
| 581 | bool has_try_catch_; |
| 582 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 583 | // Flag whether there are any irreducible loops in the graph. |
| 584 | bool has_irreducible_loops_; |
| 585 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 586 | // Indicates whether the graph should be compiled in a way that |
| 587 | // ensures full debuggability. If false, we can apply more |
| 588 | // aggressive optimizations that may limit the level of debugging. |
| 589 | const bool debuggable_; |
| 590 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 591 | // 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] | 592 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 593 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 594 | // The dex file from which the method is from. |
| 595 | const DexFile& dex_file_; |
| 596 | |
| 597 | // The method index in the dex file. |
| 598 | const uint32_t method_idx_; |
| 599 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 600 | // If inlined, this encodes how the callee is being invoked. |
| 601 | const InvokeType invoke_type_; |
| 602 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 603 | // Whether the graph has been transformed to SSA form. Only used |
| 604 | // in debug mode to ensure we are not using properties only valid |
| 605 | // for non-SSA form (like the number of temporaries). |
| 606 | bool in_ssa_form_; |
| 607 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 608 | const bool should_generate_constructor_barrier_; |
| 609 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 610 | const InstructionSet instruction_set_; |
| 611 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 612 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 613 | HNullConstant* cached_null_constant_; |
| 614 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 615 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 616 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 617 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 618 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 619 | HCurrentMethod* cached_current_method_; |
| 620 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 621 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 622 | // for example for methods whose declaring class could not be resolved |
| 623 | // (such as when the superclass could not be found). |
| 624 | ArtMethod* art_method_; |
| 625 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 626 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 627 | // collection pointer to passes which may create NullConstant. |
| 628 | ReferenceTypeInfo inexact_object_rti_; |
| 629 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 630 | // Whether we are compiling this graph for on stack replacement: this will |
| 631 | // make all loops seen as irreducible and emit special stack maps to mark |
| 632 | // compiled code entries which the interpreter can directly jump to. |
| 633 | const bool osr_; |
| 634 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 635 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 636 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 637 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 638 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 639 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 640 | }; |
| 641 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 642 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 643 | public: |
| 644 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 645 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 646 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 647 | irreducible_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 648 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 649 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 650 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 651 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 652 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 653 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 654 | bool IsIrreducible() const { return irreducible_; } |
| 655 | |
| 656 | void Dump(std::ostream& os); |
| 657 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 658 | HBasicBlock* GetHeader() const { |
| 659 | return header_; |
| 660 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 661 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 662 | void SetHeader(HBasicBlock* block) { |
| 663 | header_ = block; |
| 664 | } |
| 665 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 666 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 667 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 668 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 669 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 670 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 671 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 674 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 675 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 676 | } |
| 677 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 678 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 679 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 680 | } |
| 681 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 682 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 683 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 684 | } |
| 685 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 686 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 687 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 688 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 689 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 690 | } |
| 691 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 692 | // Returns the lifetime position of the back edge that has the |
| 693 | // greatest lifetime position. |
| 694 | size_t GetLifetimeEnd() const; |
| 695 | |
| 696 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 697 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 698 | } |
| 699 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 700 | // Finds blocks that are part of this loop. |
| 701 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 702 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 703 | // Returns whether this loop information contains `block`. |
| 704 | // Note that this loop information *must* be populated before entering this function. |
| 705 | bool Contains(const HBasicBlock& block) const; |
| 706 | |
| 707 | // Returns whether this loop information is an inner loop of `other`. |
| 708 | // Note that `other` *must* be populated before entering this function. |
| 709 | bool IsIn(const HLoopInformation& other) const; |
| 710 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 711 | // Returns true if instruction is not defined within this loop. |
| 712 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 713 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 714 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 715 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 716 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 717 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 718 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 719 | void ClearAllBlocks() { |
| 720 | blocks_.ClearAllBits(); |
| 721 | } |
| 722 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 723 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 724 | // Internal recursive implementation of `Populate`. |
| 725 | void PopulateRecursive(HBasicBlock* block); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 726 | void PopulateIrreducibleRecursive(HBasicBlock* block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 727 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 728 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 729 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 730 | bool irreducible_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 731 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 732 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 733 | |
| 734 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 735 | }; |
| 736 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 737 | // Stores try/catch information for basic blocks. |
| 738 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 739 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 740 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 741 | public: |
| 742 | // Try block information constructor. |
| 743 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 744 | : try_entry_(&try_entry), |
| 745 | catch_dex_file_(nullptr), |
| 746 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 747 | DCHECK(try_entry_ != nullptr); |
| 748 | } |
| 749 | |
| 750 | // Catch block information constructor. |
| 751 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 752 | : try_entry_(nullptr), |
| 753 | catch_dex_file_(&dex_file), |
| 754 | catch_type_index_(catch_type_index) {} |
| 755 | |
| 756 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 757 | |
| 758 | const HTryBoundary& GetTryEntry() const { |
| 759 | DCHECK(IsTryBlock()); |
| 760 | return *try_entry_; |
| 761 | } |
| 762 | |
| 763 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 764 | |
| 765 | bool IsCatchAllTypeIndex() const { |
| 766 | DCHECK(IsCatchBlock()); |
| 767 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 768 | } |
| 769 | |
| 770 | uint16_t GetCatchTypeIndex() const { |
| 771 | DCHECK(IsCatchBlock()); |
| 772 | return catch_type_index_; |
| 773 | } |
| 774 | |
| 775 | const DexFile& GetCatchDexFile() const { |
| 776 | DCHECK(IsCatchBlock()); |
| 777 | return *catch_dex_file_; |
| 778 | } |
| 779 | |
| 780 | private: |
| 781 | // One of possibly several TryBoundary instructions entering the block's try. |
| 782 | // Only set for try blocks. |
| 783 | const HTryBoundary* try_entry_; |
| 784 | |
| 785 | // Exception type information. Only set for catch blocks. |
| 786 | const DexFile* catch_dex_file_; |
| 787 | const uint16_t catch_type_index_; |
| 788 | }; |
| 789 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 790 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 791 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 792 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 793 | // A block in a method. Contains the list of instructions represented |
| 794 | // as a double linked list. Each block knows its predecessors and |
| 795 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 796 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 797 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 798 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 799 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 800 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 801 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 802 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 803 | loop_information_(nullptr), |
| 804 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 805 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 806 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 807 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 808 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 809 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 810 | try_catch_information_(nullptr) { |
| 811 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 812 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 813 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 814 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 815 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 816 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 817 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 820 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 821 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 822 | } |
| 823 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 824 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 825 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 826 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 827 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 828 | return ContainsElement(successors_, block, start_from); |
| 829 | } |
| 830 | |
| 831 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 832 | return dominated_blocks_; |
| 833 | } |
| 834 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 835 | bool IsEntryBlock() const { |
| 836 | return graph_->GetEntryBlock() == this; |
| 837 | } |
| 838 | |
| 839 | bool IsExitBlock() const { |
| 840 | return graph_->GetExitBlock() == this; |
| 841 | } |
| 842 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 843 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 844 | bool IsSingleTryBoundary() const; |
| 845 | |
| 846 | // Returns true if this block emits nothing but a jump. |
| 847 | bool IsSingleJump() const { |
| 848 | HLoopInformation* loop_info = GetLoopInformation(); |
| 849 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 850 | // Back edges generate a suspend check. |
| 851 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 852 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 853 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 854 | void AddBackEdge(HBasicBlock* back_edge) { |
| 855 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 856 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 857 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 858 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 859 | loop_information_->AddBackEdge(back_edge); |
| 860 | } |
| 861 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 862 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 863 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 864 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 865 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 866 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 867 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 868 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 869 | HBasicBlock* GetDominator() const { return dominator_; } |
| 870 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 871 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 872 | |
| 873 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 874 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 875 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 876 | |
| 877 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 878 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 879 | } |
| 880 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 881 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 882 | |
| 883 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 884 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 885 | } |
| 886 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 887 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 888 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 889 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 890 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 891 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 892 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 893 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 894 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 895 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 896 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 897 | successors_.push_back(block); |
| 898 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 901 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 902 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 903 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 904 | new_block->predecessors_.push_back(this); |
| 905 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 908 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 909 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 910 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 911 | new_block->successors_.push_back(this); |
| 912 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 915 | // Insert `this` between `predecessor` and `successor. This method |
| 916 | // preserves the indicies, and will update the first edge found between |
| 917 | // `predecessor` and `successor`. |
| 918 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 919 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 920 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 921 | successor->predecessors_[predecessor_index] = this; |
| 922 | predecessor->successors_[successor_index] = this; |
| 923 | successors_.push_back(successor); |
| 924 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 925 | } |
| 926 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 927 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 928 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 929 | } |
| 930 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 931 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 932 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 935 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 936 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 940 | predecessors_.push_back(block); |
| 941 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 942 | } |
| 943 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 944 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 945 | DCHECK_EQ(predecessors_.size(), 2u); |
| 946 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 947 | } |
| 948 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 949 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 950 | DCHECK_EQ(successors_.size(), 2u); |
| 951 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 952 | } |
| 953 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 954 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 955 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 956 | } |
| 957 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 958 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 959 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 960 | } |
| 961 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 962 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 963 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 964 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 968 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 969 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | // Returns whether the first occurrence of `predecessor` in the list of |
| 973 | // predecessors is at index `idx`. |
| 974 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 975 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 976 | return GetPredecessorIndexOf(predecessor) == idx; |
| 977 | } |
| 978 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 979 | // Create a new block between this block and its predecessors. The new block |
| 980 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 981 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 982 | // loop and try/catch information are not updated. |
| 983 | HBasicBlock* CreateImmediateDominator(); |
| 984 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 985 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 986 | // created, latter block. Note that this method will add the block to the |
| 987 | // graph, create a Goto at the end of the former block and will create an edge |
| 988 | // 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] | 989 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 990 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 991 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 992 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 993 | // created block. Note that this method just updates raw block information, |
| 994 | // like predecessors, successors, dominators, and instruction list. It does not |
| 995 | // update the graph, reverse post order, loop information, nor make sure the |
| 996 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 997 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 998 | |
| 999 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1000 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1001 | |
| 1002 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1003 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1004 | // that this method does not update the graph, reverse post order, loop |
| 1005 | // information, nor make sure the blocks are consistent (for example ending |
| 1006 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1007 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1008 | |
| 1009 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1010 | // of `this` are moved to `other`. |
| 1011 | // Note that this method does not update the graph, reverse post order, loop |
| 1012 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1013 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1014 | void ReplaceWith(HBasicBlock* other); |
| 1015 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1016 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1017 | // order, links to predecessors, successors, dominators and deletes the block |
| 1018 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1019 | // predecessor of `other` and vice versa. |
| 1020 | void MergeWith(HBasicBlock* other); |
| 1021 | |
| 1022 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1023 | // removes it from all loops it is included in and eventually from the graph. |
| 1024 | // The block must not dominate any other block. Predecessors and successors |
| 1025 | // are safely updated. |
| 1026 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1027 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1028 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1029 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1030 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1031 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1032 | // Replace instruction `initial` with `replacement` within this block. |
| 1033 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1034 | HInstruction* replacement); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1035 | void MoveInstructionBefore(HInstruction* insn, HInstruction* cursor); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1036 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1037 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1038 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1039 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1040 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1041 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1042 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1043 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1044 | |
| 1045 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1046 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1047 | } |
| 1048 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1049 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1050 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1051 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1052 | } |
| 1053 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1054 | bool IsFirstPredecessorBackEdge() const { |
| 1055 | DCHECK(IsLoopHeader()); |
| 1056 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1057 | } |
| 1058 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1059 | HLoopInformation* GetLoopInformation() const { |
| 1060 | return loop_information_; |
| 1061 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1062 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1063 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1064 | // 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] | 1065 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1066 | void SetInLoop(HLoopInformation* info) { |
| 1067 | if (IsLoopHeader()) { |
| 1068 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1069 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1070 | loop_information_ = info; |
| 1071 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1072 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1073 | // Note that a non loop header having a loop information means this loop information |
| 1074 | // has already been populated |
| 1075 | loop_information_ = info; |
| 1076 | } else { |
| 1077 | // Block is part of an inner loop. Do not update the loop information. |
| 1078 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1079 | // at this point, because this method is being called while populating `info`. |
| 1080 | } |
| 1081 | } |
| 1082 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1083 | // Raw update of the loop information. |
| 1084 | void SetLoopInformation(HLoopInformation* info) { |
| 1085 | loop_information_ = info; |
| 1086 | } |
| 1087 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1088 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1089 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1090 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1091 | |
| 1092 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1093 | try_catch_information_ = try_catch_information; |
| 1094 | } |
| 1095 | |
| 1096 | bool IsTryBlock() const { |
| 1097 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1098 | } |
| 1099 | |
| 1100 | bool IsCatchBlock() const { |
| 1101 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1102 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1103 | |
| 1104 | // Returns the try entry that this block's successors should have. They will |
| 1105 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1106 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1107 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1108 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1109 | bool HasThrowingInstructions() const; |
| 1110 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1111 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1112 | bool Dominates(HBasicBlock* block) const; |
| 1113 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1114 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1115 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1116 | |
| 1117 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1118 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1119 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1120 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1121 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1122 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1123 | bool HasSinglePhi() const; |
| 1124 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1125 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1126 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1127 | ArenaVector<HBasicBlock*> predecessors_; |
| 1128 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1129 | HInstructionList instructions_; |
| 1130 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1131 | HLoopInformation* loop_information_; |
| 1132 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1133 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1134 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1135 | // The dex program counter of the first instruction of this block. |
| 1136 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1137 | size_t lifetime_start_; |
| 1138 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1139 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1140 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1141 | friend class HGraph; |
| 1142 | friend class HInstruction; |
| 1143 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1144 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1145 | }; |
| 1146 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1147 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1148 | // from the innermost to the outermost. |
| 1149 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1150 | public: |
| 1151 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1152 | : current_(block.GetLoopInformation()) {} |
| 1153 | |
| 1154 | bool Done() const { return current_ == nullptr; } |
| 1155 | |
| 1156 | void Advance() { |
| 1157 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1158 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | HLoopInformation* Current() const { |
| 1162 | DCHECK(!Done()); |
| 1163 | return current_; |
| 1164 | } |
| 1165 | |
| 1166 | private: |
| 1167 | HLoopInformation* current_; |
| 1168 | |
| 1169 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1170 | }; |
| 1171 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1172 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1173 | M(Above, Condition) \ |
| 1174 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1175 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1176 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1177 | M(ArrayGet, Instruction) \ |
| 1178 | M(ArrayLength, Instruction) \ |
| 1179 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1180 | M(Below, Condition) \ |
| 1181 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1182 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1183 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1184 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1185 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1186 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1187 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1188 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1189 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1190 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1191 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1192 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1193 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1194 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1195 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1196 | M(Exit, Instruction) \ |
| 1197 | M(FloatConstant, Constant) \ |
| 1198 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1199 | M(GreaterThan, Condition) \ |
| 1200 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1201 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1202 | M(InstanceFieldGet, Instruction) \ |
| 1203 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1204 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1205 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1206 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1207 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1208 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1209 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1210 | M(LessThan, Condition) \ |
| 1211 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1212 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1213 | M(LoadException, Instruction) \ |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame^] | 1214 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1215 | M(LoadString, Instruction) \ |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame^] | 1216 | M(Local, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1217 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1218 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1219 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1220 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1221 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1222 | M(Neg, UnaryOperation) \ |
| 1223 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1224 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1225 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1226 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1227 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1228 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1229 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1230 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1231 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1232 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1233 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1234 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1235 | M(Return, Instruction) \ |
| 1236 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1237 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1238 | M(Shl, BinaryOperation) \ |
| 1239 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1240 | M(StaticFieldGet, Instruction) \ |
| 1241 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1242 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1243 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1244 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1245 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1246 | M(Select, Instruction) \ |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame^] | 1247 | M(StoreLocal, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1248 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1249 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1250 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1251 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1252 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1253 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1254 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1255 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1256 | /* |
| 1257 | * Instructions, shared across several (not all) architectures. |
| 1258 | */ |
| 1259 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1260 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1261 | #else |
| 1262 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1263 | M(BitwiseNegatedRight, Instruction) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1264 | M(MultiplyAccumulate, Instruction) |
| 1265 | #endif |
| 1266 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1267 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1268 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1269 | #else |
| 1270 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1271 | M(ArmDexCacheArraysBase, Instruction) |
| 1272 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1273 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1274 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1275 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1276 | #else |
| 1277 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1278 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1279 | M(Arm64IntermediateAddress, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1280 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1281 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1282 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1283 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1284 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1285 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1286 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1287 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1288 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1289 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1290 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1291 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1292 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1293 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1294 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1295 | |
| 1296 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1297 | |
| 1298 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1299 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1300 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1301 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1302 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1303 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1304 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1305 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1306 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1307 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1308 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1309 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1310 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1311 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1312 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1313 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1314 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1315 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1316 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1317 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1318 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1319 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1320 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1321 | #undef FORWARD_DECLARATION |
| 1322 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1323 | #define DECLARE_INSTRUCTION(type) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1324 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1325 | const char* DebugName() const OVERRIDE { return #type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1326 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1327 | return other->Is##type(); \ |
| 1328 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1329 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1330 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1331 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1332 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1333 | const H##type* As##type() const { return this; } \ |
| 1334 | H##type* As##type() { return this; } |
| 1335 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1336 | template <typename T> class HUseList; |
| 1337 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1338 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1339 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1340 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1341 | HUseListNode* GetPrevious() const { return prev_; } |
| 1342 | HUseListNode* GetNext() const { return next_; } |
| 1343 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1344 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1345 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1346 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1347 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1348 | HUseListNode(T user, size_t index) |
| 1349 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1350 | |
| 1351 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1352 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1353 | HUseListNode<T>* prev_; |
| 1354 | HUseListNode<T>* next_; |
| 1355 | |
| 1356 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1357 | |
| 1358 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1359 | }; |
| 1360 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1361 | template <typename T> |
| 1362 | class HUseList : public ValueObject { |
| 1363 | public: |
| 1364 | HUseList() : first_(nullptr) {} |
| 1365 | |
| 1366 | void Clear() { |
| 1367 | first_ = nullptr; |
| 1368 | } |
| 1369 | |
| 1370 | // Adds a new entry at the beginning of the use list and returns |
| 1371 | // the newly created node. |
| 1372 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1373 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1374 | if (IsEmpty()) { |
| 1375 | first_ = new_node; |
| 1376 | } else { |
| 1377 | first_->prev_ = new_node; |
| 1378 | new_node->next_ = first_; |
| 1379 | first_ = new_node; |
| 1380 | } |
| 1381 | return new_node; |
| 1382 | } |
| 1383 | |
| 1384 | HUseListNode<T>* GetFirst() const { |
| 1385 | return first_; |
| 1386 | } |
| 1387 | |
| 1388 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1389 | DCHECK(node != nullptr); |
| 1390 | DCHECK(Contains(node)); |
| 1391 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1392 | if (node->prev_ != nullptr) { |
| 1393 | node->prev_->next_ = node->next_; |
| 1394 | } |
| 1395 | if (node->next_ != nullptr) { |
| 1396 | node->next_->prev_ = node->prev_; |
| 1397 | } |
| 1398 | if (node == first_) { |
| 1399 | first_ = node->next_; |
| 1400 | } |
| 1401 | } |
| 1402 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1403 | bool Contains(const HUseListNode<T>* node) const { |
| 1404 | if (node == nullptr) { |
| 1405 | return false; |
| 1406 | } |
| 1407 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1408 | if (current == node) { |
| 1409 | return true; |
| 1410 | } |
| 1411 | } |
| 1412 | return false; |
| 1413 | } |
| 1414 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1415 | bool IsEmpty() const { |
| 1416 | return first_ == nullptr; |
| 1417 | } |
| 1418 | |
| 1419 | bool HasOnlyOneUse() const { |
| 1420 | return first_ != nullptr && first_->next_ == nullptr; |
| 1421 | } |
| 1422 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1423 | size_t SizeSlow() const { |
| 1424 | size_t count = 0; |
| 1425 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1426 | ++count; |
| 1427 | } |
| 1428 | return count; |
| 1429 | } |
| 1430 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1431 | private: |
| 1432 | HUseListNode<T>* first_; |
| 1433 | }; |
| 1434 | |
| 1435 | template<typename T> |
| 1436 | class HUseIterator : public ValueObject { |
| 1437 | public: |
| 1438 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1439 | |
| 1440 | bool Done() const { return current_ == nullptr; } |
| 1441 | |
| 1442 | void Advance() { |
| 1443 | DCHECK(!Done()); |
| 1444 | current_ = current_->GetNext(); |
| 1445 | } |
| 1446 | |
| 1447 | HUseListNode<T>* Current() const { |
| 1448 | DCHECK(!Done()); |
| 1449 | return current_; |
| 1450 | } |
| 1451 | |
| 1452 | private: |
| 1453 | HUseListNode<T>* current_; |
| 1454 | |
| 1455 | friend class HValue; |
| 1456 | }; |
| 1457 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1458 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1459 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1460 | // by the used instructions. |
| 1461 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1462 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1463 | public: |
| 1464 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1465 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1466 | |
| 1467 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1468 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1469 | DCHECK(instruction_ != nullptr); |
| 1470 | DCHECK(use_node_ != nullptr); |
| 1471 | DCHECK(old_record.use_node_ == nullptr); |
| 1472 | } |
| 1473 | |
| 1474 | HInstruction* GetInstruction() const { return instruction_; } |
| 1475 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1476 | |
| 1477 | private: |
| 1478 | // Instruction used by the user. |
| 1479 | HInstruction* instruction_; |
| 1480 | |
| 1481 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1482 | HUseListNode<T>* use_node_; |
| 1483 | }; |
| 1484 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1485 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1486 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1487 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1488 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1489 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1490 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1491 | * modify the value of a reference field read [although it may modify the |
| 1492 | * reference fetch prior to reading the field, which is represented by its own |
| 1493 | * write/read dependence]). The analysis makes conservative points-to |
| 1494 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1495 | * the same, and any reference read depends on any reference read without |
| 1496 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1497 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1498 | * The internal representation uses 38-bit and is described in the table below. |
| 1499 | * The first line indicates the side effect, and for field/array accesses the |
| 1500 | * second line indicates the type of the access (in the order of the |
| 1501 | * Primitive::Type enum). |
| 1502 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1503 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1504 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1505 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1506 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1507 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1508 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1509 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1510 | * |
| 1511 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1512 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1513 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1514 | class SideEffects : public ValueObject { |
| 1515 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1516 | SideEffects() : flags_(0) {} |
| 1517 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1518 | static SideEffects None() { |
| 1519 | return SideEffects(0); |
| 1520 | } |
| 1521 | |
| 1522 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1523 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1524 | } |
| 1525 | |
| 1526 | static SideEffects AllChanges() { |
| 1527 | return SideEffects(kAllChangeBits); |
| 1528 | } |
| 1529 | |
| 1530 | static SideEffects AllDependencies() { |
| 1531 | return SideEffects(kAllDependOnBits); |
| 1532 | } |
| 1533 | |
| 1534 | static SideEffects AllExceptGCDependency() { |
| 1535 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1536 | } |
| 1537 | |
| 1538 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1539 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1540 | } |
| 1541 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1542 | static SideEffects AllWrites() { |
| 1543 | return SideEffects(kAllWrites); |
| 1544 | } |
| 1545 | |
| 1546 | static SideEffects AllReads() { |
| 1547 | return SideEffects(kAllReads); |
| 1548 | } |
| 1549 | |
| 1550 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1551 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1552 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1553 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1554 | } |
| 1555 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1556 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1557 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1558 | } |
| 1559 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1560 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1561 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1562 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1563 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1567 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1568 | } |
| 1569 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1570 | static SideEffects CanTriggerGC() { |
| 1571 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1572 | } |
| 1573 | |
| 1574 | static SideEffects DependsOnGC() { |
| 1575 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1576 | } |
| 1577 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1578 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1579 | SideEffects Union(SideEffects other) const { |
| 1580 | return SideEffects(flags_ | other.flags_); |
| 1581 | } |
| 1582 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1583 | SideEffects Exclusion(SideEffects other) const { |
| 1584 | return SideEffects(flags_ & ~other.flags_); |
| 1585 | } |
| 1586 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1587 | void Add(SideEffects other) { |
| 1588 | flags_ |= other.flags_; |
| 1589 | } |
| 1590 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1591 | bool Includes(SideEffects other) const { |
| 1592 | return (other.flags_ & flags_) == other.flags_; |
| 1593 | } |
| 1594 | |
| 1595 | bool HasSideEffects() const { |
| 1596 | return (flags_ & kAllChangeBits); |
| 1597 | } |
| 1598 | |
| 1599 | bool HasDependencies() const { |
| 1600 | return (flags_ & kAllDependOnBits); |
| 1601 | } |
| 1602 | |
| 1603 | // Returns true if there are no side effects or dependencies. |
| 1604 | bool DoesNothing() const { |
| 1605 | return flags_ == 0; |
| 1606 | } |
| 1607 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1608 | // Returns true if something is written. |
| 1609 | bool DoesAnyWrite() const { |
| 1610 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1611 | } |
| 1612 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1613 | // Returns true if something is read. |
| 1614 | bool DoesAnyRead() const { |
| 1615 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1616 | } |
| 1617 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1618 | // Returns true if potentially everything is written and read |
| 1619 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1620 | bool DoesAllReadWrite() const { |
| 1621 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1622 | } |
| 1623 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1624 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1625 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1628 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1629 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1630 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1631 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1635 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1636 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1637 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1638 | for (int s = kLastBit; s >= 0; s--) { |
| 1639 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1640 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1641 | // This is a bit for the GC side effect. |
| 1642 | if (current_bit_is_set) { |
| 1643 | flags += "GC"; |
| 1644 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1645 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1646 | } else { |
| 1647 | // This is a bit for the array/field analysis. |
| 1648 | // The underscore character stands for the 'can trigger GC' bit. |
| 1649 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1650 | if (current_bit_is_set) { |
| 1651 | flags += kDebug[s]; |
| 1652 | } |
| 1653 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1654 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1655 | flags += "|"; |
| 1656 | } |
| 1657 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1658 | } |
| 1659 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1660 | } |
| 1661 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1662 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1663 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1664 | private: |
| 1665 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1666 | |
| 1667 | static constexpr int kFieldWriteOffset = 0; |
| 1668 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1669 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1670 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1671 | |
| 1672 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1673 | |
| 1674 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1675 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1676 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1677 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1678 | |
| 1679 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1680 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1681 | |
| 1682 | // Aliases. |
| 1683 | |
| 1684 | static_assert(kChangeBits == kDependOnBits, |
| 1685 | "the 'change' bits should match the 'depend on' bits."); |
| 1686 | |
| 1687 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1688 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1689 | static constexpr uint64_t kAllWrites = |
| 1690 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1691 | static constexpr uint64_t kAllReads = |
| 1692 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1693 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1694 | // Work around the fact that HIR aliases I/F and J/D. |
| 1695 | // TODO: remove this interceptor once HIR types are clean |
| 1696 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1697 | switch (type) { |
| 1698 | case Primitive::kPrimInt: |
| 1699 | case Primitive::kPrimFloat: |
| 1700 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1701 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1702 | case Primitive::kPrimLong: |
| 1703 | case Primitive::kPrimDouble: |
| 1704 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1705 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1706 | default: |
| 1707 | return TypeFlag(type, offset); |
| 1708 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1709 | } |
| 1710 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1711 | // Translates type to bit flag. |
| 1712 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1713 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1714 | const uint64_t one = 1; |
| 1715 | const int shift = type; // 0-based consecutive enum |
| 1716 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1717 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1718 | return one << (type + offset); |
| 1719 | } |
| 1720 | |
| 1721 | // Private constructor on direct flags value. |
| 1722 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1723 | |
| 1724 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1725 | }; |
| 1726 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1727 | // 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] | 1728 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1729 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1730 | HEnvironment(ArenaAllocator* arena, |
| 1731 | size_t number_of_vregs, |
| 1732 | const DexFile& dex_file, |
| 1733 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1734 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1735 | InvokeType invoke_type, |
| 1736 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1737 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1738 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1739 | parent_(nullptr), |
| 1740 | dex_file_(dex_file), |
| 1741 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1742 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1743 | invoke_type_(invoke_type), |
| 1744 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1745 | } |
| 1746 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1747 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1748 | : HEnvironment(arena, |
| 1749 | to_copy.Size(), |
| 1750 | to_copy.GetDexFile(), |
| 1751 | to_copy.GetMethodIdx(), |
| 1752 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1753 | to_copy.GetInvokeType(), |
| 1754 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1755 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1756 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1757 | if (parent_ != nullptr) { |
| 1758 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1759 | } else { |
| 1760 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1761 | parent_->CopyFrom(parent); |
| 1762 | if (parent->GetParent() != nullptr) { |
| 1763 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1764 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1765 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1768 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1769 | void CopyFrom(HEnvironment* environment); |
| 1770 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1771 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1772 | // input to the loop phi instead. This is for inserting instructions that |
| 1773 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1774 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1775 | |
| 1776 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1777 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1781 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1784 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1785 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1786 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1787 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1788 | HEnvironment* GetParent() const { return parent_; } |
| 1789 | |
| 1790 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1791 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1795 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | uint32_t GetDexPc() const { |
| 1799 | return dex_pc_; |
| 1800 | } |
| 1801 | |
| 1802 | uint32_t GetMethodIdx() const { |
| 1803 | return method_idx_; |
| 1804 | } |
| 1805 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1806 | InvokeType GetInvokeType() const { |
| 1807 | return invoke_type_; |
| 1808 | } |
| 1809 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1810 | const DexFile& GetDexFile() const { |
| 1811 | return dex_file_; |
| 1812 | } |
| 1813 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1814 | HInstruction* GetHolder() const { |
| 1815 | return holder_; |
| 1816 | } |
| 1817 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1818 | |
| 1819 | bool IsFromInlinedInvoke() const { |
| 1820 | return GetParent() != nullptr; |
| 1821 | } |
| 1822 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1823 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1824 | // Record instructions' use entries of this environment for constant-time removal. |
| 1825 | // It should only be called by HInstruction when a new environment use is added. |
| 1826 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1827 | DCHECK(env_use->GetUser() == this); |
| 1828 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1829 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1830 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1831 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1832 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1833 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1834 | HEnvironment* parent_; |
| 1835 | const DexFile& dex_file_; |
| 1836 | const uint32_t method_idx_; |
| 1837 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1838 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1839 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1840 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1841 | HInstruction* const holder_; |
| 1842 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1843 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1844 | |
| 1845 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1846 | }; |
| 1847 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1848 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1849 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1850 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1851 | : previous_(nullptr), |
| 1852 | next_(nullptr), |
| 1853 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1854 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1855 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1856 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1857 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1858 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1859 | locations_(nullptr), |
| 1860 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1861 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1862 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1863 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1864 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1865 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1866 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1867 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1868 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1869 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1870 | enum InstructionKind { |
| 1871 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1872 | }; |
| 1873 | #undef DECLARE_KIND |
| 1874 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1875 | HInstruction* GetNext() const { return next_; } |
| 1876 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1877 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1878 | HInstruction* GetNextDisregardingMoves() const; |
| 1879 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1880 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1881 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1882 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1883 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1884 | bool IsInBlock() const { return block_ != nullptr; } |
| 1885 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1886 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1887 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1888 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1889 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1890 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1891 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1892 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1893 | |
| 1894 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1895 | virtual const char* DebugName() const = 0; |
| 1896 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1897 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1898 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1899 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1900 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1901 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1902 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1903 | |
| 1904 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1905 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1906 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1907 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1908 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1909 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1910 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1911 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1912 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1913 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1914 | // Does not apply for all instructions, but having this at top level greatly |
| 1915 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1916 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1917 | virtual bool CanBeNull() const { |
| 1918 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1919 | return true; |
| 1920 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1921 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1922 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1923 | return false; |
| 1924 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1925 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1926 | virtual bool IsActualObject() const { |
| 1927 | return GetType() == Primitive::kPrimNot; |
| 1928 | } |
| 1929 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1930 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1931 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1932 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1933 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1934 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
| 1935 | GetPackedFlag<kFlagReferenceTypeIsExact>());; |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1936 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1937 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1938 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1939 | DCHECK(user != nullptr); |
| 1940 | HUseListNode<HInstruction*>* use = |
| 1941 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1942 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1945 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1946 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1947 | HUseListNode<HEnvironment*>* env_use = |
| 1948 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1949 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1950 | } |
| 1951 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1952 | void RemoveAsUserOfInput(size_t input) { |
| 1953 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1954 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1955 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1956 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1957 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1958 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1959 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1960 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1961 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1962 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1963 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1964 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1965 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1966 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1967 | // Does this instruction strictly dominate `other_instruction`? |
| 1968 | // Returns false if this instruction and `other_instruction` are the same. |
| 1969 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1970 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1971 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1972 | int GetId() const { return id_; } |
| 1973 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1974 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1975 | int GetSsaIndex() const { return ssa_index_; } |
| 1976 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1977 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1978 | |
| 1979 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1980 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1981 | // Set the `environment_` field. Raw because this method does not |
| 1982 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1983 | void SetRawEnvironment(HEnvironment* environment) { |
| 1984 | DCHECK(environment_ == nullptr); |
| 1985 | DCHECK_EQ(environment->GetHolder(), this); |
| 1986 | environment_ = environment; |
| 1987 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1988 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1989 | void RemoveEnvironment(); |
| 1990 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1991 | // Set the environment of this instruction, copying it from `environment`. While |
| 1992 | // copying, the uses lists are being updated. |
| 1993 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1994 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1995 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1996 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1997 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1998 | if (environment->GetParent() != nullptr) { |
| 1999 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2000 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2001 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2002 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2003 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2004 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2005 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2006 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2007 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2008 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2009 | if (environment->GetParent() != nullptr) { |
| 2010 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2011 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2014 | // Returns the number of entries in the environment. Typically, that is the |
| 2015 | // number of dex registers in a method. It could be more in case of inlining. |
| 2016 | size_t EnvironmentSize() const; |
| 2017 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2018 | LocationSummary* GetLocations() const { return locations_; } |
| 2019 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2020 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2021 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2022 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2023 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2024 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2025 | // uses of this instruction by `other` are *not* updated. |
| 2026 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2027 | ReplaceWith(other); |
| 2028 | other->ReplaceInput(this, use_index); |
| 2029 | } |
| 2030 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2031 | // Move `this` instruction before `cursor`. |
| 2032 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2033 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2034 | // Move `this` before its first user and out of any loops. If there is no |
| 2035 | // out-of-loop user that dominates all other users, move the instruction |
| 2036 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2037 | // |
| 2038 | // This can be used only on non-throwing instructions with no side effects that |
| 2039 | // have at least one use but no environment uses. |
| 2040 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2041 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2042 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2043 | bool Is##type() const; \ |
| 2044 | const H##type* As##type() const; \ |
| 2045 | H##type* As##type(); |
| 2046 | |
| 2047 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2048 | #undef INSTRUCTION_TYPE_CHECK |
| 2049 | |
| 2050 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2051 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2052 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2053 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2054 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2055 | #undef INSTRUCTION_TYPE_CHECK |
| 2056 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2057 | // Returns whether the instruction can be moved within the graph. |
| 2058 | virtual bool CanBeMoved() const { return false; } |
| 2059 | |
| 2060 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2061 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2062 | return false; |
| 2063 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2064 | |
| 2065 | // Returns whether any data encoded in the two instructions is equal. |
| 2066 | // This method does not look at the inputs. Both instructions must be |
| 2067 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2068 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2069 | return false; |
| 2070 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2071 | |
| 2072 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2073 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2074 | // 2) Their inputs are identical. |
| 2075 | bool Equals(HInstruction* other) const; |
| 2076 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2077 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2078 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2079 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2080 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2081 | InstructionKind GetKind() const PURE; |
| 2082 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2083 | |
| 2084 | virtual size_t ComputeHashCode() const { |
| 2085 | size_t result = GetKind(); |
| 2086 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2087 | result = (result * 31) + InputAt(i)->GetId(); |
| 2088 | } |
| 2089 | return result; |
| 2090 | } |
| 2091 | |
| 2092 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2093 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2094 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2095 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2096 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2097 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2098 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2099 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2100 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2101 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2102 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2103 | |
| 2104 | // Returns whether the code generation of the instruction will require to have access |
| 2105 | // to the current method. Such instructions are: |
| 2106 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2107 | // to walk the stack and have the current method stored at a specific stack address. |
| 2108 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2109 | // fields of the current method. |
| 2110 | bool NeedsCurrentMethod() const { |
| 2111 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2112 | } |
| 2113 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2114 | // Returns whether the code generation of the instruction will require to have access |
| 2115 | // to the dex cache of the current method's declaring class via the current method. |
| 2116 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2117 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2118 | // Does this instruction have any use in an environment before |
| 2119 | // control flow hits 'other'? |
| 2120 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2121 | |
| 2122 | // Remove all references to environment uses of this instruction. |
| 2123 | // The caller must ensure that this is safe to do. |
| 2124 | void RemoveEnvironmentUsers(); |
| 2125 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2126 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2127 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2128 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2129 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2130 | // If set, the machine code for this instruction is assumed to be generated by |
| 2131 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2132 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2133 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2134 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2135 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2136 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2137 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2138 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 2139 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2140 | uint32_t GetPackedFields() const { |
| 2141 | return packed_fields_; |
| 2142 | } |
| 2143 | |
| 2144 | template <size_t flag> |
| 2145 | bool GetPackedFlag() const { |
| 2146 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2147 | } |
| 2148 | |
| 2149 | template <size_t flag> |
| 2150 | void SetPackedFlag(bool value = true) { |
| 2151 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2152 | } |
| 2153 | |
| 2154 | template <typename BitFieldType> |
| 2155 | typename BitFieldType::value_type GetPackedField() const { |
| 2156 | return BitFieldType::Decode(packed_fields_); |
| 2157 | } |
| 2158 | |
| 2159 | template <typename BitFieldType> |
| 2160 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2161 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2162 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2163 | } |
| 2164 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2165 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2166 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2167 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2168 | HInstruction* previous_; |
| 2169 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2170 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2171 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2172 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2173 | // An instruction gets an id when it is added to the graph. |
| 2174 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2175 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2176 | int id_; |
| 2177 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2178 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2179 | int ssa_index_; |
| 2180 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2181 | // Packed fields. |
| 2182 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2183 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2184 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2185 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2186 | |
| 2187 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2188 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2189 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2190 | // The environment associated with this instruction. Not null if the instruction |
| 2191 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2192 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2193 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2194 | // Set by the code generator. |
| 2195 | LocationSummary* locations_; |
| 2196 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2197 | // Set by the liveness analysis. |
| 2198 | LiveInterval* live_interval_; |
| 2199 | |
| 2200 | // Set by the liveness analysis, this is the position in a linear |
| 2201 | // order of blocks where this instruction's live interval start. |
| 2202 | size_t lifetime_position_; |
| 2203 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2204 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2205 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2206 | // The reference handle part of the reference type info. |
| 2207 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2208 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2209 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2210 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2211 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2212 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2213 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2214 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2215 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2216 | |
| 2217 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2218 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2219 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2220 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2221 | class HInputIterator : public ValueObject { |
| 2222 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2223 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2224 | |
| 2225 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2226 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2227 | void Advance() { index_++; } |
| 2228 | |
| 2229 | private: |
| 2230 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2231 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2232 | |
| 2233 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2234 | }; |
| 2235 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2236 | class HInstructionIterator : public ValueObject { |
| 2237 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2238 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2239 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2240 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2243 | bool Done() const { return instruction_ == nullptr; } |
| 2244 | HInstruction* Current() const { return instruction_; } |
| 2245 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2246 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2247 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | private: |
| 2251 | HInstruction* instruction_; |
| 2252 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2253 | |
| 2254 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2255 | }; |
| 2256 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2257 | class HBackwardInstructionIterator : public ValueObject { |
| 2258 | public: |
| 2259 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2260 | : instruction_(instructions.last_instruction_) { |
| 2261 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2262 | } |
| 2263 | |
| 2264 | bool Done() const { return instruction_ == nullptr; } |
| 2265 | HInstruction* Current() const { return instruction_; } |
| 2266 | void Advance() { |
| 2267 | instruction_ = next_; |
| 2268 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2269 | } |
| 2270 | |
| 2271 | private: |
| 2272 | HInstruction* instruction_; |
| 2273 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2274 | |
| 2275 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2276 | }; |
| 2277 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2278 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2279 | class HTemplateInstruction: public HInstruction { |
| 2280 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2281 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2282 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2283 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2284 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2285 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2286 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2287 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2288 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2289 | DCHECK_LT(i, N); |
| 2290 | return inputs_[i]; |
| 2291 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2292 | |
| 2293 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2294 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2295 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2298 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2299 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2300 | |
| 2301 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2302 | }; |
| 2303 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2304 | // HTemplateInstruction specialization for N=0. |
| 2305 | template<> |
| 2306 | class HTemplateInstruction<0>: public HInstruction { |
| 2307 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2308 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2309 | : HInstruction(side_effects, dex_pc) {} |
| 2310 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2311 | virtual ~HTemplateInstruction() {} |
| 2312 | |
| 2313 | size_t InputCount() const OVERRIDE { return 0; } |
| 2314 | |
| 2315 | protected: |
| 2316 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2317 | LOG(FATAL) << "Unreachable"; |
| 2318 | UNREACHABLE(); |
| 2319 | } |
| 2320 | |
| 2321 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2322 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2323 | LOG(FATAL) << "Unreachable"; |
| 2324 | UNREACHABLE(); |
| 2325 | } |
| 2326 | |
| 2327 | private: |
| 2328 | friend class SsaBuilder; |
| 2329 | }; |
| 2330 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2331 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2332 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2333 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2334 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2335 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2336 | this->template SetPackedField<TypeField>(type); |
| 2337 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2338 | virtual ~HExpression() {} |
| 2339 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2340 | Primitive::Type GetType() const OVERRIDE { |
| 2341 | return TypeField::Decode(this->GetPackedFields()); |
| 2342 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2343 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2344 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2345 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2346 | static constexpr size_t kFieldTypeSize = |
| 2347 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2348 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2349 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2350 | "Too many packed fields."); |
| 2351 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2352 | }; |
| 2353 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2354 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2355 | // instruction that branches to the exit block. |
| 2356 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2357 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2358 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2359 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2360 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2361 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2362 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2363 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2364 | |
| 2365 | private: |
| 2366 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2367 | }; |
| 2368 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2369 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2370 | // instruction that branches to the exit block. |
| 2371 | class HReturn : public HTemplateInstruction<1> { |
| 2372 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2373 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2374 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2375 | SetRawInputAt(0, value); |
| 2376 | } |
| 2377 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2378 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2379 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2380 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2381 | |
| 2382 | private: |
| 2383 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2384 | }; |
| 2385 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2386 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2387 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2388 | // exit block. |
| 2389 | class HExit : public HTemplateInstruction<0> { |
| 2390 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2391 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2392 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2393 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2394 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2395 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2396 | |
| 2397 | private: |
| 2398 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2399 | }; |
| 2400 | |
| 2401 | // Jumps from one block to another. |
| 2402 | class HGoto : public HTemplateInstruction<0> { |
| 2403 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2404 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2405 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2406 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2407 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2408 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2409 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2412 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2413 | |
| 2414 | private: |
| 2415 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2416 | }; |
| 2417 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2418 | class HConstant : public HExpression<0> { |
| 2419 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2420 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2421 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2422 | |
| 2423 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2424 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2425 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2426 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2427 | // Is this constant 0 in the arithmetic sense? |
| 2428 | virtual bool IsArithmeticZero() const { return false; } |
| 2429 | // Is this constant a 0-bit pattern? |
| 2430 | virtual bool IsZeroBitPattern() const { return false; } |
| 2431 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2432 | virtual bool IsOne() const { return false; } |
| 2433 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2434 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2435 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2436 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2437 | |
| 2438 | private: |
| 2439 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2440 | }; |
| 2441 | |
| 2442 | class HNullConstant : public HConstant { |
| 2443 | public: |
| 2444 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2445 | return true; |
| 2446 | } |
| 2447 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2448 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2449 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2450 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2451 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2452 | // The null constant representation is a 0-bit pattern. |
| 2453 | virtual bool IsZeroBitPattern() const { return true; } |
| 2454 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2455 | DECLARE_INSTRUCTION(NullConstant); |
| 2456 | |
| 2457 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2458 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2459 | |
| 2460 | friend class HGraph; |
| 2461 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2462 | }; |
| 2463 | |
| 2464 | // Constants of the type int. Those can be from Dex instructions, or |
| 2465 | // synthesized (for example with the if-eqz instruction). |
| 2466 | class HIntConstant : public HConstant { |
| 2467 | public: |
| 2468 | int32_t GetValue() const { return value_; } |
| 2469 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2470 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2471 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2472 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2473 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2474 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2475 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2476 | return other->AsIntConstant()->value_ == value_; |
| 2477 | } |
| 2478 | |
| 2479 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2480 | |
| 2481 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2482 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2483 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2484 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2485 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2486 | // Integer constants are used to encode Boolean values as well, |
| 2487 | // where 1 means true and 0 means false. |
| 2488 | bool IsTrue() const { return GetValue() == 1; } |
| 2489 | bool IsFalse() const { return GetValue() == 0; } |
| 2490 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2491 | DECLARE_INSTRUCTION(IntConstant); |
| 2492 | |
| 2493 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2494 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2495 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2496 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2497 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2498 | |
| 2499 | const int32_t value_; |
| 2500 | |
| 2501 | friend class HGraph; |
| 2502 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2503 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2504 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2505 | }; |
| 2506 | |
| 2507 | class HLongConstant : public HConstant { |
| 2508 | public: |
| 2509 | int64_t GetValue() const { return value_; } |
| 2510 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2511 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2512 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2513 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2514 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2515 | return other->AsLongConstant()->value_ == value_; |
| 2516 | } |
| 2517 | |
| 2518 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2519 | |
| 2520 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2521 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2522 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2523 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2524 | |
| 2525 | DECLARE_INSTRUCTION(LongConstant); |
| 2526 | |
| 2527 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2528 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2529 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2530 | |
| 2531 | const int64_t value_; |
| 2532 | |
| 2533 | friend class HGraph; |
| 2534 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2535 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2536 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2537 | class HFloatConstant : public HConstant { |
| 2538 | public: |
| 2539 | float GetValue() const { return value_; } |
| 2540 | |
| 2541 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2542 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2543 | } |
| 2544 | |
| 2545 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2546 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2547 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2548 | } |
| 2549 | |
| 2550 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2551 | |
| 2552 | bool IsMinusOne() const OVERRIDE { |
| 2553 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2554 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2555 | bool IsArithmeticZero() const OVERRIDE { |
| 2556 | return std::fpclassify(value_) == FP_ZERO; |
| 2557 | } |
| 2558 | bool IsArithmeticPositiveZero() const { |
| 2559 | return IsArithmeticZero() && !std::signbit(value_); |
| 2560 | } |
| 2561 | bool IsArithmeticNegativeZero() const { |
| 2562 | return IsArithmeticZero() && std::signbit(value_); |
| 2563 | } |
| 2564 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2565 | 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] | 2566 | } |
| 2567 | bool IsOne() const OVERRIDE { |
| 2568 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2569 | } |
| 2570 | bool IsNaN() const { |
| 2571 | return std::isnan(value_); |
| 2572 | } |
| 2573 | |
| 2574 | DECLARE_INSTRUCTION(FloatConstant); |
| 2575 | |
| 2576 | private: |
| 2577 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2578 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2579 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2580 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2581 | |
| 2582 | const float value_; |
| 2583 | |
| 2584 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2585 | friend class SsaBuilder; |
| 2586 | friend class HGraph; |
| 2587 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2588 | }; |
| 2589 | |
| 2590 | class HDoubleConstant : public HConstant { |
| 2591 | public: |
| 2592 | double GetValue() const { return value_; } |
| 2593 | |
| 2594 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2595 | |
| 2596 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2597 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2598 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2599 | } |
| 2600 | |
| 2601 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2602 | |
| 2603 | bool IsMinusOne() const OVERRIDE { |
| 2604 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2605 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2606 | bool IsArithmeticZero() const OVERRIDE { |
| 2607 | return std::fpclassify(value_) == FP_ZERO; |
| 2608 | } |
| 2609 | bool IsArithmeticPositiveZero() const { |
| 2610 | return IsArithmeticZero() && !std::signbit(value_); |
| 2611 | } |
| 2612 | bool IsArithmeticNegativeZero() const { |
| 2613 | return IsArithmeticZero() && std::signbit(value_); |
| 2614 | } |
| 2615 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2616 | 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] | 2617 | } |
| 2618 | bool IsOne() const OVERRIDE { |
| 2619 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2620 | } |
| 2621 | bool IsNaN() const { |
| 2622 | return std::isnan(value_); |
| 2623 | } |
| 2624 | |
| 2625 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2626 | |
| 2627 | private: |
| 2628 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2629 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2630 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2631 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2632 | |
| 2633 | const double value_; |
| 2634 | |
| 2635 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2636 | friend class SsaBuilder; |
| 2637 | friend class HGraph; |
| 2638 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2639 | }; |
| 2640 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2641 | // Conditional branch. A block ending with an HIf instruction must have |
| 2642 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2643 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2644 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2645 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2646 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2647 | SetRawInputAt(0, input); |
| 2648 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2649 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2650 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2651 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2652 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2653 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2657 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2660 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2661 | |
| 2662 | private: |
| 2663 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2664 | }; |
| 2665 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2666 | |
| 2667 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2668 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2669 | // non-exceptional control flow. |
| 2670 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2671 | // higher indices in no particular order. |
| 2672 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2673 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2674 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2675 | kEntry, |
| 2676 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2677 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2678 | }; |
| 2679 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2680 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2681 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2682 | SetPackedField<BoundaryKindField>(kind); |
| 2683 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2684 | |
| 2685 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2686 | |
| 2687 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2688 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2689 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2690 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2691 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2692 | } |
| 2693 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2694 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2695 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2696 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2697 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2698 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | // If not present already, adds `handler` to its block's list of exception |
| 2702 | // handlers. |
| 2703 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2704 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2705 | GetBlock()->AddSuccessor(handler); |
| 2706 | } |
| 2707 | } |
| 2708 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2709 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2710 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2711 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2712 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2713 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2714 | DECLARE_INSTRUCTION(TryBoundary); |
| 2715 | |
| 2716 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2717 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2718 | static constexpr size_t kFieldBoundaryKindSize = |
| 2719 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2720 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2721 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2722 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2723 | "Too many packed fields."); |
| 2724 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2725 | |
| 2726 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2727 | }; |
| 2728 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2729 | // Deoptimize to interpreter, upon checking a condition. |
| 2730 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2731 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2732 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2733 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2734 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2735 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2736 | SetRawInputAt(0, cond); |
| 2737 | } |
| 2738 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2739 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2740 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2741 | return true; |
| 2742 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2743 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2744 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2745 | |
| 2746 | DECLARE_INSTRUCTION(Deoptimize); |
| 2747 | |
| 2748 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2749 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2750 | }; |
| 2751 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2752 | // Represents the ArtMethod that was passed as a first argument to |
| 2753 | // the method. It is used by instructions that depend on it, like |
| 2754 | // instructions that work with the dex cache. |
| 2755 | class HCurrentMethod : public HExpression<0> { |
| 2756 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2757 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2758 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2759 | |
| 2760 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2761 | |
| 2762 | private: |
| 2763 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2764 | }; |
| 2765 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2766 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2767 | // of a class. |
| 2768 | class HClassTableGet : public HExpression<1> { |
| 2769 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2770 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2771 | kVTable, |
| 2772 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2773 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2774 | }; |
| 2775 | HClassTableGet(HInstruction* cls, |
| 2776 | Primitive::Type type, |
| 2777 | TableKind kind, |
| 2778 | size_t index, |
| 2779 | uint32_t dex_pc) |
| 2780 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2781 | index_(index) { |
| 2782 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2783 | SetRawInputAt(0, cls); |
| 2784 | } |
| 2785 | |
| 2786 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2787 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2788 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2789 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2790 | } |
| 2791 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2792 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2793 | size_t GetIndex() const { return index_; } |
| 2794 | |
| 2795 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2796 | |
| 2797 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2798 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2799 | static constexpr size_t kFieldTableKindSize = |
| 2800 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2801 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2802 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2803 | "Too many packed fields."); |
| 2804 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2805 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2806 | // The index of the ArtMethod in the table. |
| 2807 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2808 | |
| 2809 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2810 | }; |
| 2811 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2812 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2813 | // have one successor for each entry in the switch table, and the final successor |
| 2814 | // will be the block containing the next Dex opcode. |
| 2815 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2816 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2817 | HPackedSwitch(int32_t start_value, |
| 2818 | uint32_t num_entries, |
| 2819 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2820 | uint32_t dex_pc = kNoDexPc) |
| 2821 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2822 | start_value_(start_value), |
| 2823 | num_entries_(num_entries) { |
| 2824 | SetRawInputAt(0, input); |
| 2825 | } |
| 2826 | |
| 2827 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2828 | |
| 2829 | int32_t GetStartValue() const { return start_value_; } |
| 2830 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2831 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2832 | |
| 2833 | HBasicBlock* GetDefaultBlock() const { |
| 2834 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2835 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2836 | } |
| 2837 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2838 | |
| 2839 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2840 | const int32_t start_value_; |
| 2841 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2842 | |
| 2843 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2844 | }; |
| 2845 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2846 | class HUnaryOperation : public HExpression<1> { |
| 2847 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2848 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2849 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2850 | SetRawInputAt(0, input); |
| 2851 | } |
| 2852 | |
| 2853 | HInstruction* GetInput() const { return InputAt(0); } |
| 2854 | Primitive::Type GetResultType() const { return GetType(); } |
| 2855 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2856 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2857 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2858 | return true; |
| 2859 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2860 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2861 | // Try to statically evaluate `this` and return a HConstant |
| 2862 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2863 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2864 | HConstant* TryStaticEvaluation() const; |
| 2865 | |
| 2866 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2867 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2868 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2869 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 2870 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2871 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2872 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2873 | |
| 2874 | private: |
| 2875 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2876 | }; |
| 2877 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2878 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2879 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2880 | HBinaryOperation(Primitive::Type result_type, |
| 2881 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2882 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2883 | SideEffects side_effects = SideEffects::None(), |
| 2884 | uint32_t dex_pc = kNoDexPc) |
| 2885 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2886 | SetRawInputAt(0, left); |
| 2887 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2890 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2891 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2892 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2893 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2894 | virtual bool IsCommutative() const { return false; } |
| 2895 | |
| 2896 | // Put constant on the right. |
| 2897 | // Returns whether order is changed. |
| 2898 | bool OrderInputsWithConstantOnTheRight() { |
| 2899 | HInstruction* left = InputAt(0); |
| 2900 | HInstruction* right = InputAt(1); |
| 2901 | if (left->IsConstant() && !right->IsConstant()) { |
| 2902 | ReplaceInput(right, 0); |
| 2903 | ReplaceInput(left, 1); |
| 2904 | return true; |
| 2905 | } |
| 2906 | return false; |
| 2907 | } |
| 2908 | |
| 2909 | // Order inputs by instruction id, but favor constant on the right side. |
| 2910 | // This helps GVN for commutative ops. |
| 2911 | void OrderInputs() { |
| 2912 | DCHECK(IsCommutative()); |
| 2913 | HInstruction* left = InputAt(0); |
| 2914 | HInstruction* right = InputAt(1); |
| 2915 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2916 | return; |
| 2917 | } |
| 2918 | if (OrderInputsWithConstantOnTheRight()) { |
| 2919 | return; |
| 2920 | } |
| 2921 | // Order according to instruction id. |
| 2922 | if (left->GetId() > right->GetId()) { |
| 2923 | ReplaceInput(right, 0); |
| 2924 | ReplaceInput(left, 1); |
| 2925 | } |
| 2926 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2927 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2928 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2929 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2930 | return true; |
| 2931 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2932 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2933 | // Try to statically evaluate `this` and return a HConstant |
| 2934 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2935 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2936 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2937 | |
| 2938 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2939 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2940 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 2941 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 2942 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2943 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2944 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2945 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2946 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2947 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 2948 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 2949 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2950 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2951 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 2952 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2953 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2954 | // 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] | 2955 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2956 | HConstant* GetConstantRight() const; |
| 2957 | |
| 2958 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2959 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2960 | HInstruction* GetLeastConstantLeft() const; |
| 2961 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2962 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2963 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2964 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2965 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2966 | }; |
| 2967 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2968 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2969 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2970 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2971 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2972 | kGtBias, // return 1 for NaN comparisons |
| 2973 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2974 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2975 | }; |
| 2976 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2977 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 2978 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2979 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2980 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2981 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2982 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 2983 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 2984 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2985 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2986 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2987 | // `instruction`, and disregard moves in between. |
| 2988 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2989 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2990 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2991 | |
| 2992 | virtual IfCondition GetCondition() const = 0; |
| 2993 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2994 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2995 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2996 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 2997 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 2998 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2999 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3000 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3001 | |
| 3002 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3003 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3004 | } |
| 3005 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3006 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3007 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3008 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3009 | if (if_cond == kCondNE) { |
| 3010 | return true; |
| 3011 | } else if (if_cond == kCondEQ) { |
| 3012 | return false; |
| 3013 | } |
| 3014 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3018 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3019 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3020 | if (if_cond == kCondEQ) { |
| 3021 | return true; |
| 3022 | } else if (if_cond == kCondNE) { |
| 3023 | return false; |
| 3024 | } |
| 3025 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3026 | } |
| 3027 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3028 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3029 | // Needed if we merge a HCompare into a HCondition. |
| 3030 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3031 | static constexpr size_t kFieldComparisonBiasSize = |
| 3032 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3033 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3034 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3035 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3036 | using ComparisonBiasField = |
| 3037 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3038 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3039 | template <typename T> |
| 3040 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3041 | |
| 3042 | template <typename T> |
| 3043 | int32_t CompareFP(T x, T y) const { |
| 3044 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3045 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3046 | // Handle the bias. |
| 3047 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3048 | } |
| 3049 | |
| 3050 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3051 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3052 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3053 | } |
| 3054 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3055 | private: |
| 3056 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3057 | }; |
| 3058 | |
| 3059 | // Instruction to check if two inputs are equal to each other. |
| 3060 | class HEqual : public HCondition { |
| 3061 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3062 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3063 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3064 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3065 | bool IsCommutative() const OVERRIDE { return true; } |
| 3066 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3067 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3068 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3069 | return MakeConstantCondition(true, GetDexPc()); |
| 3070 | } |
| 3071 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3072 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3073 | } |
| 3074 | // In the following Evaluate methods, a HCompare instruction has |
| 3075 | // been merged into this HEqual instruction; evaluate it as |
| 3076 | // `Compare(x, y) == 0`. |
| 3077 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3078 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3079 | GetDexPc()); |
| 3080 | } |
| 3081 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3082 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3083 | } |
| 3084 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3085 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3086 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3087 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3088 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3089 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3090 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3091 | return kCondEQ; |
| 3092 | } |
| 3093 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3094 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3095 | return kCondNE; |
| 3096 | } |
| 3097 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3098 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3099 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 3100 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3101 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3102 | }; |
| 3103 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3104 | class HNotEqual : public HCondition { |
| 3105 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3106 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3107 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3108 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3109 | bool IsCommutative() const OVERRIDE { return true; } |
| 3110 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3111 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3112 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3113 | return MakeConstantCondition(false, GetDexPc()); |
| 3114 | } |
| 3115 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3116 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3117 | } |
| 3118 | // In the following Evaluate methods, a HCompare instruction has |
| 3119 | // been merged into this HNotEqual instruction; evaluate it as |
| 3120 | // `Compare(x, y) != 0`. |
| 3121 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3122 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3123 | } |
| 3124 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3125 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3126 | } |
| 3127 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3128 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3129 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3130 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3131 | DECLARE_INSTRUCTION(NotEqual); |
| 3132 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3133 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3134 | return kCondNE; |
| 3135 | } |
| 3136 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3137 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3138 | return kCondEQ; |
| 3139 | } |
| 3140 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3141 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3142 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 3143 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3144 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3145 | }; |
| 3146 | |
| 3147 | class HLessThan : public HCondition { |
| 3148 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3149 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3150 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3151 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3152 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3153 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3154 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3155 | // In the following Evaluate methods, a HCompare instruction has |
| 3156 | // been merged into this HLessThan instruction; evaluate it as |
| 3157 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3158 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3159 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3160 | } |
| 3161 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3162 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3163 | } |
| 3164 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3165 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3166 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3167 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3168 | DECLARE_INSTRUCTION(LessThan); |
| 3169 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3170 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3171 | return kCondLT; |
| 3172 | } |
| 3173 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3174 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3175 | return kCondGE; |
| 3176 | } |
| 3177 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3178 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3179 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 3180 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3181 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3182 | }; |
| 3183 | |
| 3184 | class HLessThanOrEqual : public HCondition { |
| 3185 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3186 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3187 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3188 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3189 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3190 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3191 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3192 | // In the following Evaluate methods, a HCompare instruction has |
| 3193 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3194 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3195 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3196 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3197 | } |
| 3198 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3199 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3200 | } |
| 3201 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3202 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3203 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3204 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3205 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3206 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3207 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3208 | return kCondLE; |
| 3209 | } |
| 3210 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3211 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3212 | return kCondGT; |
| 3213 | } |
| 3214 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3215 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3216 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 3217 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3218 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3219 | }; |
| 3220 | |
| 3221 | class HGreaterThan : public HCondition { |
| 3222 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3223 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3224 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3225 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3226 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3227 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3228 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3229 | // In the following Evaluate methods, a HCompare instruction has |
| 3230 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3231 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3232 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3233 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3234 | } |
| 3235 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3236 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3237 | } |
| 3238 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3239 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3240 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3241 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3242 | DECLARE_INSTRUCTION(GreaterThan); |
| 3243 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3244 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3245 | return kCondGT; |
| 3246 | } |
| 3247 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3248 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3249 | return kCondLE; |
| 3250 | } |
| 3251 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3252 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3253 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3254 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3255 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3256 | }; |
| 3257 | |
| 3258 | class HGreaterThanOrEqual : public HCondition { |
| 3259 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3260 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3261 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3262 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3263 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3264 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3265 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3266 | // In the following Evaluate methods, a HCompare instruction has |
| 3267 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3268 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3269 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3270 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3271 | } |
| 3272 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3273 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3274 | } |
| 3275 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3276 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3277 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3278 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3279 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3280 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3281 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3282 | return kCondGE; |
| 3283 | } |
| 3284 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3285 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3286 | return kCondLT; |
| 3287 | } |
| 3288 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3289 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3290 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3291 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3292 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3293 | }; |
| 3294 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3295 | class HBelow : public HCondition { |
| 3296 | public: |
| 3297 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3298 | : HCondition(first, second, dex_pc) {} |
| 3299 | |
| 3300 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3301 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3302 | } |
| 3303 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3304 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3305 | } |
| 3306 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3307 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3308 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3309 | UNREACHABLE(); |
| 3310 | } |
| 3311 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3312 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3313 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3314 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | DECLARE_INSTRUCTION(Below); |
| 3318 | |
| 3319 | IfCondition GetCondition() const OVERRIDE { |
| 3320 | return kCondB; |
| 3321 | } |
| 3322 | |
| 3323 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3324 | return kCondAE; |
| 3325 | } |
| 3326 | |
| 3327 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3328 | template <typename T> bool Compute(T x, T y) const { |
| 3329 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3330 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3331 | |
| 3332 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3333 | }; |
| 3334 | |
| 3335 | class HBelowOrEqual : public HCondition { |
| 3336 | public: |
| 3337 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3338 | : HCondition(first, second, dex_pc) {} |
| 3339 | |
| 3340 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3341 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3342 | } |
| 3343 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3344 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3345 | } |
| 3346 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3347 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3348 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3349 | UNREACHABLE(); |
| 3350 | } |
| 3351 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3352 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3353 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3354 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3358 | |
| 3359 | IfCondition GetCondition() const OVERRIDE { |
| 3360 | return kCondBE; |
| 3361 | } |
| 3362 | |
| 3363 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3364 | return kCondA; |
| 3365 | } |
| 3366 | |
| 3367 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3368 | template <typename T> bool Compute(T x, T y) const { |
| 3369 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3370 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3371 | |
| 3372 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3373 | }; |
| 3374 | |
| 3375 | class HAbove : public HCondition { |
| 3376 | public: |
| 3377 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3378 | : HCondition(first, second, dex_pc) {} |
| 3379 | |
| 3380 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3381 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3382 | } |
| 3383 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3384 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3385 | } |
| 3386 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3387 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3388 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3389 | UNREACHABLE(); |
| 3390 | } |
| 3391 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3392 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3393 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3394 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | DECLARE_INSTRUCTION(Above); |
| 3398 | |
| 3399 | IfCondition GetCondition() const OVERRIDE { |
| 3400 | return kCondA; |
| 3401 | } |
| 3402 | |
| 3403 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3404 | return kCondBE; |
| 3405 | } |
| 3406 | |
| 3407 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3408 | template <typename T> bool Compute(T x, T y) const { |
| 3409 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3410 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3411 | |
| 3412 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3413 | }; |
| 3414 | |
| 3415 | class HAboveOrEqual : public HCondition { |
| 3416 | public: |
| 3417 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3418 | : HCondition(first, second, dex_pc) {} |
| 3419 | |
| 3420 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3421 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3422 | } |
| 3423 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3424 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3425 | } |
| 3426 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3427 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3428 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3429 | UNREACHABLE(); |
| 3430 | } |
| 3431 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3432 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3433 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3434 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3438 | |
| 3439 | IfCondition GetCondition() const OVERRIDE { |
| 3440 | return kCondAE; |
| 3441 | } |
| 3442 | |
| 3443 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3444 | return kCondB; |
| 3445 | } |
| 3446 | |
| 3447 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3448 | template <typename T> bool Compute(T x, T y) const { |
| 3449 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3450 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3451 | |
| 3452 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3453 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3454 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3455 | // Instruction to check how two inputs compare to each other. |
| 3456 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3457 | class HCompare : public HBinaryOperation { |
| 3458 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3459 | // Note that `comparison_type` is the type of comparison performed |
| 3460 | // between the comparison's inputs, not the type of the instantiated |
| 3461 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3462 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3463 | HInstruction* first, |
| 3464 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3465 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3466 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3467 | : HBinaryOperation(Primitive::kPrimInt, |
| 3468 | first, |
| 3469 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3470 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3471 | dex_pc) { |
| 3472 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3473 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3474 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3475 | } |
| 3476 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3477 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3478 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3479 | |
| 3480 | template <typename T> |
| 3481 | int32_t ComputeFP(T x, T y) const { |
| 3482 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3483 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3484 | // Handle the bias. |
| 3485 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3486 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3487 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3488 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3489 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3490 | // reach this code path when processing a freshly built HIR |
| 3491 | // graph. However HCompare integer instructions can be synthesized |
| 3492 | // by the instruction simplifier to implement IntegerCompare and |
| 3493 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3494 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3495 | } |
| 3496 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3497 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3498 | } |
| 3499 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3500 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3501 | } |
| 3502 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3503 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3504 | } |
| 3505 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3506 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3507 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3508 | } |
| 3509 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3510 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3511 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3512 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3513 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3514 | bool IsGtBias() const { |
| 3515 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3516 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3517 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3518 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3519 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3520 | // Comparisons do not require a runtime call in any back end. |
| 3521 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3522 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3523 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3524 | DECLARE_INSTRUCTION(Compare); |
| 3525 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3526 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3527 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3528 | static constexpr size_t kFieldComparisonBiasSize = |
| 3529 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3530 | static constexpr size_t kNumberOfComparePackedBits = |
| 3531 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3532 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3533 | using ComparisonBiasField = |
| 3534 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3535 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3536 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3537 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3538 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3539 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3540 | } |
| 3541 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3542 | private: |
| 3543 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3544 | }; |
| 3545 | |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame^] | 3546 | // A local in the graph. Corresponds to a Dex register. |
| 3547 | class HLocal : public HTemplateInstruction<0> { |
| 3548 | public: |
| 3549 | explicit HLocal(uint16_t reg_number) |
| 3550 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
| 3551 | |
| 3552 | DECLARE_INSTRUCTION(Local); |
| 3553 | |
| 3554 | uint16_t GetRegNumber() const { return reg_number_; } |
| 3555 | |
| 3556 | private: |
| 3557 | // The Dex register number. |
| 3558 | const uint16_t reg_number_; |
| 3559 | |
| 3560 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3561 | }; |
| 3562 | |
| 3563 | // Load a given local. The local is an input of this instruction. |
| 3564 | class HLoadLocal : public HExpression<1> { |
| 3565 | public: |
| 3566 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3567 | : HExpression(type, SideEffects::None(), dex_pc) { |
| 3568 | SetRawInputAt(0, local); |
| 3569 | } |
| 3570 | |
| 3571 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3572 | |
| 3573 | DECLARE_INSTRUCTION(LoadLocal); |
| 3574 | |
| 3575 | private: |
| 3576 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3577 | }; |
| 3578 | |
| 3579 | // Store a value in a given local. This instruction has two inputs: the value |
| 3580 | // and the local. |
| 3581 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3582 | public: |
| 3583 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3584 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 3585 | SetRawInputAt(0, local); |
| 3586 | SetRawInputAt(1, value); |
| 3587 | } |
| 3588 | |
| 3589 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3590 | |
| 3591 | DECLARE_INSTRUCTION(StoreLocal); |
| 3592 | |
| 3593 | private: |
| 3594 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3595 | }; |
| 3596 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3597 | class HNewInstance : public HExpression<2> { |
| 3598 | public: |
| 3599 | HNewInstance(HInstruction* cls, |
| 3600 | HCurrentMethod* current_method, |
| 3601 | uint32_t dex_pc, |
| 3602 | uint16_t type_index, |
| 3603 | const DexFile& dex_file, |
| 3604 | bool can_throw, |
| 3605 | bool finalizable, |
| 3606 | QuickEntrypointEnum entrypoint) |
| 3607 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3608 | type_index_(type_index), |
| 3609 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3610 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3611 | SetPackedFlag<kFlagCanThrow>(can_throw); |
| 3612 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3613 | SetRawInputAt(0, cls); |
| 3614 | SetRawInputAt(1, current_method); |
| 3615 | } |
| 3616 | |
| 3617 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3618 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3619 | |
| 3620 | // Calls runtime so needs an environment. |
| 3621 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3622 | |
| 3623 | // It may throw when called on type that's not instantiable/accessible. |
| 3624 | // It can throw OOME. |
| 3625 | // TODO: distinguish between the two cases so we can for example allow allocation elimination. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3626 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>() || true; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3627 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3628 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3629 | |
| 3630 | bool CanBeNull() const OVERRIDE { return false; } |
| 3631 | |
| 3632 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3633 | |
| 3634 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3635 | entrypoint_ = entrypoint; |
| 3636 | } |
| 3637 | |
| 3638 | bool IsStringAlloc() const; |
| 3639 | |
| 3640 | DECLARE_INSTRUCTION(NewInstance); |
| 3641 | |
| 3642 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3643 | static constexpr size_t kFlagCanThrow = kNumberOfExpressionPackedBits; |
| 3644 | static constexpr size_t kFlagFinalizable = kFlagCanThrow + 1; |
| 3645 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3646 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3647 | "Too many packed fields."); |
| 3648 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3649 | const uint16_t type_index_; |
| 3650 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3651 | QuickEntrypointEnum entrypoint_; |
| 3652 | |
| 3653 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3654 | }; |
| 3655 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3656 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3657 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3658 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3659 | #include "intrinsics_list.h" |
| 3660 | kNone, |
| 3661 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3662 | #undef INTRINSICS_LIST |
| 3663 | #undef OPTIMIZING_INTRINSICS |
| 3664 | }; |
| 3665 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3666 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3667 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3668 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3669 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3670 | }; |
| 3671 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3672 | enum IntrinsicSideEffects { |
| 3673 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3674 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3675 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3676 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3677 | }; |
| 3678 | |
| 3679 | enum IntrinsicExceptions { |
| 3680 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3681 | kCanThrow // Intrinsic may throw exceptions. |
| 3682 | }; |
| 3683 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3684 | class HInvoke : public HInstruction { |
| 3685 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3686 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3687 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3688 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3689 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3690 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3691 | SetRawInputAt(index, argument); |
| 3692 | } |
| 3693 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3694 | // Return the number of arguments. This number can be lower than |
| 3695 | // the number of inputs returned by InputCount(), as some invoke |
| 3696 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3697 | // inputs at the end of their list of inputs. |
| 3698 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3699 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3700 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3701 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3702 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3703 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3704 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3705 | InvokeType GetOriginalInvokeType() const { |
| 3706 | return GetPackedField<OriginalInvokeTypeField>(); |
| 3707 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3708 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3709 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3710 | return intrinsic_; |
| 3711 | } |
| 3712 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3713 | void SetIntrinsic(Intrinsics intrinsic, |
| 3714 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3715 | IntrinsicSideEffects side_effects, |
| 3716 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3717 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3718 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3719 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3720 | } |
| 3721 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3722 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3723 | |
| 3724 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3725 | |
| 3726 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3727 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3728 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3729 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3730 | uint32_t* GetIntrinsicOptimizations() { |
| 3731 | return &intrinsic_optimizations_; |
| 3732 | } |
| 3733 | |
| 3734 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3735 | return &intrinsic_optimizations_; |
| 3736 | } |
| 3737 | |
| 3738 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3739 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3740 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3741 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3742 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3743 | static constexpr size_t kFieldOriginalInvokeType = kNumberOfGenericPackedBits; |
| 3744 | static constexpr size_t kFieldOriginalInvokeTypeSize = |
| 3745 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3746 | static constexpr size_t kFieldReturnType = |
| 3747 | kFieldOriginalInvokeType + kFieldOriginalInvokeTypeSize; |
| 3748 | static constexpr size_t kFieldReturnTypeSize = |
| 3749 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3750 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3751 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3752 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3753 | using OriginalInvokeTypeField = |
| 3754 | BitField<InvokeType, kFieldOriginalInvokeType, kFieldOriginalInvokeTypeSize>; |
| 3755 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3756 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3757 | HInvoke(ArenaAllocator* arena, |
| 3758 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3759 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3760 | Primitive::Type return_type, |
| 3761 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3762 | uint32_t dex_method_index, |
| 3763 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3764 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3765 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3766 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3767 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3768 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3769 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3770 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3771 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3772 | SetPackedField<ReturnTypeField>(return_type); |
| 3773 | SetPackedField<OriginalInvokeTypeField>(original_invoke_type); |
| 3774 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3775 | } |
| 3776 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3777 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3778 | return inputs_[index]; |
| 3779 | } |
| 3780 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3781 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3782 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3783 | } |
| 3784 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3785 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3786 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3787 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3788 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3789 | const uint32_t dex_method_index_; |
| 3790 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3791 | |
| 3792 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3793 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3794 | |
| 3795 | private: |
| 3796 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3797 | }; |
| 3798 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3799 | class HInvokeUnresolved : public HInvoke { |
| 3800 | public: |
| 3801 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3802 | uint32_t number_of_arguments, |
| 3803 | Primitive::Type return_type, |
| 3804 | uint32_t dex_pc, |
| 3805 | uint32_t dex_method_index, |
| 3806 | InvokeType invoke_type) |
| 3807 | : HInvoke(arena, |
| 3808 | number_of_arguments, |
| 3809 | 0u /* number_of_other_inputs */, |
| 3810 | return_type, |
| 3811 | dex_pc, |
| 3812 | dex_method_index, |
| 3813 | invoke_type) { |
| 3814 | } |
| 3815 | |
| 3816 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3817 | |
| 3818 | private: |
| 3819 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3820 | }; |
| 3821 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3822 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3823 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3824 | // Requirements of this method call regarding the class |
| 3825 | // initialization (clinit) check of its declaring class. |
| 3826 | enum class ClinitCheckRequirement { |
| 3827 | kNone, // Class already initialized. |
| 3828 | kExplicit, // Static call having explicit clinit check as last input. |
| 3829 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3830 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3831 | }; |
| 3832 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3833 | // Determines how to load the target ArtMethod*. |
| 3834 | enum class MethodLoadKind { |
| 3835 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3836 | kStringInit, |
| 3837 | |
| 3838 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3839 | kRecursive, |
| 3840 | |
| 3841 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3842 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3843 | kDirectAddress, |
| 3844 | |
| 3845 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3846 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3847 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3848 | // the image relocatable or not. |
| 3849 | kDirectAddressWithFixup, |
| 3850 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3851 | // 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] | 3852 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3853 | // may cause class initialization (the entry may point to a resolution method), |
| 3854 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3855 | kDexCachePcRelative, |
| 3856 | |
| 3857 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3858 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3859 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3860 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3861 | kDexCacheViaMethod, |
| 3862 | }; |
| 3863 | |
| 3864 | // Determines the location of the code pointer. |
| 3865 | enum class CodePtrLocation { |
| 3866 | // Recursive call, use local PC-relative call instruction. |
| 3867 | kCallSelf, |
| 3868 | |
| 3869 | // Use PC-relative call instruction patched at link time. |
| 3870 | // Used for calls within an oat file, boot->boot or app->app. |
| 3871 | kCallPCRelative, |
| 3872 | |
| 3873 | // Call to a known target address, embed the direct address in code. |
| 3874 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3875 | kCallDirect, |
| 3876 | |
| 3877 | // Call to a target address that will be known at link time, embed the direct |
| 3878 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3879 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3880 | // the image relocatable or not. |
| 3881 | kCallDirectWithFixup, |
| 3882 | |
| 3883 | // Use code pointer from the ArtMethod*. |
| 3884 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3885 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3886 | kCallArtMethod, |
| 3887 | }; |
| 3888 | |
| 3889 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3890 | MethodLoadKind method_load_kind; |
| 3891 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3892 | // The method load data holds |
| 3893 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3894 | // Note that there are multiple string init methods, each having its own offset. |
| 3895 | // - the method address for kDirectAddress |
| 3896 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3897 | uint64_t method_load_data; |
| 3898 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3899 | }; |
| 3900 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3901 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3902 | uint32_t number_of_arguments, |
| 3903 | Primitive::Type return_type, |
| 3904 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3905 | uint32_t method_index, |
| 3906 | MethodReference target_method, |
| 3907 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3908 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3909 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3910 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3911 | : HInvoke(arena, |
| 3912 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3913 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3914 | // potentially one other if the clinit check is explicit, and potentially |
| 3915 | // one other if the method is a string factory. |
| 3916 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame^] | 3917 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3918 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3919 | return_type, |
| 3920 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3921 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3922 | original_invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3923 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3924 | dispatch_info_(dispatch_info) { |
| 3925 | SetPackedField<OptimizedInvokeTypeField>(optimized_invoke_type); |
| 3926 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 3927 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3928 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3929 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3930 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3931 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3932 | |
| 3933 | // Using the current method is the default and once we find a better |
| 3934 | // method load kind, we should not go back to using the current method. |
| 3935 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3936 | |
| 3937 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3938 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3939 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3940 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3941 | dispatch_info_ = dispatch_info; |
| 3942 | } |
| 3943 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3944 | void AddSpecialInput(HInstruction* input) { |
| 3945 | // We allow only one special input. |
| 3946 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3947 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3948 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3949 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3950 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3951 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3952 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3953 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3954 | // TODO: for intrinsics we can generate implicit null checks. |
| 3955 | return false; |
| 3956 | } |
| 3957 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3958 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3959 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3960 | } |
| 3961 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3962 | // Get the index of the special input, if any. |
| 3963 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3964 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 3965 | // method pointer; otherwise there may be one platform-specific special input, |
| 3966 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3967 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 3968 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3969 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3970 | InvokeType GetOptimizedInvokeType() const { |
| 3971 | return GetPackedField<OptimizedInvokeTypeField>(); |
| 3972 | } |
| 3973 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3974 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3975 | SetPackedField<OptimizedInvokeTypeField>(invoke_type); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3976 | } |
| 3977 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3978 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3979 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3980 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3981 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3982 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3983 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3984 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3985 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3986 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3987 | bool HasCurrentMethodInput() const { |
| 3988 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3989 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3990 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3991 | return true; |
| 3992 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3993 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3994 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3995 | return false; |
| 3996 | } |
| 3997 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3998 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3999 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4000 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4001 | |
| 4002 | int32_t GetStringInitOffset() const { |
| 4003 | DCHECK(IsStringInit()); |
| 4004 | return dispatch_info_.method_load_data; |
| 4005 | } |
| 4006 | |
| 4007 | uint64_t GetMethodAddress() const { |
| 4008 | DCHECK(HasMethodAddress()); |
| 4009 | return dispatch_info_.method_load_data; |
| 4010 | } |
| 4011 | |
| 4012 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4013 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4014 | return dispatch_info_.method_load_data; |
| 4015 | } |
| 4016 | |
| 4017 | uint64_t GetDirectCodePtr() const { |
| 4018 | DCHECK(HasDirectCodePtr()); |
| 4019 | return dispatch_info_.direct_code_ptr; |
| 4020 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4021 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4022 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4023 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4024 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4025 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4026 | // Is this instruction a call to a static method? |
| 4027 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4028 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4029 | } |
| 4030 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4031 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4032 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4033 | // instruction; only relevant for static calls with explicit clinit check. |
| 4034 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4035 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 4036 | size_t last_input_index = InputCount() - 1; |
| 4037 | HInstruction* last_input = InputAt(last_input_index); |
| 4038 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4039 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4040 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4041 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4042 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4043 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4044 | } |
| 4045 | |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame^] | 4046 | HInstruction* GetAndRemoveThisArgumentOfStringInit() { |
| 4047 | DCHECK(IsStringInit()); |
| 4048 | size_t index = InputCount() - 1; |
| 4049 | HInstruction* input = InputAt(index); |
| 4050 | RemoveAsUserOfInput(index); |
| 4051 | inputs_.pop_back(); |
| 4052 | return input; |
| 4053 | } |
| 4054 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4055 | // 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] | 4056 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4057 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4058 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | // Is this a call to a static method whose declaring class has an |
| 4062 | // implicit intialization check requirement? |
| 4063 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4064 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4065 | } |
| 4066 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4067 | // Does this method load kind need the current method as an input? |
| 4068 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4069 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4070 | } |
| 4071 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4072 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4073 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4074 | protected: |
| 4075 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 4076 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 4077 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 4078 | HInstruction* input = input_record.GetInstruction(); |
| 4079 | // `input` is the last input of a static invoke marked as having |
| 4080 | // an explicit clinit check. It must either be: |
| 4081 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4082 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4083 | DCHECK(input != nullptr); |
| 4084 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 4085 | } |
| 4086 | return input_record; |
| 4087 | } |
| 4088 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4089 | void InsertInputAt(size_t index, HInstruction* input); |
| 4090 | void RemoveInputAt(size_t index); |
| 4091 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4092 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4093 | static constexpr size_t kFieldOptimizedInvokeType = kNumberOfInvokePackedBits; |
| 4094 | static constexpr size_t kFieldOptimizedInvokeTypeSize = |
| 4095 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4096 | static constexpr size_t kFieldClinitCheckRequirement = |
| 4097 | kFieldOptimizedInvokeType + kFieldOptimizedInvokeTypeSize; |
| 4098 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4099 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4100 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4101 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4102 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4103 | "Too many packed fields."); |
| 4104 | using OptimizedInvokeTypeField = |
| 4105 | BitField<InvokeType, kFieldOptimizedInvokeType, kFieldOptimizedInvokeTypeSize>; |
| 4106 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4107 | kFieldClinitCheckRequirement, |
| 4108 | kFieldClinitCheckRequirementSize>; |
| 4109 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4110 | // The target method may refer to different dex file or method index than the original |
| 4111 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 4112 | // in derived class to increase visibility. |
| 4113 | MethodReference target_method_; |
| 4114 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4115 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4116 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4117 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4118 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4119 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4120 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4121 | class HInvokeVirtual : public HInvoke { |
| 4122 | public: |
| 4123 | HInvokeVirtual(ArenaAllocator* arena, |
| 4124 | uint32_t number_of_arguments, |
| 4125 | Primitive::Type return_type, |
| 4126 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4127 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4128 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4129 | : 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] | 4130 | vtable_index_(vtable_index) {} |
| 4131 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4132 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4133 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4134 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4135 | } |
| 4136 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4137 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4138 | |
| 4139 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4140 | |
| 4141 | private: |
| 4142 | const uint32_t vtable_index_; |
| 4143 | |
| 4144 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4145 | }; |
| 4146 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4147 | class HInvokeInterface : public HInvoke { |
| 4148 | public: |
| 4149 | HInvokeInterface(ArenaAllocator* arena, |
| 4150 | uint32_t number_of_arguments, |
| 4151 | Primitive::Type return_type, |
| 4152 | uint32_t dex_pc, |
| 4153 | uint32_t dex_method_index, |
| 4154 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4155 | : 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] | 4156 | imt_index_(imt_index) {} |
| 4157 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4158 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4159 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4160 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4161 | } |
| 4162 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4163 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4164 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4165 | |
| 4166 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4167 | |
| 4168 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4169 | const uint32_t imt_index_; |
| 4170 | |
| 4171 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4172 | }; |
| 4173 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4174 | class HNeg : public HUnaryOperation { |
| 4175 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4176 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4177 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4178 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4179 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4180 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4181 | template <typename T> T Compute(T x) const { return -x; } |
| 4182 | |
| 4183 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4184 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4185 | } |
| 4186 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4187 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4188 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4189 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4190 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4191 | } |
| 4192 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4193 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4194 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4195 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4196 | DECLARE_INSTRUCTION(Neg); |
| 4197 | |
| 4198 | private: |
| 4199 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4200 | }; |
| 4201 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4202 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4203 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4204 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4205 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4206 | uint32_t dex_pc, |
| 4207 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4208 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4209 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4210 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4211 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4212 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4213 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4214 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4215 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4216 | } |
| 4217 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4218 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4219 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4220 | |
| 4221 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4222 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4223 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4224 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4225 | bool CanThrow() const OVERRIDE { return true; } |
| 4226 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4227 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4228 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4229 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4230 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4231 | DECLARE_INSTRUCTION(NewArray); |
| 4232 | |
| 4233 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4234 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4235 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4236 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4237 | |
| 4238 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4239 | }; |
| 4240 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4241 | class HAdd : public HBinaryOperation { |
| 4242 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4243 | HAdd(Primitive::Type result_type, |
| 4244 | HInstruction* left, |
| 4245 | HInstruction* right, |
| 4246 | uint32_t dex_pc = kNoDexPc) |
| 4247 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4248 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4249 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4250 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4251 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 4252 | |
| 4253 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4254 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4255 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4256 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4257 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4258 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4259 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4260 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4261 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4262 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4263 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4264 | } |
| 4265 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4266 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4267 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4268 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4269 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4270 | DECLARE_INSTRUCTION(Add); |
| 4271 | |
| 4272 | private: |
| 4273 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4274 | }; |
| 4275 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4276 | class HSub : public HBinaryOperation { |
| 4277 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4278 | HSub(Primitive::Type result_type, |
| 4279 | HInstruction* left, |
| 4280 | HInstruction* right, |
| 4281 | uint32_t dex_pc = kNoDexPc) |
| 4282 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4283 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4284 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 4285 | |
| 4286 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4287 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4288 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4289 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4290 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4291 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4292 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4293 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4294 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4295 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4296 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4297 | } |
| 4298 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4299 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4300 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4301 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4302 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4303 | DECLARE_INSTRUCTION(Sub); |
| 4304 | |
| 4305 | private: |
| 4306 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4307 | }; |
| 4308 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4309 | class HMul : public HBinaryOperation { |
| 4310 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4311 | HMul(Primitive::Type result_type, |
| 4312 | HInstruction* left, |
| 4313 | HInstruction* right, |
| 4314 | uint32_t dex_pc = kNoDexPc) |
| 4315 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4316 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4317 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4318 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4319 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 4320 | |
| 4321 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4322 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4323 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4324 | } |
| 4325 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4326 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4327 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4328 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4329 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4330 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4331 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4332 | } |
| 4333 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4334 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4335 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4336 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4337 | |
| 4338 | DECLARE_INSTRUCTION(Mul); |
| 4339 | |
| 4340 | private: |
| 4341 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4342 | }; |
| 4343 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4344 | class HDiv : public HBinaryOperation { |
| 4345 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4346 | HDiv(Primitive::Type result_type, |
| 4347 | HInstruction* left, |
| 4348 | HInstruction* right, |
| 4349 | uint32_t dex_pc) |
| 4350 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4351 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4352 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4353 | T ComputeIntegral(T x, T y) const { |
| 4354 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4355 | // Our graph structure ensures we never have 0 for `y` during |
| 4356 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4357 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4358 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4359 | return (y == -1) ? -x : x / y; |
| 4360 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4361 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4362 | template <typename T> |
| 4363 | T ComputeFP(T x, T y) const { |
| 4364 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4365 | return x / y; |
| 4366 | } |
| 4367 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4368 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4369 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4370 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4371 | } |
| 4372 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4373 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4374 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4375 | } |
| 4376 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4377 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4378 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4379 | } |
| 4380 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4381 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4382 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4383 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4384 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4385 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4386 | // The generated code can use a runtime call. |
| 4387 | return SideEffects::CanTriggerGC(); |
| 4388 | } |
| 4389 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4390 | DECLARE_INSTRUCTION(Div); |
| 4391 | |
| 4392 | private: |
| 4393 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4394 | }; |
| 4395 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4396 | class HRem : public HBinaryOperation { |
| 4397 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4398 | HRem(Primitive::Type result_type, |
| 4399 | HInstruction* left, |
| 4400 | HInstruction* right, |
| 4401 | uint32_t dex_pc) |
| 4402 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4403 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4404 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4405 | T ComputeIntegral(T x, T y) const { |
| 4406 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4407 | // Our graph structure ensures we never have 0 for `y` during |
| 4408 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4409 | DCHECK_NE(y, 0); |
| 4410 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4411 | return (y == -1) ? 0 : x % y; |
| 4412 | } |
| 4413 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4414 | template <typename T> |
| 4415 | T ComputeFP(T x, T y) const { |
| 4416 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4417 | return std::fmod(x, y); |
| 4418 | } |
| 4419 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4420 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4421 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4422 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4423 | } |
| 4424 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4425 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4426 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4427 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4428 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4429 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4430 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4431 | } |
| 4432 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4433 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4434 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4435 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4436 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4437 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4438 | return SideEffects::CanTriggerGC(); |
| 4439 | } |
| 4440 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4441 | DECLARE_INSTRUCTION(Rem); |
| 4442 | |
| 4443 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4444 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4445 | }; |
| 4446 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4447 | class HDivZeroCheck : public HExpression<1> { |
| 4448 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4449 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4450 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4451 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4452 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4453 | SetRawInputAt(0, value); |
| 4454 | } |
| 4455 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4456 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4457 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4458 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4459 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4460 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4461 | return true; |
| 4462 | } |
| 4463 | |
| 4464 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4465 | bool CanThrow() const OVERRIDE { return true; } |
| 4466 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4467 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4468 | |
| 4469 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4470 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4471 | }; |
| 4472 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4473 | class HShl : public HBinaryOperation { |
| 4474 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4475 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4476 | HInstruction* value, |
| 4477 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4478 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4479 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4480 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4481 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4482 | } |
| 4483 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4484 | template <typename T> |
| 4485 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4486 | return value << (distance & max_shift_distance); |
| 4487 | } |
| 4488 | |
| 4489 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4490 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4491 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4492 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4493 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4494 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4495 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4496 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4497 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4498 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4499 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4500 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4501 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4502 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4503 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4504 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4505 | UNREACHABLE(); |
| 4506 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4507 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4508 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4509 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4510 | UNREACHABLE(); |
| 4511 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4512 | |
| 4513 | DECLARE_INSTRUCTION(Shl); |
| 4514 | |
| 4515 | private: |
| 4516 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4517 | }; |
| 4518 | |
| 4519 | class HShr : public HBinaryOperation { |
| 4520 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4521 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4522 | HInstruction* value, |
| 4523 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4524 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4525 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4526 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4527 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4528 | } |
| 4529 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4530 | template <typename T> |
| 4531 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4532 | return value >> (distance & max_shift_distance); |
| 4533 | } |
| 4534 | |
| 4535 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4536 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4537 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4538 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4539 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4540 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4541 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4542 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4543 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4544 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4545 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4546 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4547 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4548 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4549 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4550 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4551 | UNREACHABLE(); |
| 4552 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4553 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4554 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4555 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4556 | UNREACHABLE(); |
| 4557 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4558 | |
| 4559 | DECLARE_INSTRUCTION(Shr); |
| 4560 | |
| 4561 | private: |
| 4562 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4563 | }; |
| 4564 | |
| 4565 | class HUShr : public HBinaryOperation { |
| 4566 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4567 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4568 | HInstruction* value, |
| 4569 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4570 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4571 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4572 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4573 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4574 | } |
| 4575 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4576 | template <typename T> |
| 4577 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4578 | typedef typename std::make_unsigned<T>::type V; |
| 4579 | V ux = static_cast<V>(value); |
| 4580 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4581 | } |
| 4582 | |
| 4583 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4584 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4585 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4586 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4587 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4588 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4589 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4590 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4591 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4592 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4593 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4594 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4595 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4596 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4597 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4598 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4599 | UNREACHABLE(); |
| 4600 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4601 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4602 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4603 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4604 | UNREACHABLE(); |
| 4605 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4606 | |
| 4607 | DECLARE_INSTRUCTION(UShr); |
| 4608 | |
| 4609 | private: |
| 4610 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4611 | }; |
| 4612 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4613 | class HAnd : public HBinaryOperation { |
| 4614 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4615 | HAnd(Primitive::Type result_type, |
| 4616 | HInstruction* left, |
| 4617 | HInstruction* right, |
| 4618 | uint32_t dex_pc = kNoDexPc) |
| 4619 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4620 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4621 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4622 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4623 | 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] | 4624 | |
| 4625 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4626 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4627 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4628 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4629 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4630 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4631 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4632 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4633 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4634 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4635 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4636 | UNREACHABLE(); |
| 4637 | } |
| 4638 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4639 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4640 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4641 | UNREACHABLE(); |
| 4642 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4643 | |
| 4644 | DECLARE_INSTRUCTION(And); |
| 4645 | |
| 4646 | private: |
| 4647 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4648 | }; |
| 4649 | |
| 4650 | class HOr : public HBinaryOperation { |
| 4651 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4652 | HOr(Primitive::Type result_type, |
| 4653 | HInstruction* left, |
| 4654 | HInstruction* right, |
| 4655 | uint32_t dex_pc = kNoDexPc) |
| 4656 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4657 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4658 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4659 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4660 | 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] | 4661 | |
| 4662 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4663 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4664 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4665 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4666 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4667 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4668 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4669 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4670 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4671 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4672 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4673 | UNREACHABLE(); |
| 4674 | } |
| 4675 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4676 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4677 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4678 | UNREACHABLE(); |
| 4679 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4680 | |
| 4681 | DECLARE_INSTRUCTION(Or); |
| 4682 | |
| 4683 | private: |
| 4684 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4685 | }; |
| 4686 | |
| 4687 | class HXor : public HBinaryOperation { |
| 4688 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4689 | HXor(Primitive::Type result_type, |
| 4690 | HInstruction* left, |
| 4691 | HInstruction* right, |
| 4692 | uint32_t dex_pc = kNoDexPc) |
| 4693 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4694 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4695 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4696 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4697 | 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] | 4698 | |
| 4699 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4700 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4701 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4702 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4703 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4704 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4705 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4706 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4707 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4708 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4709 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4710 | UNREACHABLE(); |
| 4711 | } |
| 4712 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4713 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4714 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4715 | UNREACHABLE(); |
| 4716 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4717 | |
| 4718 | DECLARE_INSTRUCTION(Xor); |
| 4719 | |
| 4720 | private: |
| 4721 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4722 | }; |
| 4723 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4724 | class HRor : public HBinaryOperation { |
| 4725 | public: |
| 4726 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4727 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4728 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4729 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4730 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4731 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4732 | template <typename T> |
| 4733 | T Compute(T value, int32_t distance, int32_t max_shift_value) const { |
| 4734 | typedef typename std::make_unsigned<T>::type V; |
| 4735 | V ux = static_cast<V>(value); |
| 4736 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4737 | return static_cast<T>(ux); |
| 4738 | } else { |
| 4739 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4740 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4741 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4742 | } |
| 4743 | } |
| 4744 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4745 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4746 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4747 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4748 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4749 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4750 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4751 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4752 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4753 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4754 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4755 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4756 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4757 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4758 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4759 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4760 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4761 | UNREACHABLE(); |
| 4762 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4763 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4764 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4765 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4766 | UNREACHABLE(); |
| 4767 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4768 | |
| 4769 | DECLARE_INSTRUCTION(Ror); |
| 4770 | |
| 4771 | private: |
| 4772 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4773 | }; |
| 4774 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4775 | // The value of a parameter in this method. Its location depends on |
| 4776 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4777 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4778 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4779 | HParameterValue(const DexFile& dex_file, |
| 4780 | uint16_t type_index, |
| 4781 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4782 | Primitive::Type parameter_type, |
| 4783 | bool is_this = false) |
| 4784 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4785 | dex_file_(dex_file), |
| 4786 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4787 | index_(index) { |
| 4788 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4789 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4790 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4791 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4792 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4793 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4794 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4795 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4796 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4797 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4798 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4799 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4800 | DECLARE_INSTRUCTION(ParameterValue); |
| 4801 | |
| 4802 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4803 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4804 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4805 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4806 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4807 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4808 | "Too many packed fields."); |
| 4809 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4810 | const DexFile& dex_file_; |
| 4811 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4812 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4813 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4814 | const uint8_t index_; |
| 4815 | |
| 4816 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4817 | }; |
| 4818 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4819 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4820 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4821 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4822 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4823 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4824 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4825 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4826 | return true; |
| 4827 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4828 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4829 | template <typename T> T Compute(T x) const { return ~x; } |
| 4830 | |
| 4831 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4832 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4833 | } |
| 4834 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4835 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4836 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4837 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4838 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4839 | UNREACHABLE(); |
| 4840 | } |
| 4841 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4842 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4843 | UNREACHABLE(); |
| 4844 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4845 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4846 | DECLARE_INSTRUCTION(Not); |
| 4847 | |
| 4848 | private: |
| 4849 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4850 | }; |
| 4851 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4852 | class HBooleanNot : public HUnaryOperation { |
| 4853 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4854 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4855 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4856 | |
| 4857 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4858 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4859 | return true; |
| 4860 | } |
| 4861 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4862 | template <typename T> bool Compute(T x) const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4863 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4864 | return !x; |
| 4865 | } |
| 4866 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4867 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4868 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4869 | } |
| 4870 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4871 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4872 | UNREACHABLE(); |
| 4873 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4874 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4875 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4876 | UNREACHABLE(); |
| 4877 | } |
| 4878 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4879 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4880 | UNREACHABLE(); |
| 4881 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4882 | |
| 4883 | DECLARE_INSTRUCTION(BooleanNot); |
| 4884 | |
| 4885 | private: |
| 4886 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4887 | }; |
| 4888 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4889 | class HTypeConversion : public HExpression<1> { |
| 4890 | public: |
| 4891 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4892 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4893 | : HExpression(result_type, |
| 4894 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4895 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4896 | SetRawInputAt(0, input); |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame^] | 4897 | DCHECK_NE(input->GetType(), result_type); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 4898 | // Invariant: We should never generate a conversion to a Boolean value. |
| 4899 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4900 | } |
| 4901 | |
| 4902 | HInstruction* GetInput() const { return InputAt(0); } |
| 4903 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4904 | Primitive::Type GetResultType() const { return GetType(); } |
| 4905 | |
| 4906 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4907 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4908 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4909 | // Try to statically evaluate the conversion and return a HConstant |
| 4910 | // containing the result. If the input cannot be converted, return nullptr. |
| 4911 | HConstant* TryStaticEvaluation() const; |
| 4912 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4913 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4914 | Primitive::Type result_type) { |
| 4915 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4916 | // in the compilation process we do not know what architecture we will |
| 4917 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4918 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4919 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4920 | return SideEffects::CanTriggerGC(); |
| 4921 | } |
| 4922 | return SideEffects::None(); |
| 4923 | } |
| 4924 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4925 | DECLARE_INSTRUCTION(TypeConversion); |
| 4926 | |
| 4927 | private: |
| 4928 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4929 | }; |
| 4930 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4931 | static constexpr uint32_t kNoRegNumber = -1; |
| 4932 | |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame^] | 4933 | class HPhi : public HInstruction { |
| 4934 | public: |
| 4935 | HPhi(ArenaAllocator* arena, |
| 4936 | uint32_t reg_number, |
| 4937 | size_t number_of_inputs, |
| 4938 | Primitive::Type type, |
| 4939 | uint32_t dex_pc = kNoDexPc) |
| 4940 | : HInstruction(SideEffects::None(), dex_pc), |
| 4941 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
| 4942 | reg_number_(reg_number) { |
| 4943 | SetPackedField<TypeField>(ToPhiType(type)); |
| 4944 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 4945 | // Phis are constructed live and marked dead if conflicting or unused. |
| 4946 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 4947 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 4948 | SetPackedFlag<kFlagIsLive>(true); |
| 4949 | SetPackedFlag<kFlagCanBeNull>(true); |
| 4950 | } |
| 4951 | |
| 4952 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4953 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4954 | switch (type) { |
| 4955 | case Primitive::kPrimBoolean: |
| 4956 | case Primitive::kPrimByte: |
| 4957 | case Primitive::kPrimShort: |
| 4958 | case Primitive::kPrimChar: |
| 4959 | return Primitive::kPrimInt; |
| 4960 | default: |
| 4961 | return type; |
| 4962 | } |
| 4963 | } |
| 4964 | |
| 4965 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4966 | |
| 4967 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
| 4968 | |
| 4969 | void AddInput(HInstruction* input); |
| 4970 | void RemoveInputAt(size_t index); |
| 4971 | |
| 4972 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 4973 | void SetType(Primitive::Type new_type) { |
| 4974 | // Make sure that only valid type changes occur. The following are allowed: |
| 4975 | // (1) int -> float/ref (primitive type propagation), |
| 4976 | // (2) long -> double (primitive type propagation). |
| 4977 | DCHECK(GetType() == new_type || |
| 4978 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 4979 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 4980 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 4981 | SetPackedField<TypeField>(new_type); |
| 4982 | } |
| 4983 | |
| 4984 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4985 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 4986 | |
| 4987 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4988 | |
| 4989 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 4990 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 4991 | bool IsDead() const { return !IsLive(); } |
| 4992 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 4993 | |
| 4994 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4995 | return other != nullptr |
| 4996 | && other->IsPhi() |
| 4997 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4998 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4999 | } |
| 5000 | |
| 5001 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 5002 | // An equivalent phi is a phi having the same dex register and type. |
| 5003 | // It assumes that phis with the same dex register are adjacent. |
| 5004 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 5005 | HInstruction* next = GetNext(); |
| 5006 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 5007 | if (next->GetType() == GetType()) { |
| 5008 | return next->AsPhi(); |
| 5009 | } |
| 5010 | next = next->GetNext(); |
| 5011 | } |
| 5012 | return nullptr; |
| 5013 | } |
| 5014 | |
| 5015 | DECLARE_INSTRUCTION(Phi); |
| 5016 | |
| 5017 | protected: |
| 5018 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 5019 | return inputs_[index]; |
| 5020 | } |
| 5021 | |
| 5022 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
| 5023 | inputs_[index] = input; |
| 5024 | } |
| 5025 | |
| 5026 | private: |
| 5027 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5028 | static constexpr size_t kFieldTypeSize = |
| 5029 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5030 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 5031 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 5032 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 5033 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5034 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 5035 | |
| 5036 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
| 5037 | const uint32_t reg_number_; |
| 5038 | |
| 5039 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 5040 | }; |
| 5041 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5042 | class HNullCheck : public HExpression<1> { |
| 5043 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5044 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 5045 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5046 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5047 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5048 | SetRawInputAt(0, value); |
| 5049 | } |
| 5050 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5051 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5052 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5053 | return true; |
| 5054 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5055 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5056 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5057 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5058 | bool CanThrow() const OVERRIDE { return true; } |
| 5059 | |
| 5060 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5061 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5062 | |
| 5063 | DECLARE_INSTRUCTION(NullCheck); |
| 5064 | |
| 5065 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5066 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 5067 | }; |
| 5068 | |
| 5069 | class FieldInfo : public ValueObject { |
| 5070 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5071 | FieldInfo(MemberOffset field_offset, |
| 5072 | Primitive::Type field_type, |
| 5073 | bool is_volatile, |
| 5074 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5075 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5076 | const DexFile& dex_file, |
| 5077 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5078 | : field_offset_(field_offset), |
| 5079 | field_type_(field_type), |
| 5080 | is_volatile_(is_volatile), |
| 5081 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5082 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5083 | dex_file_(dex_file), |
| 5084 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5085 | |
| 5086 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5087 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5088 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5089 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5090 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5091 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5092 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5093 | |
| 5094 | private: |
| 5095 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5096 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5097 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5098 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5099 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5100 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5101 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5102 | }; |
| 5103 | |
| 5104 | class HInstanceFieldGet : public HExpression<1> { |
| 5105 | public: |
| 5106 | HInstanceFieldGet(HInstruction* value, |
| 5107 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5108 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5109 | bool is_volatile, |
| 5110 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5111 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5112 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5113 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5114 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5115 | : HExpression(field_type, |
| 5116 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5117 | dex_pc), |
| 5118 | field_info_(field_offset, |
| 5119 | field_type, |
| 5120 | is_volatile, |
| 5121 | field_idx, |
| 5122 | declaring_class_def_index, |
| 5123 | dex_file, |
| 5124 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5125 | SetRawInputAt(0, value); |
| 5126 | } |
| 5127 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5128 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5129 | |
| 5130 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5131 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 5132 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5133 | } |
| 5134 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5135 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5136 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5137 | } |
| 5138 | |
| 5139 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5140 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5141 | } |
| 5142 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5143 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5144 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5145 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5146 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5147 | |
| 5148 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5149 | |
| 5150 | private: |
| 5151 | const FieldInfo field_info_; |
| 5152 | |
| 5153 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5154 | }; |
| 5155 | |
| 5156 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 5157 | public: |
| 5158 | HInstanceFieldSet(HInstruction* object, |
| 5159 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5160 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5161 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5162 | bool is_volatile, |
| 5163 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5164 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5165 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5166 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5167 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5168 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5169 | dex_pc), |
| 5170 | field_info_(field_offset, |
| 5171 | field_type, |
| 5172 | is_volatile, |
| 5173 | field_idx, |
| 5174 | declaring_class_def_index, |
| 5175 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5176 | dex_cache) { |
| 5177 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5178 | SetRawInputAt(0, object); |
| 5179 | SetRawInputAt(1, value); |
| 5180 | } |
| 5181 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5182 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5183 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5184 | } |
| 5185 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5186 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5187 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5188 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5189 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5190 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5191 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5192 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5193 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5194 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5195 | |
| 5196 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5197 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5198 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5199 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5200 | "Too many packed fields."); |
| 5201 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5202 | const FieldInfo field_info_; |
| 5203 | |
| 5204 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5205 | }; |
| 5206 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5207 | class HArrayGet : public HExpression<2> { |
| 5208 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5209 | HArrayGet(HInstruction* array, |
| 5210 | HInstruction* index, |
| 5211 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5212 | uint32_t dex_pc, |
| 5213 | SideEffects additional_side_effects = SideEffects::None()) |
| 5214 | : HExpression(type, |
| 5215 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 5216 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5217 | SetRawInputAt(0, array); |
| 5218 | SetRawInputAt(1, index); |
| 5219 | } |
| 5220 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5221 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5222 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5223 | return true; |
| 5224 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5225 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5226 | // TODO: We can be smarter here. |
| 5227 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5228 | // which generates the implicit null check. There are cases when these can be removed |
| 5229 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5230 | // implicit check here (as long as the address falls in the first page). |
| 5231 | return false; |
| 5232 | } |
| 5233 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5234 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5235 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5236 | if (kIsDebugBuild && result) { |
| 5237 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5238 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5239 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5240 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5241 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5242 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5243 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5244 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5245 | } |
| 5246 | } |
| 5247 | return result; |
| 5248 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5249 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5250 | HInstruction* GetArray() const { return InputAt(0); } |
| 5251 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5252 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5253 | DECLARE_INSTRUCTION(ArrayGet); |
| 5254 | |
| 5255 | private: |
| 5256 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5257 | }; |
| 5258 | |
| 5259 | class HArraySet : public HTemplateInstruction<3> { |
| 5260 | public: |
| 5261 | HArraySet(HInstruction* array, |
| 5262 | HInstruction* index, |
| 5263 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5264 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5265 | uint32_t dex_pc, |
| 5266 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5267 | : HTemplateInstruction( |
| 5268 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5269 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 5270 | additional_side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5271 | dex_pc) { |
| 5272 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5273 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5274 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5275 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5276 | SetRawInputAt(0, array); |
| 5277 | SetRawInputAt(1, index); |
| 5278 | SetRawInputAt(2, value); |
| 5279 | } |
| 5280 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5281 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5282 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5283 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5284 | } |
| 5285 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5286 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5287 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5288 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5289 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5290 | // TODO: Same as for ArrayGet. |
| 5291 | return false; |
| 5292 | } |
| 5293 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5294 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5295 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5296 | } |
| 5297 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5298 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5299 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5300 | } |
| 5301 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5302 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5303 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5304 | } |
| 5305 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5306 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5307 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5308 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5309 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5310 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5311 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5312 | HInstruction* GetArray() const { return InputAt(0); } |
| 5313 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5314 | HInstruction* GetValue() const { return InputAt(2); } |
| 5315 | |
| 5316 | Primitive::Type GetComponentType() const { |
| 5317 | // The Dex format does not type floating point index operations. Since the |
| 5318 | // `expected_component_type_` is set during building and can therefore not |
| 5319 | // be correct, we also check what is the value type. If it is a floating |
| 5320 | // point type, we must use that type. |
| 5321 | Primitive::Type value_type = GetValue()->GetType(); |
| 5322 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5323 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5324 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5325 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5326 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5327 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5328 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5329 | } |
| 5330 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5331 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5332 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5333 | } |
| 5334 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5335 | DECLARE_INSTRUCTION(ArraySet); |
| 5336 | |
| 5337 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5338 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5339 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5340 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5341 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5342 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5343 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5344 | // Cached information for the reference_type_info_ so that codegen |
| 5345 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5346 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5347 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5348 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5349 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5350 | using ExpectedComponentTypeField = |
| 5351 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5352 | |
| 5353 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5354 | }; |
| 5355 | |
| 5356 | class HArrayLength : public HExpression<1> { |
| 5357 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 5358 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5359 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5360 | // Note that arrays do not change length, so the instruction does not |
| 5361 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5362 | SetRawInputAt(0, array); |
| 5363 | } |
| 5364 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5365 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5366 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5367 | return true; |
| 5368 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5369 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5370 | return obj == InputAt(0); |
| 5371 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5372 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5373 | DECLARE_INSTRUCTION(ArrayLength); |
| 5374 | |
| 5375 | private: |
| 5376 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5377 | }; |
| 5378 | |
| 5379 | class HBoundsCheck : public HExpression<2> { |
| 5380 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5381 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5382 | // constructor. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5383 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5384 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame^] | 5385 | DCHECK(index->GetType() == Primitive::kPrimInt); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5386 | SetRawInputAt(0, index); |
| 5387 | SetRawInputAt(1, length); |
| 5388 | } |
| 5389 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5390 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5391 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5392 | return true; |
| 5393 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5394 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5395 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5396 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5397 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5398 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5399 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5400 | |
| 5401 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5402 | |
| 5403 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5404 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5405 | }; |
| 5406 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5407 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 5408 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5409 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5410 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5411 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5412 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5413 | return true; |
| 5414 | } |
| 5415 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5416 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5417 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5418 | |
| 5419 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5420 | |
| 5421 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5422 | // Only used for code generation, in order to share the same slow path between back edges |
| 5423 | // of a same loop. |
| 5424 | SlowPathCode* slow_path_; |
| 5425 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5426 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5427 | }; |
| 5428 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5429 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5430 | // It ensures that we can generate line number and local variables at this point. |
| 5431 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5432 | public: |
| 5433 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5434 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5435 | |
| 5436 | bool NeedsEnvironment() const OVERRIDE { |
| 5437 | return true; |
| 5438 | } |
| 5439 | |
| 5440 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5441 | |
| 5442 | private: |
| 5443 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5444 | }; |
| 5445 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5446 | /** |
| 5447 | * Instruction to load a Class object. |
| 5448 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5449 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5450 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5451 | HLoadClass(HCurrentMethod* current_method, |
| 5452 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5453 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5454 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5455 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5456 | bool needs_access_check, |
| 5457 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5458 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5459 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5460 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5461 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5462 | // Referrers class should not need access check. We never inline unverified |
| 5463 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5464 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5465 | |
| 5466 | SetPackedFlag<kFlagIsReferrersClass>(is_referrers_class); |
| 5467 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5468 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
| 5469 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5470 | SetRawInputAt(0, current_method); |
| 5471 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5472 | |
| 5473 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5474 | |
| 5475 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 5476 | // Note that we don't need to test for generate_clinit_check_. |
| 5477 | // Whether or not we need to generate the clinit check is processed in |
| 5478 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5479 | return other->AsLoadClass()->type_index_ == type_index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5480 | other->AsLoadClass()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5481 | } |
| 5482 | |
| 5483 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5484 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5485 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5486 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5487 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5488 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5489 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5490 | } |
| 5491 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5492 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5493 | // The entrypoint the code generator is going to call does not do |
| 5494 | // clinit of the class. |
| 5495 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5496 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5497 | } |
| 5498 | |
| 5499 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5500 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5501 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5502 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5503 | } |
| 5504 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5505 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5506 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5507 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5508 | } |
| 5509 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5510 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5511 | return loaded_class_rti_; |
| 5512 | } |
| 5513 | |
| 5514 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5515 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5516 | DCHECK(rti.IsExact()); |
| 5517 | loaded_class_rti_ = rti; |
| 5518 | } |
| 5519 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5520 | const DexFile& GetDexFile() { return dex_file_; } |
| 5521 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5522 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5523 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5524 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5525 | return SideEffects::CanTriggerGC(); |
| 5526 | } |
| 5527 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5528 | bool IsReferrersClass() const { return GetPackedFlag<kFlagIsReferrersClass>(); } |
| 5529 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5530 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5531 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5532 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5533 | DECLARE_INSTRUCTION(LoadClass); |
| 5534 | |
| 5535 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5536 | static constexpr size_t kFlagIsReferrersClass = kNumberOfExpressionPackedBits; |
| 5537 | static constexpr size_t kFlagNeedsAccessCheck = kFlagIsReferrersClass + 1; |
| 5538 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5539 | // Whether this instruction must generate the initialization check. |
| 5540 | // Used for code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5541 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInDexCache + 1; |
| 5542 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagGenerateClInitCheck + 1; |
| 5543 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5544 | |
| 5545 | const uint16_t type_index_; |
| 5546 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5547 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5548 | ReferenceTypeInfo loaded_class_rti_; |
| 5549 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5550 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5551 | }; |
| 5552 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5553 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5554 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5555 | // Determines how to load the String. |
| 5556 | enum class LoadKind { |
| 5557 | // Use boot image String* address that will be known at link time. |
| 5558 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5559 | kBootImageLinkTimeAddress, |
| 5560 | |
| 5561 | // Use PC-relative boot image String* address that will be known at link time. |
| 5562 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5563 | kBootImageLinkTimePcRelative, |
| 5564 | |
| 5565 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5566 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5567 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5568 | // GetIncludePatchInformation(). |
| 5569 | kBootImageAddress, |
| 5570 | |
| 5571 | // Load from the resolved strings array at an absolute address. |
| 5572 | // Used for strings outside the boot image referenced by JIT-compiled code. |
| 5573 | kDexCacheAddress, |
| 5574 | |
| 5575 | // Load from resolved strings array in the dex cache using a PC-relative load. |
| 5576 | // Used for strings outside boot image when we know that we can access |
| 5577 | // the dex cache arrays using a PC-relative load. |
| 5578 | kDexCachePcRelative, |
| 5579 | |
| 5580 | // Load from resolved strings array accessed through the class loaded from |
| 5581 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5582 | // all other types are unavailable. |
| 5583 | kDexCacheViaMethod, |
| 5584 | |
| 5585 | kLast = kDexCacheViaMethod |
| 5586 | }; |
| 5587 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5588 | HLoadString(HCurrentMethod* current_method, |
| 5589 | uint32_t string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5590 | const DexFile& dex_file, |
| 5591 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5592 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5593 | string_index_(string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5594 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5595 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
| 5596 | load_data_.ref.dex_file = &dex_file; |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5597 | SetRawInputAt(0, current_method); |
| 5598 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5599 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5600 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5601 | DCHECK(HasAddress(load_kind)); |
| 5602 | load_data_.address = address; |
| 5603 | SetLoadKindInternal(load_kind); |
| 5604 | } |
| 5605 | |
| 5606 | void SetLoadKindWithStringReference(LoadKind load_kind, |
| 5607 | const DexFile& dex_file, |
| 5608 | uint32_t string_index) { |
| 5609 | DCHECK(HasStringReference(load_kind)); |
| 5610 | load_data_.ref.dex_file = &dex_file; |
| 5611 | string_index_ = string_index; |
| 5612 | SetLoadKindInternal(load_kind); |
| 5613 | } |
| 5614 | |
| 5615 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5616 | const DexFile& dex_file, |
| 5617 | uint32_t element_index) { |
| 5618 | DCHECK(HasDexCacheReference(load_kind)); |
| 5619 | load_data_.ref.dex_file = &dex_file; |
| 5620 | load_data_.ref.dex_cache_element_index = element_index; |
| 5621 | SetLoadKindInternal(load_kind); |
| 5622 | } |
| 5623 | |
| 5624 | LoadKind GetLoadKind() const { |
| 5625 | return GetPackedField<LoadKindField>(); |
| 5626 | } |
| 5627 | |
| 5628 | const DexFile& GetDexFile() const; |
| 5629 | |
| 5630 | uint32_t GetStringIndex() const { |
| 5631 | DCHECK(HasStringReference(GetLoadKind()) || /* For slow paths. */ !IsInDexCache()); |
| 5632 | return string_index_; |
| 5633 | } |
| 5634 | |
| 5635 | uint32_t GetDexCacheElementOffset() const; |
| 5636 | |
| 5637 | uint64_t GetAddress() const { |
| 5638 | DCHECK(HasAddress(GetLoadKind())); |
| 5639 | return load_data_.address; |
| 5640 | } |
| 5641 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5642 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5643 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5644 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5645 | |
| 5646 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5647 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5648 | // Will call the runtime if we need to load the string through |
| 5649 | // the dex cache and the string is not guaranteed to be there yet. |
| 5650 | bool NeedsEnvironment() const OVERRIDE { |
| 5651 | LoadKind load_kind = GetLoadKind(); |
| 5652 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5653 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5654 | load_kind == LoadKind::kBootImageAddress) { |
| 5655 | return false; |
| 5656 | } |
| 5657 | return !IsInDexCache(); |
| 5658 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5659 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5660 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5661 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5662 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5663 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5664 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5665 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5666 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5667 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5668 | return SideEffects::CanTriggerGC(); |
| 5669 | } |
| 5670 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5671 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5672 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5673 | void MarkInDexCache() { |
| 5674 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5675 | DCHECK(!NeedsEnvironment()); |
| 5676 | RemoveEnvironment(); |
| 5677 | } |
| 5678 | |
| 5679 | size_t InputCount() const OVERRIDE { |
| 5680 | return (InputAt(0) != nullptr) ? 1u : 0u; |
| 5681 | } |
| 5682 | |
| 5683 | void AddSpecialInput(HInstruction* special_input); |
| 5684 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5685 | DECLARE_INSTRUCTION(LoadString); |
| 5686 | |
| 5687 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5688 | static constexpr size_t kFlagIsInDexCache = kNumberOfExpressionPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5689 | static constexpr size_t kFieldLoadKind = kFlagIsInDexCache + 1; |
| 5690 | static constexpr size_t kFieldLoadKindSize = |
| 5691 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5692 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5693 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5694 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5695 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5696 | static bool HasStringReference(LoadKind load_kind) { |
| 5697 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5698 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5699 | load_kind == LoadKind::kDexCacheViaMethod; |
| 5700 | } |
| 5701 | |
| 5702 | static bool HasAddress(LoadKind load_kind) { |
| 5703 | return load_kind == LoadKind::kBootImageAddress || load_kind == LoadKind::kDexCacheAddress; |
| 5704 | } |
| 5705 | |
| 5706 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5707 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5708 | } |
| 5709 | |
| 5710 | void SetLoadKindInternal(LoadKind load_kind); |
| 5711 | |
| 5712 | // String index serves also as the hash code and it's also needed for slow-paths, |
| 5713 | // so it must not be overwritten with other load data. |
| 5714 | uint32_t string_index_; |
| 5715 | |
| 5716 | union { |
| 5717 | struct { |
| 5718 | const DexFile* dex_file; // For string reference and dex cache reference. |
| 5719 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
| 5720 | } ref; |
| 5721 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5722 | } load_data_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5723 | |
| 5724 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5725 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5726 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5727 | |
| 5728 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5729 | inline const DexFile& HLoadString::GetDexFile() const { |
| 5730 | DCHECK(HasStringReference(GetLoadKind()) || HasDexCacheReference(GetLoadKind())) |
| 5731 | << GetLoadKind(); |
| 5732 | return *load_data_.ref.dex_file; |
| 5733 | } |
| 5734 | |
| 5735 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5736 | inline uint32_t HLoadString::GetDexCacheElementOffset() const { |
| 5737 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5738 | return load_data_.ref.dex_cache_element_index; |
| 5739 | } |
| 5740 | |
| 5741 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5742 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
| 5743 | // The special input is used for PC-relative loads on some architectures. |
| 5744 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 5745 | GetLoadKind() == LoadKind::kDexCachePcRelative) << GetLoadKind(); |
| 5746 | DCHECK(InputAt(0) == nullptr); |
| 5747 | SetRawInputAt(0u, special_input); |
| 5748 | special_input->AddUseAt(this, 0); |
| 5749 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5750 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5751 | /** |
| 5752 | * Performs an initialization check on its Class object input. |
| 5753 | */ |
| 5754 | class HClinitCheck : public HExpression<1> { |
| 5755 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5756 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5757 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5758 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5759 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5760 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5761 | SetRawInputAt(0, constant); |
| 5762 | } |
| 5763 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5764 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5765 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5766 | return true; |
| 5767 | } |
| 5768 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5769 | bool NeedsEnvironment() const OVERRIDE { |
| 5770 | // May call runtime to initialize the class. |
| 5771 | return true; |
| 5772 | } |
| 5773 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5774 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5775 | |
| 5776 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5777 | |
| 5778 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5779 | |
| 5780 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5781 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5782 | }; |
| 5783 | |
| 5784 | class HStaticFieldGet : public HExpression<1> { |
| 5785 | public: |
| 5786 | HStaticFieldGet(HInstruction* cls, |
| 5787 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5788 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5789 | bool is_volatile, |
| 5790 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5791 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5792 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5793 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5794 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5795 | : HExpression(field_type, |
| 5796 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5797 | dex_pc), |
| 5798 | field_info_(field_offset, |
| 5799 | field_type, |
| 5800 | is_volatile, |
| 5801 | field_idx, |
| 5802 | declaring_class_def_index, |
| 5803 | dex_file, |
| 5804 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5805 | SetRawInputAt(0, cls); |
| 5806 | } |
| 5807 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5808 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5809 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5810 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5811 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5812 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5813 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | size_t ComputeHashCode() const OVERRIDE { |
| 5817 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5818 | } |
| 5819 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5820 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5821 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5822 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5823 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5824 | |
| 5825 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5826 | |
| 5827 | private: |
| 5828 | const FieldInfo field_info_; |
| 5829 | |
| 5830 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5831 | }; |
| 5832 | |
| 5833 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5834 | public: |
| 5835 | HStaticFieldSet(HInstruction* cls, |
| 5836 | HInstruction* value, |
| 5837 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5838 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5839 | bool is_volatile, |
| 5840 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5841 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5842 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5843 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5844 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5845 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5846 | dex_pc), |
| 5847 | field_info_(field_offset, |
| 5848 | field_type, |
| 5849 | is_volatile, |
| 5850 | field_idx, |
| 5851 | declaring_class_def_index, |
| 5852 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5853 | dex_cache) { |
| 5854 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5855 | SetRawInputAt(0, cls); |
| 5856 | SetRawInputAt(1, value); |
| 5857 | } |
| 5858 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5859 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5860 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5861 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5862 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5863 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5864 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5865 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5866 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5867 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5868 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5869 | |
| 5870 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5871 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5872 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5873 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5874 | "Too many packed fields."); |
| 5875 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5876 | const FieldInfo field_info_; |
| 5877 | |
| 5878 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5879 | }; |
| 5880 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5881 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5882 | public: |
| 5883 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5884 | Primitive::Type field_type, |
| 5885 | uint32_t field_index, |
| 5886 | uint32_t dex_pc) |
| 5887 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5888 | field_index_(field_index) { |
| 5889 | SetRawInputAt(0, obj); |
| 5890 | } |
| 5891 | |
| 5892 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5893 | bool CanThrow() const OVERRIDE { return true; } |
| 5894 | |
| 5895 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5896 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5897 | |
| 5898 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5899 | |
| 5900 | private: |
| 5901 | const uint32_t field_index_; |
| 5902 | |
| 5903 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5904 | }; |
| 5905 | |
| 5906 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5907 | public: |
| 5908 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5909 | HInstruction* value, |
| 5910 | Primitive::Type field_type, |
| 5911 | uint32_t field_index, |
| 5912 | uint32_t dex_pc) |
| 5913 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5914 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5915 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame^] | 5916 | DCHECK_EQ(field_type, value->GetType()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5917 | SetRawInputAt(0, obj); |
| 5918 | SetRawInputAt(1, value); |
| 5919 | } |
| 5920 | |
| 5921 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5922 | bool CanThrow() const OVERRIDE { return true; } |
| 5923 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5924 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5925 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5926 | |
| 5927 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5928 | |
| 5929 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5930 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5931 | static constexpr size_t kFieldFieldTypeSize = |
| 5932 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5933 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5934 | kFieldFieldType + kFieldFieldTypeSize; |
| 5935 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5936 | "Too many packed fields."); |
| 5937 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5938 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5939 | const uint32_t field_index_; |
| 5940 | |
| 5941 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5942 | }; |
| 5943 | |
| 5944 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5945 | public: |
| 5946 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5947 | uint32_t field_index, |
| 5948 | uint32_t dex_pc) |
| 5949 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5950 | field_index_(field_index) { |
| 5951 | } |
| 5952 | |
| 5953 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5954 | bool CanThrow() const OVERRIDE { return true; } |
| 5955 | |
| 5956 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5957 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5958 | |
| 5959 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5960 | |
| 5961 | private: |
| 5962 | const uint32_t field_index_; |
| 5963 | |
| 5964 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5965 | }; |
| 5966 | |
| 5967 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5968 | public: |
| 5969 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5970 | Primitive::Type field_type, |
| 5971 | uint32_t field_index, |
| 5972 | uint32_t dex_pc) |
| 5973 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5974 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5975 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame^] | 5976 | DCHECK_EQ(field_type, value->GetType()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5977 | SetRawInputAt(0, value); |
| 5978 | } |
| 5979 | |
| 5980 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5981 | bool CanThrow() const OVERRIDE { return true; } |
| 5982 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5983 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5984 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5985 | |
| 5986 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5987 | |
| 5988 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5989 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5990 | static constexpr size_t kFieldFieldTypeSize = |
| 5991 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5992 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5993 | kFieldFieldType + kFieldFieldTypeSize; |
| 5994 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5995 | "Too many packed fields."); |
| 5996 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5997 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5998 | const uint32_t field_index_; |
| 5999 | |
| 6000 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 6001 | }; |
| 6002 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6003 | // Implement the move-exception DEX instruction. |
| 6004 | class HLoadException : public HExpression<0> { |
| 6005 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6006 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 6007 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6008 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6009 | bool CanBeNull() const OVERRIDE { return false; } |
| 6010 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6011 | DECLARE_INSTRUCTION(LoadException); |
| 6012 | |
| 6013 | private: |
| 6014 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 6015 | }; |
| 6016 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6017 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6018 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 6019 | class HClearException : public HTemplateInstruction<0> { |
| 6020 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6021 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 6022 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6023 | |
| 6024 | DECLARE_INSTRUCTION(ClearException); |
| 6025 | |
| 6026 | private: |
| 6027 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 6028 | }; |
| 6029 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6030 | class HThrow : public HTemplateInstruction<1> { |
| 6031 | public: |
| 6032 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6033 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6034 | SetRawInputAt(0, exception); |
| 6035 | } |
| 6036 | |
| 6037 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6038 | |
| 6039 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6040 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6041 | bool CanThrow() const OVERRIDE { return true; } |
| 6042 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6043 | |
| 6044 | DECLARE_INSTRUCTION(Throw); |
| 6045 | |
| 6046 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6047 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 6048 | }; |
| 6049 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6050 | /** |
| 6051 | * Implementation strategies for the code generator of a HInstanceOf |
| 6052 | * or `HCheckCast`. |
| 6053 | */ |
| 6054 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6055 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6056 | kExactCheck, // Can do a single class compare. |
| 6057 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 6058 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 6059 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 6060 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6061 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 6062 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6063 | }; |
| 6064 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6065 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 6066 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6067 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6068 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6069 | HInstanceOf(HInstruction* object, |
| 6070 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6071 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6072 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6073 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6074 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6075 | dex_pc) { |
| 6076 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6077 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6078 | SetRawInputAt(0, object); |
| 6079 | SetRawInputAt(1, constant); |
| 6080 | } |
| 6081 | |
| 6082 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6083 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6084 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6085 | return true; |
| 6086 | } |
| 6087 | |
| 6088 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6089 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6090 | } |
| 6091 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6092 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6093 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6094 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6095 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6096 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6097 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6098 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 6099 | // Mips currently does runtime calls for any other checks. |
| 6100 | return check_kind != TypeCheckKind::kExactCheck; |
| 6101 | } |
| 6102 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6103 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6104 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6105 | } |
| 6106 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6107 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6108 | |
| 6109 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6110 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6111 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6112 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6113 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6114 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6115 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6116 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6117 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6118 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6119 | }; |
| 6120 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6121 | class HBoundType : public HExpression<1> { |
| 6122 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6123 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6124 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6125 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6126 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6127 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6128 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6129 | SetRawInputAt(0, input); |
| 6130 | } |
| 6131 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6132 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6133 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6134 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6135 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6136 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6137 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6138 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6139 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6140 | } |
| 6141 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6142 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6143 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6144 | DECLARE_INSTRUCTION(BoundType); |
| 6145 | |
| 6146 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6147 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6148 | // is false then CanBeNull() cannot be true). |
| 6149 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6150 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6151 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6152 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6153 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6154 | // 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] | 6155 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6156 | // It is used to bound the type in cases like: |
| 6157 | // if (x instanceof ClassX) { |
| 6158 | // // uper_bound_ will be ClassX |
| 6159 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6160 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6161 | |
| 6162 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6163 | }; |
| 6164 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6165 | class HCheckCast : public HTemplateInstruction<2> { |
| 6166 | public: |
| 6167 | HCheckCast(HInstruction* object, |
| 6168 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6169 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6170 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6171 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6172 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6173 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6174 | SetRawInputAt(0, object); |
| 6175 | SetRawInputAt(1, constant); |
| 6176 | } |
| 6177 | |
| 6178 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6179 | |
| 6180 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6181 | return true; |
| 6182 | } |
| 6183 | |
| 6184 | bool NeedsEnvironment() const OVERRIDE { |
| 6185 | // Instruction may throw a CheckCastError. |
| 6186 | return true; |
| 6187 | } |
| 6188 | |
| 6189 | bool CanThrow() const OVERRIDE { return true; } |
| 6190 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6191 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6192 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6193 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6194 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6195 | |
| 6196 | DECLARE_INSTRUCTION(CheckCast); |
| 6197 | |
| 6198 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6199 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6200 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6201 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6202 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6203 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6204 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6205 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6206 | |
| 6207 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6208 | }; |
| 6209 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6210 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 6211 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6212 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6213 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6214 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6215 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6216 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6217 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6218 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6219 | |
| 6220 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6221 | |
| 6222 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6223 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6224 | static constexpr size_t kFieldBarrierKindSize = |
| 6225 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6226 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6227 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6228 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6229 | "Too many packed fields."); |
| 6230 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6231 | |
| 6232 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6233 | }; |
| 6234 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6235 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 6236 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6237 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6238 | kEnter, |
| 6239 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6240 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6241 | }; |
| 6242 | |
| 6243 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6244 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6245 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6246 | dex_pc) { |
| 6247 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6248 | SetRawInputAt(0, object); |
| 6249 | } |
| 6250 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6251 | // Instruction may go into runtime, so we need an environment. |
| 6252 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6253 | |
| 6254 | bool CanThrow() const OVERRIDE { |
| 6255 | // Verifier guarantees that monitor-exit cannot throw. |
| 6256 | // This is important because it allows the HGraphBuilder to remove |
| 6257 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6258 | return IsEnter(); |
| 6259 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6260 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6261 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6262 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6263 | |
| 6264 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6265 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6266 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6267 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6268 | static constexpr size_t kFieldOperationKindSize = |
| 6269 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6270 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6271 | kFieldOperationKind + kFieldOperationKindSize; |
| 6272 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6273 | "Too many packed fields."); |
| 6274 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6275 | |
| 6276 | private: |
| 6277 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6278 | }; |
| 6279 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6280 | class HSelect : public HExpression<3> { |
| 6281 | public: |
| 6282 | HSelect(HInstruction* condition, |
| 6283 | HInstruction* true_value, |
| 6284 | HInstruction* false_value, |
| 6285 | uint32_t dex_pc) |
| 6286 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6287 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6288 | |
| 6289 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6290 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6291 | // that architectures which implement HSelect as a conditional move also |
| 6292 | // will not need to invert the condition. |
| 6293 | SetRawInputAt(0, false_value); |
| 6294 | SetRawInputAt(1, true_value); |
| 6295 | SetRawInputAt(2, condition); |
| 6296 | } |
| 6297 | |
| 6298 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6299 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6300 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6301 | |
| 6302 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6303 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
| 6304 | |
| 6305 | bool CanBeNull() const OVERRIDE { |
| 6306 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6307 | } |
| 6308 | |
| 6309 | DECLARE_INSTRUCTION(Select); |
| 6310 | |
| 6311 | private: |
| 6312 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6313 | }; |
| 6314 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6315 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6316 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6317 | MoveOperands(Location source, |
| 6318 | Location destination, |
| 6319 | Primitive::Type type, |
| 6320 | HInstruction* instruction) |
| 6321 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6322 | |
| 6323 | Location GetSource() const { return source_; } |
| 6324 | Location GetDestination() const { return destination_; } |
| 6325 | |
| 6326 | void SetSource(Location value) { source_ = value; } |
| 6327 | void SetDestination(Location value) { destination_ = value; } |
| 6328 | |
| 6329 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6330 | // destination (but not the source). |
| 6331 | Location MarkPending() { |
| 6332 | DCHECK(!IsPending()); |
| 6333 | Location dest = destination_; |
| 6334 | destination_ = Location::NoLocation(); |
| 6335 | return dest; |
| 6336 | } |
| 6337 | |
| 6338 | void ClearPending(Location dest) { |
| 6339 | DCHECK(IsPending()); |
| 6340 | destination_ = dest; |
| 6341 | } |
| 6342 | |
| 6343 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6344 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6345 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6346 | } |
| 6347 | |
| 6348 | // True if this blocks a move from the given location. |
| 6349 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6350 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6351 | } |
| 6352 | |
| 6353 | // A move is redundant if it's been eliminated, if its source and |
| 6354 | // destination are the same, or if its destination is unneeded. |
| 6355 | bool IsRedundant() const { |
| 6356 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6357 | } |
| 6358 | |
| 6359 | // We clear both operands to indicate move that's been eliminated. |
| 6360 | void Eliminate() { |
| 6361 | source_ = destination_ = Location::NoLocation(); |
| 6362 | } |
| 6363 | |
| 6364 | bool IsEliminated() const { |
| 6365 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6366 | return source_.IsInvalid(); |
| 6367 | } |
| 6368 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6369 | Primitive::Type GetType() const { return type_; } |
| 6370 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6371 | bool Is64BitMove() const { |
| 6372 | return Primitive::Is64BitType(type_); |
| 6373 | } |
| 6374 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6375 | HInstruction* GetInstruction() const { return instruction_; } |
| 6376 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6377 | private: |
| 6378 | Location source_; |
| 6379 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6380 | // The type this move is for. |
| 6381 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6382 | // The instruction this move is assocatied with. Null when this move is |
| 6383 | // for moving an input in the expected locations of user (including a phi user). |
| 6384 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6385 | // in the same parallel move. |
| 6386 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6387 | }; |
| 6388 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6389 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6390 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6391 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6392 | |
| 6393 | class HParallelMove : public HTemplateInstruction<0> { |
| 6394 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6395 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6396 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6397 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6398 | moves_.reserve(kDefaultNumberOfMoves); |
| 6399 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6400 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6401 | void AddMove(Location source, |
| 6402 | Location destination, |
| 6403 | Primitive::Type type, |
| 6404 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6405 | DCHECK(source.IsValid()); |
| 6406 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6407 | if (kIsDebugBuild) { |
| 6408 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6409 | for (const MoveOperands& move : moves_) { |
| 6410 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6411 | // Special case the situation where the move is for the spill slot |
| 6412 | // of the instruction. |
| 6413 | if ((GetPrevious() == instruction) |
| 6414 | || ((GetPrevious() == nullptr) |
| 6415 | && instruction->IsPhi() |
| 6416 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6417 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6418 | << "Doing parallel moves for the same instruction."; |
| 6419 | } else { |
| 6420 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6421 | } |
| 6422 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6423 | } |
| 6424 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6425 | for (const MoveOperands& move : moves_) { |
| 6426 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6427 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6428 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6429 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6430 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6431 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6432 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6433 | } |
| 6434 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6435 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6436 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6437 | } |
| 6438 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6439 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6440 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6441 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6442 | |
| 6443 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6444 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6445 | |
| 6446 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6447 | }; |
| 6448 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6449 | } // namespace art |
| 6450 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6451 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6452 | #include "nodes_shared.h" |
| 6453 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6454 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6455 | #include "nodes_arm.h" |
| 6456 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6457 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6458 | #include "nodes_arm64.h" |
| 6459 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6460 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6461 | #include "nodes_x86.h" |
| 6462 | #endif |
| 6463 | |
| 6464 | namespace art { |
| 6465 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6466 | class HGraphVisitor : public ValueObject { |
| 6467 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6468 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6469 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6470 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6471 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6472 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6473 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6474 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6475 | void VisitInsertionOrder(); |
| 6476 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6477 | // Visit the graph following dominator tree reverse post-order. |
| 6478 | void VisitReversePostOrder(); |
| 6479 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6480 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6481 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6482 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6483 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6484 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6485 | |
| 6486 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6487 | |
| 6488 | #undef DECLARE_VISIT_INSTRUCTION |
| 6489 | |
| 6490 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6491 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6492 | |
| 6493 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6494 | }; |
| 6495 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6496 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6497 | public: |
| 6498 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6499 | virtual ~HGraphDelegateVisitor() {} |
| 6500 | |
| 6501 | // Visit functions that delegate to to super class. |
| 6502 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6503 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6504 | |
| 6505 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6506 | |
| 6507 | #undef DECLARE_VISIT_INSTRUCTION |
| 6508 | |
| 6509 | private: |
| 6510 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6511 | }; |
| 6512 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6513 | class HInsertionOrderIterator : public ValueObject { |
| 6514 | public: |
| 6515 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 6516 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6517 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 6518 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6519 | void Advance() { ++index_; } |
| 6520 | |
| 6521 | private: |
| 6522 | const HGraph& graph_; |
| 6523 | size_t index_; |
| 6524 | |
| 6525 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 6526 | }; |
| 6527 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6528 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6529 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6530 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 6531 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6532 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6533 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6534 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6535 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 6536 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6537 | void Advance() { ++index_; } |
| 6538 | |
| 6539 | private: |
| 6540 | const HGraph& graph_; |
| 6541 | size_t index_; |
| 6542 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6543 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6544 | }; |
| 6545 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6546 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6547 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6548 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6549 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6550 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6551 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6552 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6553 | |
| 6554 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6555 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6556 | void Advance() { --index_; } |
| 6557 | |
| 6558 | private: |
| 6559 | const HGraph& graph_; |
| 6560 | size_t index_; |
| 6561 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6562 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6563 | }; |
| 6564 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6565 | class HLinearPostOrderIterator : public ValueObject { |
| 6566 | public: |
| 6567 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6568 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6569 | |
| 6570 | bool Done() const { return index_ == 0; } |
| 6571 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6572 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6573 | |
| 6574 | void Advance() { |
| 6575 | --index_; |
| 6576 | DCHECK_GE(index_, 0U); |
| 6577 | } |
| 6578 | |
| 6579 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6580 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6581 | size_t index_; |
| 6582 | |
| 6583 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 6584 | }; |
| 6585 | |
| 6586 | class HLinearOrderIterator : public ValueObject { |
| 6587 | public: |
| 6588 | explicit HLinearOrderIterator(const HGraph& graph) |
| 6589 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 6590 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6591 | bool Done() const { return index_ == order_.size(); } |
| 6592 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6593 | void Advance() { ++index_; } |
| 6594 | |
| 6595 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6596 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6597 | size_t index_; |
| 6598 | |
| 6599 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 6600 | }; |
| 6601 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6602 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6603 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6604 | // block id. |
| 6605 | class HBlocksInLoopIterator : public ValueObject { |
| 6606 | public: |
| 6607 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6608 | : blocks_in_loop_(info.GetBlocks()), |
| 6609 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6610 | index_(0) { |
| 6611 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6612 | Advance(); |
| 6613 | } |
| 6614 | } |
| 6615 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6616 | bool Done() const { return index_ == blocks_.size(); } |
| 6617 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6618 | void Advance() { |
| 6619 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6620 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6621 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6622 | break; |
| 6623 | } |
| 6624 | } |
| 6625 | } |
| 6626 | |
| 6627 | private: |
| 6628 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6629 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6630 | size_t index_; |
| 6631 | |
| 6632 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6633 | }; |
| 6634 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6635 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6636 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6637 | // post order. |
| 6638 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6639 | public: |
| 6640 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6641 | : blocks_in_loop_(info.GetBlocks()), |
| 6642 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6643 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6644 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6645 | Advance(); |
| 6646 | } |
| 6647 | } |
| 6648 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6649 | bool Done() const { return index_ == blocks_.size(); } |
| 6650 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6651 | void Advance() { |
| 6652 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6653 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6654 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6655 | break; |
| 6656 | } |
| 6657 | } |
| 6658 | } |
| 6659 | |
| 6660 | private: |
| 6661 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6662 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6663 | size_t index_; |
| 6664 | |
| 6665 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6666 | }; |
| 6667 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6668 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6669 | if (constant->IsIntConstant()) { |
| 6670 | return constant->AsIntConstant()->GetValue(); |
| 6671 | } else if (constant->IsLongConstant()) { |
| 6672 | return constant->AsLongConstant()->GetValue(); |
| 6673 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6674 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6675 | return 0; |
| 6676 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6677 | } |
| 6678 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6679 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 6680 | // For the purposes of the compiler, the dex files must actually be the same object |
| 6681 | // if we want to safely treat them as the same. This is especially important for JIT |
| 6682 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 6683 | // times and provide different class resolution but no two class loaders should ever |
| 6684 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 6685 | // all sorts of weird failures. |
| 6686 | return &lhs == &rhs; |
| 6687 | } |
| 6688 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6689 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6690 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6691 | inline const H##type* HInstruction::As##type() const { \ |
| 6692 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6693 | } \ |
| 6694 | inline H##type* HInstruction::As##type() { \ |
| 6695 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6696 | } |
| 6697 | |
| 6698 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6699 | #undef INSTRUCTION_TYPE_CHECK |
| 6700 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6701 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6702 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6703 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6704 | size_t number_of_new_blocks, |
| 6705 | size_t after) { |
| 6706 | DCHECK_LT(after, blocks->size()); |
| 6707 | size_t old_size = blocks->size(); |
| 6708 | size_t new_size = old_size + number_of_new_blocks; |
| 6709 | blocks->resize(new_size); |
| 6710 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6711 | } |
| 6712 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6713 | } // namespace art |
| 6714 | |
| 6715 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |